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'
pyautogui.click(x,y,button = button)
2.2.2双击
import pyautogui
x = 100
y = 100
button = 'right'
pyautogui.doubleClick(x,y,button = button)
2.3移动
import pyautogui
x = 100
y = 100
s = 2
pyautogui.move(x,y,s)
2.4拖动
import pyautogui
x = 100
y = 100
s = 2
button = 'left'
pyautogui.drag(x,y,s,button = button)
2.5滚动滚轮
import pyautogui
l = 10
pyautogui.scroll(l)
3.键盘操作及自动化
3.1写英文段落
import pyautogui
text = 'hello world'
interval = 0.25
pyautogui.write(text,interval=interval)
3.2按键
import pyautogui
key = 'a'
pyautogui.press(key)
3.3按住按键
import pyautogui
with pyautogui.hold('ctrl'):
pyautogui.press(['right','right','right'])
3.4按快捷键
import pyautogui
pyautogui.hotkey('ctrl','c')