python库--pyautogui————windows模拟鼠标键盘、图像自动匹配、按钮弹窗

python库--pyautogui------------windows模拟鼠标键盘、图像自动匹配、按钮弹窗


一、模拟鼠标

鼠标移动

1s内匀速移动到坐标(100, 200)处

python 复制代码
pyautogui.moveTo(100, 200, duration=1)

1s内相对右移100,下移200

python 复制代码
pyautogui.moveRel(100, 200, duration=1)

鼠标点击

按下、松开

python 复制代码
pyautogui.mouseDown()
pyautogui.mouseUp()

对坐标(100, 200)点击3次左键,间隔为1s

python 复制代码
pyautogui.click(100, 200, clicks=3, interval=1, button='right')

滚轮向上滚100

python 复制代码
pyautogui.scroll(100)

二、模拟键盘

输入字符串s,每个字符输入间隔为0.5s

python 复制代码
pyautogui.typewrite(s, interval=0.5)

按键(键值在文章最下方)

按下、松开回车

python 复制代码
pyautogui.keyDown('enter')
pyautogui.keyUp('enter')

按顺序点击

python 复制代码
pyautogui.press(['enter', 'shift', 'tab'])

点击组合键

python 复制代码
pyautogui.hotkey('ctrl', 'v')

三、图像自动匹配

需要安装opencv库(pip install opencv-python)

获取图片在当前屏幕的所在位置的中心坐标,confidence为精度

python 复制代码
x, y = pyautogui.locateCenterOnScreen(r'.\**.png', confidence=0.9)

四、弹窗

带有一个按钮的弹窗,点击按钮后会返回button中的值(string)

python 复制代码
a = pyautogui.alert(text='', title='', button='abc')

带有多个按钮的弹窗,点击按钮后会返回对应buttons的值(string)

python 复制代码
a = pyautogui.confirm(text='', title='', buttons=['a', 'b', 'c'])

可输入内容的弹窗,自带OK与Cancel按钮,点击OK会返回输入的值,点击Cancel会返回None

python 复制代码
a = pyautogui.prompt(text='', title='', default='')

用于输入密码的弹窗,输入值会用mask中的字符代为显示,自带OK与Cancel按钮,点击OK会返回输入的值,点击Cancel会返回None

python 复制代码
a = pyautogui.password(text='', title='', mask='*')

五、按键名称

'a', 'b', 'c', ..., 'z'

'0', '1', '2', ..., '9'

'f1', 'f2', ..., 'f12'

'enter', 'esc', 'shift', 'shiftleft', 'shiftright', 'ctrl', 'ctrlleft', 'ctrlright', 'alt', 'altleft', 'altright', 'tab', 'capslock'

'up', 'down', 'left', 'right', 'home', 'end', 'pagedown', 'pageup'

'backspace', 'delete', 'insert'

'space', 'enter', 'esc'

'', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '[', '{', ']', '}', '', '|', ';', ':', '"', ',', '<', '.', '>', '/', '?'

'numlock', 'num0', 'num1', ..., 'num9', 'numdivide', 'nummultiply', 'numsubtract', 'numadd', 'numdecimal'

相关推荐
iuu_star2 分钟前
跑通最简单的Vue3+Python前后端分离项目
前端·vue.js·python
li星野7 分钟前
双指针 & 贪心算法六题通关:从回文串到跳跃游戏(Python + C++)
python·游戏·贪心算法
WL_Aurora7 分钟前
Python 算法基础篇之元组与列表
python·算法
颜安青16 分钟前
【python】运算符号(后续不断补充)
开发语言·python
于先生吖17 分钟前
家政派单小程序源头厂家
python
于先生吖19 分钟前
口碑好的家政派单小程序
python
深度学习lover22 分钟前
<数据集>yolo 货车识别<目标检测>
人工智能·python·yolo·目标检测·计算机视觉·货车识别
geovindu24 分钟前
Python: Condition Variable Pattern
开发语言·python·设计模式·条件变量模式
yuanpan27 分钟前
Python + Pillow 实战:开发一个图片批量格式转换工具
python·microsoft·pillow
YJlio30 分钟前
2023-09-25:ChatGPT 开始支持“看、听、说”,从纯文本正式迈向多模态交互
人工智能·python·科技·chatgpt·django·交互·pygame