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


猜你喜欢
- 前言最近在写行为识别的代码,涉及到两个网络的融合,这个融合是有加权的网络结果的融合,所以需要对网络的结果进行加权(相乘)和融合(相加)。最初
- Python安装为什么默认安装到c盘?所有的软件如果你不对安装过程的路径进行设置的话都是默认安装到c盘的,不仅仅是Python。那安装到c盘
- 红包:Lena椒盐噪声图片:# -*- coding: utf-8 -*-"""Created on Sat
- 本文实例讲述了Python中Django框架利用url来控制登录的方法。分享给大家供大家参考。具体如下:from django.conf.u
- 介绍在本文中,你将学习如何使用 Python 构建人脸识别系统。人脸识别比人脸检测更进一步。在人脸检测中,我们只检测人脸在图像中的位置,但在
- 目前为止,我们一直没有对函数声明和函数表达式加以区别。而实际上,解析器在向执行环境中加载数据时,对函数声明和函数表达式并非一视同仁。解析器会
- reader.html<html><head><meta http-equiv=&quo
- 先介绍一下jsSmarty Project:简要说明:利用JavaScript?在客户端完成SmartyPhp的工作,加速模板开发。主要是利
- 换用非默认浏览器时需要输入密码或token查询方法:在XX:\AnacondaXX\Scripts下 运行jupyter-notebook.
- 重置系统后,很久之前安装的MySQL数据库出现了控制台查询中文乱码问题,时间太久早已经不记得怎么设置了。网上查询了许多,各种设置,重启数据库
- 现在的垃圾留言越来越智能,并且从留言内容几乎看不出来是垃圾留言,而大量的垃圾留言会导致文章可读性下降,并可能会被搜索引擎惩罚,经过一段时间的
- 这礼拜碰到一些问题,然后意识到基础知识一段时间没巩固的话,还是有遗忘的部分,还是需要温习,这里做份笔记,记录一下前续先简单描述下碰到的题目,
- 在众多的浏览器产品中,IE、Firefox、Opera、Safari........众多品牌却标准不一,因此时常需要根据不同的浏览器,甚至相
- 场景:由于自己的电脑A性能不足,需要转移到一台高性能的主机B上运行python程序,但是该主机不能连接互联网。问题:在个人电脑A上建立了一个
- 最近,使用 golang 去管理本地应用的生命周期,期间有几个有趣的点,今天就一起看下。场景一我们来看看下面两个脚本会产
- 一、 操作数据库(mysql)的工具1.1命令行工具1.2navicat界面化工具1.3phpAdmin界面化工具一般情况下安装phpstu
- 学习前言在Github上我们可以看到许多模型,他们都有mAP值的评价指标,如下图所示:这到底是个啥呢?我查了好久的资料&hellip
- 步骤一:index页面处理<!DOCTYPE html><html lang="en"><
- 在介绍GROUP BY 和 HAVING 子句前,我们必需先讲讲sql语言中一种特殊的函数:聚合函数,例如SUM, COUNT, MAX,
- python正则表达式 匹配反斜杠正则 需要把原始字符串不被转义的条件下传递给正则模块,正则再去转义。 r表示r后面的字符串为原始字符串,防