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'

相关推荐
Shorasul3 分钟前
golang如何实现设备数据采集网关_golang设备数据采集网关实现要点
jvm·数据库·python
慕涯AI7 分钟前
Agent 30 课程开发指南 - 第19课
人工智能·python
2301_764150569 分钟前
如何用 some 检测数组中是否存在至少一个满足条件的项
jvm·数据库·python
我是无敌小恐龙15 分钟前
线下班第一课
python·考研·django·ai编程
_oP_i17 分钟前
python 之playwright 介绍
开发语言·python
@不误正业24 分钟前
大模型注意力机制源码解析-从MQA到MLA全链路演进与PyTorch实现
人工智能·pytorch·python
weixin_4087177725 分钟前
CSS如何优化大型项目样式_使用SASS预处理器提升开发效率
jvm·数据库·python
2301_8135995529 分钟前
CSS如何解决CSS引入后的样式覆盖_理解优先级原则避免重写
jvm·数据库·python
Li emily39 分钟前
外汇api接口实践:实时汇率与历史数据获取
人工智能·python·api·fastapi
weixin_4087177744 分钟前
PHP8.1新特性对AI开发帮助_JIT编译优势【解答】
jvm·数据库·python