0

我正在寻找在 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)
4

0 回答 0