To click on specific coordinates by the left mouse button in Python, we can use the pynput
library, which allows us to control and monitor input devices like a mouse or keyboard.
Here is an example code to click on coordinates (x,y) using the left mouse button:
main.py331 chars16 lines
In the above code, we first import the Button
and Controller
classes from the pynput.mouse
module. Then, we create a Controller
object to control the mouse.
Next, we set the coordinates of the point where we want to click by assigning values to the x
and y
variables.
After that, we move the mouse pointer to the desired coordinates by setting the position
attribute of the mouse object to a tuple of the (x, y)
values.
Finally, we issue the "click" by pressing the left button down ("press") and releasing it immediately after ("release").
gistlibby LogSnag