Ctrlキーを押しながら何かを実行するスクリプトを書こうとしています。最初のダブルクリックでうまく機能しますが、その後エラーが発生します。また、タイマー実行機能トリガーの後にCtrlキーを何度も押すと、同じエラーが発生します。
import pythoncom, pyHook, threading
press = False
def triger():
global press
press=False
def something():
print 'hello'
def OnKeyboardEvent(event):
global press
if event.Key=='Lcontrol':
if press:
something()
press = False
else:
press=True
threading.Timer(1,triger).start()
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
エラー:
hello
Warning (from warnings module):
File "C:\Python27\lib\threading.py", line 828
return _active[_get_ident()]
RuntimeWarning: tp_compare didn't return -1 or -2 for exception
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pyHook\HookManager.py", line 351, in KeyboardSwitch
return func(event)
File "C:\Users\123\Desktop\code\hooks.py", line 20, in OnKeyboardEvent
threading.Timer(1,triger).start()
File "C:\Python27\lib\threading.py", line 731, in Timer
return _Timer(*args, **kwargs)
File "C:\Python27\lib\threading.py", line 742, in __init__
Thread.__init__(self)
File "C:\Python27\lib\threading.py", line 446, in __init__
self.__daemonic = self._set_daemon()
File "C:\Python27\lib\threading.py", line 470, in _set_daemon
return current_thread().daemon
File "C:\Python27\lib\threading.py", line 828, in currentThread
return _active[_get_ident()]
TypeError: an integer is required