0

I am using this code to detect mouse position with pyhook in Windows. What I need is to detect mouse click and add delay before execution - scenario: I click with mouse but this click should be 0.5 second delayed (so click should be executed after 0.5 second). Is this possible somehow?

import pyHook
import pythoncom

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

hm = pyHook.HookManager()
hm.SubscribeMouseAllButtonsDown(onclick)
hm.HookMouse()
pythoncom.PumpMessages()
hm.UnhookMouse()
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
peter
  • 4,289
  • 12
  • 44
  • 67

1 Answers1

0

Like this :

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 !

I hope it helps(TESTED).

dsgdfg
  • 1,492
  • 11
  • 18