Skip to content Skip to sidebar Skip to footer

Help With PyHook Error

I'm trying to make a global hotkey with pyhook in python that is supposed to work only with the alt key pressed. here is the source: import pyHook import pythoncom hm = pyHook.Hoo

Solution 1:

Note from the tutorial that you need a return value at the end of your handler:

def OnKeyboardEvent(event):
    if event.Alt == 32 and event.KeyID == 49:
        print 'HERE WILL BE THE CODE'

    # return True to pass the event to other handlers
    return True

I agree it's ambiguous from the docs whether that's required, but you do need to return True or False (or possibly any integer value), with any "false" value (e.g. 0) blocking the event such that no subsequent handlers get it. (This lets you swallow certain keystrokes conditionally, as in the Event Filtering section of the tutorial.)

(This wasn't as easy to figure out as it might look! :-) )


Post a Comment for "Help With PyHook Error"