0

Pythonでオートコレクトメカニズムを作成しようとしています。ユーザーのキーストロークをログに記録し、ユーザーが1秒間入力を停止したら、すべてを消去して、修正した文を再入力します。

以下のコードは、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()
4

1 に答える 1

0

どうでも。SendKeys を呼び出す前に hm.UnhookKeyboard() を呼び出す必要がありました。

編集:誰かが私に詳細を尋ねました。キー関連の実験を GitHub にダンプすることにしました: https://github.com/JesseAldridge/Keyboard-Tricks

于 2011-05-01T22:51:55.443 に答える