import pyWinhook as pyHook
import time
def OnMouseEventLeft(event):
print('MessageName: %s' % event.MessageName)
time.sleep(2) //Intentional delay
print("------")
return True
def OnKeyboardEvent(event):
print('Key: %s' % event.Key)
print('---')
return True
hm = pyHook.HookManager()
hm.MouseLeftDown = OnMouseEventLeft
hm.KeyDown = OnKeyboardEvent
hm.HookMouse()
hm.HookKeyboard()
if __name__ == '__main__':
import pythoncom
pythoncom.PumpMessages()
In the above code, if we delay one callback (OnMouseEventLeft), why is it affecting the other callback (OnKeyboardEvent). When I run this code, if I click and type a character in notepad(quickly within 2 seconds), the keyboard callback(OnKeyboardEvent) is not invoked. I read the documentation in pyhook which mentions callbacks should be returned as quickly as possible, if not it can cause undesirable effect on the current callback chain. But, in this case, it looks like the effect is seen in the next callback chain. What can be causing this? Is this expected?