PyHook: return keydown fires twice
In the following code, when I hit return, on_key_down gets called twice. It only gets called once for any other key. Any ide开发者_C百科a what's going on here?
import pyHook, pythoncom, win32api
def on_key_down(e):
if e.MessageName == 'key down':
print 'e.Key: ', e.Key
print 'e.Ascii: ', e.Ascii
return True
hm = pyHook.HookManager()
hm.KeyDown = on_key_down
hm.HookKeyboard()
pythoncom.PumpMessages()
Because Window's New Line is a '\r\n' you are probably getting both of those characters when you hit return.
If you can, try using KeyUp instead of KeyDown. I only get one event with KeyUp.
精彩评论