Having callbacks on MouseAllButtonsDbl, MouseLeftDbl, MouseRightDbl and MouseMiddleDb in HookManager just gives gives no effect what-so-ever. It seems that mouse double click events can't be caught.
Using windows 7 x64, Pyton 2.6.2, pywin32 214 and pyHook 1.5.1.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here's workarround solution for this problem - a LMB double-clicking handler example. It's pretty ugly, though working. I now that time.clock() method is rather inconvenient for building high-resolution timers, but it catches the 0.1 second difference. How fast can you double-click, anyway? ))
import pythoncom, win32gui, pyHook, time
state = 0 #LMB states: 0 - befire ckicks; 1 - after 1st down; 2 - after 1st up; 3 - after 2nd down
tstart = 0 #timer start
tend = 0 #timer end
double_click_speed = 0.5 #in seconds
#LMB down handler
def OnMouseLeftDown(event):
print 'MessageName:',event.MessageName
global state
global tstart
if state == 0:
tstart = time.clock()
print 'TStart: ' + str(tstart)
state = 1
elif state == 2:
state = 3
print 'State: ' + str(state)
print '-----'
# return True to pass the event to other handlers
return True
#LMB up handler
def OnMouseLeftUp(event):
print 'MessageName:',event.MessageName
global state
global tstart
global tend
if state == 1:
state = 2
elif state == 3:
state = 0
tend = time.clock()
tdiff = tend - tstart
print 'TEnd: ' + str(tend)
print 'Time: ' + str(tdiff)
if tdiff < double_click_speed :
OnMouseLeftDbl()
tstart = 0
tend = 0
print 'State: ' + str(state)
print '-----'
# return True to pass the event to other handlers
return True
#exit script by right click
def OnMouseRightDown(event):
print 'MessageName:',event.MessageName
print 'exit'
hm.UnhookMouse()
win32gui.PostQuitMessage(0)
# return True to pass the event to other handlers
return True
Having callbacks on MouseAllButtonsDbl, MouseLeftDbl, MouseRightDbl and MouseMiddleDb in HookManager just gives gives no effect what-so-ever. It seems that mouse double click events can't be caught.
Using windows 7 x64, Pyton 2.6.2, pywin32 214 and pyHook 1.5.1.
Here's workarround solution for this problem - a LMB double-clicking handler example. It's pretty ugly, though working. I now that time.clock() method is rather inconvenient for building high-resolution timers, but it catches the 0.1 second difference. How fast can you double-click, anyway? ))
import pythoncom, win32gui, pyHook, time
state = 0 #LMB states: 0 - befire ckicks; 1 - after 1st down; 2 - after 1st up; 3 - after 2nd down
tstart = 0 #timer start
tend = 0 #timer end
double_click_speed = 0.5 #in seconds
#LMB down handler
def OnMouseLeftDown(event):
print 'MessageName:',event.MessageName
global state
global tstart
if state == 0:
tstart = time.clock()
print 'TStart: ' + str(tstart)
state = 1
elif state == 2:
state = 3
print 'State: ' + str(state)
print '-----'
# return True to pass the event to other handlers
return True
#LMB up handler
def OnMouseLeftUp(event):
print 'MessageName:',event.MessageName
global state
global tstart
global tend
if state == 1:
state = 2
elif state == 3:
state = 0
tend = time.clock()
tdiff = tend - tstart
print 'TEnd: ' + str(tend)
print 'Time: ' + str(tdiff)
if tdiff < double_click_speed :
OnMouseLeftDbl()
tstart = 0
tend = 0
print 'State: ' + str(state)
print '-----'
# return True to pass the event to other handlers
return True
#exit script by right click
def OnMouseRightDown(event):
print 'MessageName:',event.MessageName
print 'exit'
hm.UnhookMouse()
win32gui.PostQuitMessage(0)
# return True to pass the event to other handlers
return True
#LMB double clicking handler
def OnMouseLeftDbl():
print 'DOUBLE CLICK!'
# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.MouseRightDown = OnMouseRightDown
hm.MouseLeftDown = OnMouseLeftDown
hm.MouseLeftUp = OnMouseLeftUp
# set the hook
hm.HookMouse()
print 'State: ' + str(state)
# wait for messages
pythoncom.PumpMessages()
Hi,
Thanks for the comment, and workaround!
I'll see if i can reproduce this when i get a chance, over the next few days...