Python - pyautogui库 模拟鼠标和键盘执行GUI任务

安装库: pip install pyautogui

导入库:import pyautogui

获取屏幕尺寸

s_width, s_height = pyautogui.size()

获取鼠标当前位置

x, y= pyautogui.position()

移动鼠标到指定位置(可以先使用用上一个函数调试获取当前位置参数再使用):

pyautogui.moveTo(x, y) #x, y 是屏幕上的坐标

鼠标点击

pyautogui.click()

鼠标滚轮滚动

pyautogui.scrool(para)

键盘输入:

pyautogui.typewrite("text")

模拟键盘

pyautogui.hotkey("ctrl", "c")

按下和释放键盘

pyautogui.keyDown("left")

pyautogui.keyUp("left")

等待

pyautogui.sleep(2) #等待2秒

等待特定的图像出现

pyautogui.locateOnScreen()

相关推荐
关关钧29 分钟前
【R语言】R语言安装包的相关操作
开发语言·python·r语言
赔罪1 小时前
Python基础-使用list和tuple
windows·vscode·python·pycharm·list
米码收割机1 小时前
【python】python油田数据分析与可视化(源码+数据集)【独一无二】
开发语言·python·数据分析
花酒锄作田2 小时前
[python]png转webp的命令行工具
python
aiweker2 小时前
Python处理数据库:MySQL与SQLite详解
数据库·python
Amd7942 小时前
Python 与 PostgreSQL 集成:深入 psycopg2 的应用与实践
python·postgresql·数据分析·开发·最佳实践·psycopg2·数据库集成
查理零世3 小时前
【算法】回溯算法专题③ ——排列型回溯 python
python·算法·深度优先
游王子5 小时前
Python NumPy(6):修改数组形状、翻转数组、修改数组维度
开发语言·python·numpy
枫叶落雨2226 小时前
15JavaWeb——Maven高级篇
linux·python·maven