Skip to content

Instantly share code, notes, and snippets.

@deanlxvii
Created September 14, 2012 10:01
Show Gist options
  • Save deanlxvii/3721126 to your computer and use it in GitHub Desktop.
Save deanlxvii/3721126 to your computer and use it in GitHub Desktop.
catch key(board) events (ms-windows)
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