安装代码
pip install pyautogui
简介
PyAutoGUI可以模拟移动鼠标,单击鼠标,用鼠标拖动,按键,按住键,然后按键盘热键组合。
<获取当前屏幕分辨率>
screenWidth, screenHeight = pyautogui.size()
'''
案例
让鼠标移动屏幕中央
'''
import pyautogui
screenWidth, screenHeight = pyautogui.size()
pyautogui.moveTo(screenWidth/2, screenHeight/2)
<获取当前鼠标位置>
mouseX, mouseY = pyautogui.position()
<鼠标移动>
绝对移动
pyautogui.moveTo(x,y)
相对移动
pyautogui.moveRel(x,y)
移动速度
pyautogui.moveTo(x, y, duration = 0.5)
<鼠标点击>
鼠标双击
pyautogui.click() = pyautogui.mouseDown() + pyautogui.mouseUp()
鼠标左击
pyautogui.click(x, y, button = 'left')
鼠标右击
pyautogui.click(x, y, button = 'right')
<拖动鼠标>
绝对拖动
pyautogui.dragTo()
相对拖动
pyautogui.dragRel()
限速
set duration()
import pyautogui
import time
long = 700
temp = 6
time.sleep(3)
while long>0:
pyautogui.dragRel(long, 0) # move right
long -= temp
pyautogui.dragRel(0, long) # move down
pyautogui.dragRel(-long, 0) # move left
long -= temp
pyautogui.dragRel(0, -long) # move up
绘制方形螺旋形状
网友评论