pyHook - PumpWaitingMessages抛出execption而PumpMessages没有

时间:2014-08-01 15:34:21

标签: python python-3.x pyhook

我希望创建一个在PyHook中帮助记录鼠标点击位置的应用程序。在高水平,我想

  • 将鼠标单击绑定到方法或功能
  • 当用户点击鼠标时,取消勾选鼠标
  • 在我的程序中做一些事情,稍后重新绑定鼠标(hookMouse)并等待再次点击

使用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)

0 个答案:

没有答案
相关问题