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'

相关推荐
孟健12 小时前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
码路飞13 小时前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽16 小时前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers
敏编程20 小时前
一天一个Python库:jsonschema - JSON 数据验证利器
python
前端付豪20 小时前
LangChain记忆:通过Memory记住上次的对话细节
人工智能·python·langchain
databook21 小时前
ManimCE v0.20.1 发布:LaTeX 渲染修复与动画稳定性提升
python·动效
花酒锄作田1 天前
使用 pkgutil 实现动态插件系统
python
前端付豪2 天前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽2 天前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战2 天前
Pydantic配置管理最佳实践(一)
python