Created
September 14, 2012 10:01
-
-
Save deanlxvii/3721126 to your computer and use it in GitHub Desktop.
catch key(board) events (ms-windows)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pythoncom, pyHook | |
def OnKeyboardEvent(event): | |
print 'MessageName:',event.MessageName | |
print 'Message:',event.Message | |
print 'Time:',event.Time | |
print 'Window:',event.Window | |
print 'WindowName:',event.WindowName | |
print 'Ascii:', event.Ascii, chr(event.Ascii) | |
print 'Key:', event.Key | |
print 'KeyID:', event.KeyID | |
print 'ScanCode:', event.ScanCode | |
print 'Extended:', event.Extended | |
print 'Injected:', event.Injected | |
print 'Alt', event.Alt | |
print 'Transition', event.Transition | |
print '---' | |
# return True to pass the event to other handlers | |
return True | |
# create a hook manager | |
hm = pyHook.HookManager() | |
# watch for all mouse events | |
hm.KeyDown = OnKeyboardEvent | |
# set the hook | |
hm.HookKeyboard() | |
# wait forever | |
pythoncom.PumpMessages() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment