python PyAutoGUI 模拟鼠标键盘操作和截屏功能
作者:lilongsy 发布时间:2022-11-12 08:16:41
标签:python,PyAutoGUI,鼠标,键盘,截屏
简介
一款跨平台/无依赖的自动化测试工具,目测只能控制鼠标/键盘/获取屏幕尺寸/弹出消息框/截屏。
安装
pip install pyautogui
鼠标键盘控制
>>> import pyautogui
>>> screenWidth, screenHeight = pyautogui.size()
>>> currentMouseX, currentMouseY = pyautogui.position()
>>> pyautogui.moveTo(100, 150)
>>> pyautogui.click()
>>> pyautogui.moveRel(None, 10) # move mouse 10 pixels down
>>> pyautogui.doubleClick()
>>> pyautogui.moveTo(500, 500, duration=2, tween=pyautogui.tweens.easeInOutQuad) # use tweening/easing function to move mouse over 2 seconds.
>>> pyautogui.typewrite('Hello world!', interval=0.25) # type with quarter-second pause in between each key
>>> pyautogui.press('esc')
>>> pyautogui.keyDown('shift')
>>> pyautogui.typewrite(['left', 'left', 'left', 'left', 'left', 'left'])
>>> pyautogui.keyUp('shift')
>>> pyautogui.hotkey('ctrl', 'c')
显示消息弹出框
>>> import pyautogui
>>> pyautogui.alert('This is an alert box.')
'OK'
>>> pyautogui.confirm('Shall I proceed?')
'Cancel'
>>> pyautogui.confirm('Enter option.', buttons=['A', 'B', 'C'])
'B'
>>> pyautogui.prompt('What is your name?')
'Al'
>>> pyautogui.password('Enter password (text will be hidden)')
'swordfish'
截屏
>>> import pyautogui
>>> im1 = pyautogui.screenshot()
>>> im1.save('my_screenshot.png')
>>> im2 = pyautogui.screenshot('my_screenshot2.png')
定位截屏
>>> import pyautogui
>>> button7location = pyautogui.locateOnScreen('button.png') # returns (left, top, width, height) of matching region
>>> button7location
(1416, 562, 50, 41)
>>> buttonx, buttony = pyautogui.center(button7location)
>>> buttonx, buttony
(1441, 582)
>>> pyautogui.click(buttonx, buttony) # clicks the center of where the button was found
参考
http://pyautogui.readthedocs.io/en/latest/index.html
https://github.com/asweigart/pyautogui
https://github.com/asweigart/sushigoroundbot
总结
以上所述是小编给大家介绍的python PyAutoGUI 模拟鼠标键盘操作和截屏功能,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
来源:https://blog.csdn.net/lilongsy/article/details/81607125
0
投稿
猜你喜欢
- 通过优化CSS代码,减小对系统资源的占用。自己整理出几个能减少系统资源占用的CSS写法,要优化网站的页面加载速度,这些注意点不能忽视!一、尽
- Q1 :如何解压 rar 压缩包文件?A :Step1:检查是否有 rarfile 第三方库,若没有该模块,则需要进行安装 ;Step2:参
- 1、可以在mode参数中添加'b'字符。所有适合文件对象的相同方法。然而,每种方法都希望并返回一个bytes对象。>&
- 环境:Windows, Python2.7一维情况:<span style="font-size:14px;"&g
- 我有个需求就是抓取一些简单的书籍信息存储到mysql数据库,例如,封面图片,书名,类型,作者,简历,出版社,语种。我比较之后,决定在亚马逊来
- 本文实例为大家分享了Python3实现飞机大战游戏的具体代码,供大家参考,具体内容如下1、主程序:plane_main.pyimport p
- 本文实例讲述了Python Django框架实现应用添加logging日志。分享给大家供大家参考,具体如下:Django uses Pyth
- 代码如下:declare @Q_ID uniqueidentifier set @Q_ID = dbo.uf_GetParamValueBy
- 本文实例讲述了python中while循环语句用法。分享给大家供大家参考。具体如下:number = 1while number <
- 环境变量配置首先需要将anaconda的路径配置进环境变量中,我是用户变量和系统变量都配置了。我的anaconda安装在D:\Anacond
- osql 工具是一个 Microsoft Windows 32 命令提示符工具,您可以使用它运行 Transact-SQL 语句和脚本文件。
- 公布到网页上的Email经常会被一些工具自动提取,一些非法用户就会利用所提取的Email大肆发送垃圾邮件。这些工具大多都是查找链接中“mai
- 众所周知,随着数据库体积的日益庞大,其备份文件的大小也水涨船高。虽然说通过差异备份与完全备份配套策略,可以大大的减小SQL Server数据
- 一、写在前面之前一直用putty,ssh,修改代码,或者本地修改,上传到服务器,各种不爽,现在改用xshell,但是有时候还是不方便感觉,于
- 本文实例借鉴mvc模式,核心数据为model,维护1个矩阵,0表无雷,1表雷,-1表已经检测过。本例使用python的tkinter做gui
- 概述从今天开始, 小白我将带领大家一起来补充一下 数据库的知识.条件查询我们可以使用关键词Where来指定条件, 用于插入, 修改删除或者查
- 不知道在坛子里有多少朋友使用触发器,如果你已经对触发器很了解了,那么请跳过此文,如果你还没有使用过触发器的话,那就让我们来认识一下吧。相关阅
- 本例详细介绍了如何在wiondws XP下安装与配置MySQL5.0.37 ,图文并茂,相信对初学mysql的朋友有所帮助。1 点击MySQ
- 1.文档对象模型(DOM)DOM是HTML和XML文档的编程基础,它定义了处理执行文档的途径。编程者可以使用DOM增加文档、定位文档结构、填
- 1-删除模型变量del model_define2-清空CUDA cachetorch.cuda.empty_cache()3-步骤2(异步