I am trying to use pyhooks to detect mouse clicks anywhere on the screen. The problem is that I can get it to work with PumpMessages (). I would like it to work inside the while loop that I created. Is there a way to accomplish this / why does he need pump messages?
def onclick(event):
print 'Mouse click!'
return True
hm = pyHook.HookManager()
hm.MouseLeftDown = onclick
hm.HookMouse()
pythoncom.PumpMessages()
hm.UnhookMouse()
This is the only way to make it work.
I am trying to execute something like this:
sTime = time.time()
def onclick(event):
global sTime
print 'Time between clicks equals: %i' % time.time() - stime
sTime = time.time()
return True
hm.MouseLeftDown = OnClick
while True:
hm.HookMouse()
EDIT: I'm not a smart person. There is no need for a while loop in the script.
Sigh..
source
share