Python 详细教程 —— pyautogui 库 基本用法
目录
1. 安装及详细使用说明(表格)
1.1 安装
pip install pyautogui
1.2 详细使用说明(表格)
注:以下为详细教程
2. 鼠标操作自动化
2.1 定位(获取鼠标的 x,y 坐标)
import pyautogui pyautogui.position()
2.2 单击&双击
2.2.1 单击
import pyautogui x = 100 y = 100 button = left #x,y 为 单击坐标,button 为 鼠标左或右键点击(left / right) pyautogui.click(x,y,button = button)
2.2.2 双击
import pyautogui x = 100 y = 100 button = right #x,y 为 双击坐标,button 为 鼠标左或右键点击(left / right) pyautogui.doubleClick(x,y,button = button)
2.3 移动
import pyautogui x = 100 y = 100 s = 2 #x,y 为 移动目标坐标,s 为 移动时间(秒) pyautogui.move(x,y,s)
2.4 拖动
import pyautogui x = 100 y = 100 s = 2 button = left # x , y 为 拖动目标坐标,s 为 移动时间(秒), button 为 鼠标左或右键点击(left / right) pyautogui.drag(x,y,s,button = button)
2.5 滚轮滚动
import pyautogui l = 10 # l 为 滚动格数 pyauotgui.scroll(l) #向上滚动l格
3. 键盘操作自动化
3.1 写英文段落
import pyautogui text = hello world interval = 0.25 #text 为写的文字(仅支持英文),interval 为按下每个按键后停留的时间 pyautogui.write(text,interval=interval)
3.2 按键
import pyautogui key = a #key 为要按下的按键 pyautogui.press(key)
3.3 按住按键
import pyautogui with pyautogui.hold(ctrl): pyautogui.press([right,right,right]) # 先按住ctrl,再按三次right,再释放ctrl
3.4 按快捷键
import pyautogui pyautogui.hotkey(ctrl,c) #按下 ctrl + c 组合键
