0
Python simulate click into specific window
Hi! I'm trying to make my script send click to a specific window (Calculator). I want it to send the click even if the Calculator is not on top of all windows. Heres the script, no erros but it doesnt seem to do a click... import win32gui import win32api import win32con def click(x, y): hWnd = win32gui.FindWindow(None, "Calculator") lParam = win32api.MAKELONG(x, y) win32api.SendMessage(hWnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lParam) win32api.SendMessage(hWnd, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, lParam) click(90,300)
4 Réponses
+ 4
You can try the PyUserInput https://github.com/PyUserInput/PyUserInput it's a wrapper
+ 2
Starting extract of the README.md file displaying on @Alex linked page:
"PyUserInput
A module for cross-platform control of the mouse and keyboard in python that is simple to use.
Mouse control should work on Windows, Mac, and X11 (most Linux systems). Scrolling is implemented, but users should be aware that variations may exist between platforms and applications.
Keyboard control works on X11(linux) and Windows systems. Mac control is a work in progress."
0
Thanks for the quick reply, Alex! Ive been trying to solve this issue whole day, and now Im on phone.
Do pyuserinput work on windows/programs that are not on top? Also, supporting python 3.6?
0
The example code seemed to work for me... I'm using windows 10 & I didn't run the code as administrator.
(I'm using it to autoclick Minecraft in the background & have chrome open in front)
Not sure why it wouldn't work, but maybe the coordinates are wrong - ?