我希望创建一个在PyHook中帮助记录鼠标点击位置的应用程序。在高水平,我想
使用pumpMessages块不是一种选择。如果我知道如何向pumpMessages发送退出消息,这可能是另一种选择。我试图使用pythoncom.PumpWaitingMessages(),这似乎是一个完美的ft,但每次单击鼠标时都会导致异常。我一直无法调试原因。
def onclick(event):
global hm
try:
print (str(event.Position))
hm.UnhookMouse()
except:
pass
# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.SubscribeMouseLeftDown(onclick)
# set the hook
hm.HookMouse()
# wait forever
pythoncom.PumpWaitingMessages()
错误,正如所见:
Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
>>> (187, 505)
Traceback (most recent call last):
** IDLE Internal Exception:
File "C:\Python34\lib\idlelib\run.py", line 121, in main
seq, request = rpc.request_queue.get(block=True, timeout=0.05)
File "C:\Python34\lib\queue.py", line 175, in get
raise Empty
queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
** IDLE Internal Exception:
File "C:\Python34\lib\idlelib\run.py", line 121, in main
seq, request = rpc.request_queue.get(block=True, timeout=0.05)
File "C:\Python34\lib\queue.py", line 176, in get
self.not_empty.wait(remaining)
File "C:\Python34\lib\threading.py", line 294, in wait
gotit = waiter.acquire(True, timeout)
TypeError: an integer is required (got type NoneType)