开发者

PyHook: return keydown fires twice

开发者 https://www.devze.com 2023-03-04 14:45 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消