目录

1. 安装及详细使用说明(表格)

1.1 安装

 1.2 详细使用说明(表格)

2. 鼠标操作自动化

2.1 定位(获取鼠标的 x,y 坐标)

2.2 单击&双击

2.2.1 单击

2.2.2 双击 

2.3 移动

2.4 拖动

2.5 滚轮滚动

3. 键盘操作自动化

3.1 写英文段落

3.2 按键

3.3 按住按键

3.4 按快捷键


1. 安装及详细使用说明(表格)

1.1 安装

pip install pyautogui

 1.2 详细使用说明(表格)

用途

代码

获取位置

posititon

单击

click

双击

doubleClick

移动

move,moveTo

拖动

drag,dragTo

写英文段落

write

按键

press

按住按键

hold

按快捷键

hotkey

注:以下为详细教程 

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 组合键