Reputation: 371
I am using python's win32 module to create a simple click() method, which should emulate a mouse click, but unfortunately my approach is not working.
def click(x, y):
hWnd = win32gui.FindWindow(None, "SomeWindowTitle")
lParam = win32api.MAKELONG(x, y)
win32gui.PostMessage(hWnd, WM_LBUTTONDOWN, MK_LBUTTON, lParam);
win32gui.PostMessage(hWnd, WM_LBUTTONUP, MK_LBUTTON, lParam);
...
timer = Timer(30, click, [x, y])
timer.start()
I am thankful for every hint!
Upvotes: 0
Views: 6648
Reputation: 371
I got it working now.. The above code is working well, the only thing I was not aware of was that I was getting my cursor position from win32api.GetCursorPos()
in screen coordinates, but win32gui.PostMessage()
needed the relative coordinates of the hWnd. Simply converting it with ScreenToClient()
did the trick.
Upvotes: 5