让pyHook和SendKeys一起使用。
|
我正在尝试在Python中编写一种自动更正机制。我记录了用户的击键,当他们停止输入一秒钟时,我想删除所有内容并重新输入正确的句子。
下面的代码工作正常,除了SendKeys运行非常缓慢的事实。我认为PumpMessages调用以某种方式干扰了它。有谁知道我该如何解决这个问题?
import threading
import pyHook
import pythoncom
from SendKeys import SendKeys
# Store typed keys. Correct words when stop typing for a bit.
def info_handler():
def event_info(e):
if e.MessageName == \'key down\':
v.keys_pressed.append(e.Key)
if v.t: v.t.cancel()
v.t = threading.Timer(1, correct_words)
v.t.start()
return True
return event_info
def correct_words():
SendKeys(\'{BS %i}\' % len(v.keys_pressed))
# Listen to keys.
class v:
keys_pressed = []
t = None
hm = pyHook.HookManager()
hm.KeyDown = info_handler()
hm.HookKeyboard()
pythoncom.PumpMessages()
没有找到相关结果
已邀请:
1 个回复
穗揣