让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()
    
已邀请:
没关系。我只需要在调用SendKeys之前调用hm.UnhookKeyboard()。 编辑:有人问我更多信息。我决定将与密钥相关的实验仅转储到GitHub上:https://github.com/JesseAldridge/Keyboard-Tricks     

要回复问题请先登录注册