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'

相关推荐
@zulnger18 小时前
Django 模型
后端·python·django
huwei85318 小时前
python设计通用表格类 带右键菜单
开发语言·windows·python
计算机毕业编程指导师18 小时前
【计算机毕设选题】基于Spark的拉勾网招聘数据分析系统源码,Python+Django全流程
大数据·hadoop·python·spark·django·招聘·拉勾网
duyinbi751718 小时前
TOOD_R50_FPN_Anchor-Based_1x_COCO_列车悬挂部件检测分类实战
python
学习3人组18 小时前
大模型轻量化调优(昇腾平台方向)岗位技术名词拆解
人工智能·python
知乎的哥廷根数学学派18 小时前
基于物理引导和不确定性量化的轻量化神经网络机械退化预测算法(Python)
人工智能·pytorch·python·深度学习·神经网络·算法·机器学习
xj75730653318 小时前
Django 面试常见问题
python·面试·django
a努力。18 小时前
得物Java面试被问:Netty的ByteBuf引用计数和内存释放
java·开发语言·分布式·python·面试·职场和发展
写代码的【黑咖啡】19 小时前
Python中的JSON处理(标准库)
开发语言·python·json
梨子串桃子_1 天前
推荐系统学习笔记 | PyTorch学习笔记
pytorch·笔记·python·学习·算法