[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] pyHooking the Arrow Keys



Hi everyone,
I wrote a little while back about how I wanted to tie the arrow keys
specifically to my program so that they could be used exclusively for the
program instead of being intercepted by a screen reader. I attempted to
modify the code from the tutorial I found, but it is producing some rather
strange results. In addition to not allowing the arrow keys to work inside
of the program, the program also blocks the arrow keys in other windows. Can
anyone tell me, please, what is going wrong and how I can fix it?
Here is the code I have pasted at the bottom of my main file:
def OnKeyboardEvent(event):
# return True to pass the event to other handlers
  return (event.Key not in ['Up', 'Down', 'Right', 'Left'])
 
# create a hook manager
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()

Thanks for your help.
Best,
Ryan