How does one control the mouse cursor in Python, i.e. move it to certain position and click, under Windows?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Pynput is the best solution I have found, both for Windows and for Mac. Super easy to program, and works very well.
For example,
Another option is to use the cross-platform AutoPy package. This package has two different options for moving the mouse:
This code snippet will instantly move the cursor to position (200,200):
If you instead want the cursor to visibly move across the screen to a given location, you can use the smooth_move command:
Linux
Source: Python mouse move in 5 lines of code (Linux only).
Try with the PyAutoGUI module. It's multiplatform.
And so:
It also has other features:
This is much easier than going through all the win32con stuff.
Quick and dirty function that'll left click wherever
clicks
times on Windows 7 using thectypes
library. No downloads required.You can use
win32api
orctypes
module to use win32 apis for controlling mouse or any guiHere is a fun example to control mouse using win32api:
A click using ctypes: