Zhao Lee wrote:
I originally posted the question here <https://stackoverflow.com/questions/55399565/hook-the-left-mouse-button-down-event-on-any-window>, please help ,thank you !Your code came across badly formatted, so I can't tell exactly what you wrote. You aren't actually calling listener() from within a continuous, tight CPU loop, are you? This function is going to get called thousands and thousands of times a second. This is very poor practice, and it's part of the reason these other modules exist.I want to hook the left mouse button down event on any window, my code as following : |importwin32guiimportwin32uiimportwin32condefonMousePressed(self):print('onMousePressed',win32gui.GetCursorPos())deflistener(): 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 <https://github.com/PyUserInput/PyUserInput>, mouse <https://github.com/boppreh/mouse>, pynput <https://pythonhosted.org/pynput/keyboard.html#monitoring-the-keyboard>, just want to know why my code didn't work.
You attach to an external window, install your mouse message hook, then your function exits, the window object is deleted, and the hook is released.
-- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc.
smime.p7s
Description: S/MIME Cryptographic Signature
_______________________________________________ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32