延迟鼠标点击 0.5 秒

Delay mouse click 0.5 second

我在 Windows 中使用此代码通过 pyhook 检测鼠标位置。我需要的是检测鼠标点击并在执行前添加延迟 - 场景:我用鼠标点击但这次点击应该延迟 0.5 秒(所以点击应该在 0.5 秒后执行)。这有可能吗?

import pyHook
import pythoncom

def onclick(event):
    print event.Position
    return True

hm = pyHook.HookManager()
hm.SubscribeMouseAllButtonsDown(onclick)
hm.HookMouse()
pythoncom.PumpMessages()
hm.UnhookMouse()

像这样:

import pyHook
import pythoncom
import time
import thread

class _HK :
    def __init__(self):
        self.ev = None
    def run(self,passarg):
        pythoncom.CoInitialize()
        while True :
            if self.ev != None :
                time.sleep(1)
                print self.ev.Position
                self.ev = None

HK = _HK()
s = thread.start_new_thread(HK.run,(None,))


def onclick(event):

    HK.ev = event

    return True

hm = pyHook.HookManager()
hm.SubscribeMouseAllButtonsDown(onclick)
hm.HookMouse()
pythoncom.PumpMessages()
hm.UnhookMouse()

Other definitions are invalid if the application is focused on a process. Initially the process must be resolved by the system. It can then access internal and external components. pythoncom.CoInitialize() require for a function or additional process !

希望对您有所帮助(已测试)。