python - Help with pyHook error -


I am trying to create a global hotkey with pyhook in pyhook which only works by pressing the atl key.

Here is the source:

  import pyHook import pythoncom hm = pyHook.HookManager () def OnKeyboardEvent (event): if event.Alt == 32 and event.KeyID == 49: print 'code will be here' hm.KeyDown = OnKeyboardEvent hm.HookKeyboard () pythoncom.PumpMessages ()  

But when I execute, only works with other presses Is the second key (number 1 = 49) ... and this error two:

How do I solve it? For work in the previously pressed time.

Note that you need a return value on it your handler:

< Pre> def OnKeyboardEvent (event): if event.Alt == 32 and event.KeyID == 49: print 'Here the code will be' # Return the correct other handlers back to the right to return the event

I agree that it is unclear from the documents that it is necessary, but you need to return true or false (or possibly any integer value) with the "false" value Blocking the event (such as 0) such that no later handler gets it (this prohibits certain keystrokes, such as in the Event Filtering section of the tutorial.)

( It was not as easy to see as it can be seen! :-))


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -