import pythoncom, pyHook def OnKeyboardEvent(event): print 'KeyID:', event.KeyID print 'Extended:', event.Extended print '---' # return True to pass the event to other handlers return False print "hello" # create a hook manager hm = pyHook.HookManager () # watch for all mouse events hm.KeyDown = OnKeyboardEvent # set the hook hm.HookKeyboard() # wait forever pythoncom.PumpMessages()