user1641677
user1641677

Reputation: 32

python win32com events don't work from command line

import win32com.client as cc


class AgentEvents(object):
    def OnClick(self, cid, button, shift, x, y):
        peedy.Speak('He he he')
    def OnCommand(self, UserInput):
        cmdname = cc.Dispatch(UserInput).Name
        print(cmdname)
        if cmdname == 'hwru':
            peedy.Speak('Well. Thank you.')
        elif cmdname == 'yoname':
            peedy.Speak('My name is Peedy.')


ag = cc.DispatchWithEvents('Agent.Control.2', AgentEvents)
ag.Connected = True
ag.Characters.Load('peedy', 'peedy.acs')
peedy = ag.Characters('peedy')
peedy.Show()
peedy.LanguageID=0x0409
#print(peedy.SRModeID)
peedy.Commands.Add('hwru','how are you','how are you',True,True)
peedy.Commands.Add('yoname',"what's your name","what's your name",True,True)
ag.CommandsWindow.Visible=True

When I run this from pythonwin IDE all works normal, but from windows command line OnCommand events don't work, it prints no errors, COM object methods (like peedy.Speak("Hello")) work normal too. Is it possible to use win32com activex objects with events from command line?

Solved with:

while True:
    # Pump messages so that COM gets a look in
    pythoncom.PumpWaitingMessages()

Upvotes: 0

Views: 405

Answers (0)

Related Questions