[python-win32] hook the left mouse button down event on any window

Zhao Lee redstone-cold at 163.com
Thu Mar 28 10:08:32 EDT 2019


I originally posted the question here , please help ,thank you !




I want to hook the left mouse button down event on any window, my code as following :
import win32guiimport win32uiimport win32condef onMousePressed(self):
    print('onMousePressed', win32gui.GetCursorPos())def listener():
    windowHandle = win32gui.WindowFromPoint(win32gui.GetCursorPos())
    clickedWindow = win32ui.CreateWindowFromHandle(windowHandle)
    clickedWindow.HookMessage(onMousePressed, win32con.WM_LBUTTONDOWN)
    # print('-------------registerMouseEvent', clickedWindow)whileTrue:
    listener()

However , the onMousePressed function was never called when clicked, what is wrong ?

P.S. I know some similar projects such as PyUserInput, mouse, pynput, just want to know why my code didn't work.






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20190328/d4b3aaeb/attachment-0001.html>


More information about the python-win32 mailing list