Python3 模擬鼠標點擊
1. 安裝 pywin32
適用於 Microsoft Windows 的 Python 擴展 提供對大部分 Win32 API 的訪問、創建和使用 COM 對象的能力以及 Pythonwin 環境。
Project description
Python extensions for Microsoft Windows Provides access to much of the Win32 API,
the ability to create and use COM objects, and the Pythonwin environment.
安裝:
pip install pywin32
或
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pywin32 - 使用國內鏡像
2. 安裝 py-Hook
pyHook 包為 Windows 中的全局鼠標和鍵盤事件提供回調。Python 應用程序為用戶輸入事件(例如鼠標左鍵按下、鼠標左鍵按下、按鍵按下等)注冊事件處理程序,並設置鍵盤和/或鼠標掛鈎。底層 C 庫報告諸如事件時間、發生事件的窗口名稱、事件值、任何鍵盤修飾符等信息。
Project description
The pyHook package provides callbacks for global mouse and keyboard events in
Windows. Python applications register event handlers for user input events such as
left mouse down, left mouse up, key down, etc. and set the keyboard and/or mouse
hook. The underlying C library reports information like the time of the event, the
name of the window in which the event occurred, the value of the event, any keyboard
modifiers, etc.
安裝:
由於 PytHook 沒有與 python3.9 相對應的版本
直接下再PyHook3, 例: PyHook3-1.6.1.tar.gz. (網 址:https://pypi.org/project/PyHook3/#files)

-
方法 1
下載成功后, 將壓縮包解壓:
-
打開cmd
-
到達解壓的文件目錄中
-
python setup.py build。 -
將生成的文件放到 C:\Python3.7\Lib\site-packages\ 中。
-
-
方法 2
下載成功后, 將壓縮包解壓:
-
打開cmd
-
到達解壓的文件目錄中
-
python setup.py build -
python setup.py install
-
3. 安裝 PyUserInput
一個
簡單易用的python中跨平台控制鼠標和鍵盤的模塊。
Project description
PyUserInput
A module for cross-platform control of the mouse and keyboard in python that is
simple to use.
安裝:
pip install PyUserInput
或
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple PyUserInput - 使用國內鏡像
測試
from mouse import PyMouse
x = PyMouse()
txt = x.position() # 獲取當前坐標的位置
print(a)
x.move(50, 50) # 鼠標移動到(x,y)位置
x.click(50, 50) # 鼠標左擊(x,y)
x.click(50, 50, 2) # 鼠標右擊(x,y)
模塊詳情:https://pypi.org/
參考: https://www.cnblogs.com/newmiracle/p/12409037.html
