Basically I have this code here:
import win32api
import win32con
import time
from random import randint
import pythoncom
import pyHook
import sys
semaphore = False
def OnMouseLeftUp(event):
global semaphore
if semaphore:
return True
semaphore = True
if randint(0, 10) < 4:
time.sleep(float(randint(6,9))/1000)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
semaphore = False
return True
# create a hook manager
hm = pyHook.HookManager()
# set the hook
hm.HookMouse()
# waits for MouseLeftUp event
hm.MouseLeftUp = OnMouseLeftUp # Triggers OnMouseLeftUp function
# wait forever
pythoncom.PumpMessages()
I need to delay win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
for about 50 ms but if I use time.sleep the whole code gets stopped for that time. Therefore, the mouse Hook gets stopped as well so my computer stops recording mouse inputs for that time and that's really annoying. I would need a solution to delay that win32api function without stopping the whole code. Any suggestion is greatly appreciated.