I use pyhook and pyhk to match keystrokes on a Windows XP computer, and it works fine unless a keystroke (e.g. ctrl + z) already exists in the application. In this case, ctrl + z goes to the application and launches the action that was associated with it.
If you are familiar with autohotkey , note that autohotkey circumvents this by defining hotkeys that can be passed to the main application. Here are some codes that fall into this idea. Please note that I am trying to track when the ctrl key is not working.
import pythoncom, pyHook control_down = False def OnKeyboardEvent_up(event): global control_down if event.Key=='Lcontrol' or event.Key=='Rcontrol': control_down=False return True def OnKeyboardEvent(event,action=None,key='Z',context=None): global control_down if event.Key=='Lcontrol' or event.Key=='Rcontrol': control_down=True if control_down and event.Key==key: print 'do something' return False if event.Key=='Pause': win32gui.PostQuitMessage(1) return False
Any help was appreciated.
Thanks!
source share