Python操作Windows
用python进行windows端UI自动化的库有很多,比如pywinauto等,本文介绍一个使用autoit3来实现的 pyautoit 库
pyautoit 是一个用python写的基于AutoItX3.dll的接口库,用来进行windows窗口的一系列操作,也支持鼠标键盘的操作。
安装
pip install pyautoit
import autoit # 注意:引用的模块名跟安装的模块名是不一样的
启动程序
autoit.run("notepad.exe")
窗口操作
autoit.win_wait_active(title="无标题- 记事本", timeout=10) # 等待窗口激活
autoit.win_exists("aaa") # 判断窗口是否存在
autoit.win_get_handle("无标题- 记事本") # 获取窗口句柄
autoit.win_activate("bbb") # 激活窗口
autoit.win_close("[CLASS:Notepad]") # 关闭窗口
此处,窗口标题的匹配模式也是可以自定义的,默认是1 -- 匹配开始部分,可以在脚本前面加上以下改为2--匹配子字符串:
autoit.opt("WinTitleMatchMode", 2)
控件操作
autoit.control_set_text("无标题", "Edit1", "12312313123") # 输入文字
autoit.control_click(title="title", control="controlid") # 点击
autoit.control_get_text(title="title", control="controlid") # 获取控件文本
autoit.control_command(title="title", control="controlid", command="command")
autoit.control_list_view(title="title", control="controlid", command="command")
autoit.control_tree_view(title="title", control="controlid", command="command")
进程操作
autoit.process.process_wait(process="process", timeout=10)
autoit.process.process_close("process")
autoit.process.process_exists("process")
鼠标操作
autoit.mouse_click(button='left', x=100, y=200, clicks=1, speed=-1)
autoit.mouse_move(x=200, y=300, speed=-1)
autoit.mouse_wheel(direction="down")
键盘操作
autoit.send("12312412")
autoit.send("+{F10}") # 发送shift+F10(右键效果)
autoit.send("^a") # 发送ctrl+a
其他
autoit.shutdown(2)
0 = Logoff 1 = Shutdown 2 = Reboot 4 = Force 8 = Power down
相关文章
- pywin32库 : Python 操作 windows 系统 API
- Python实现简单HTTP服务器
- Windows-Python 应用:使用消息操作窗口
- windows python web flask 编写 Hello World
- 学习Python的三种境界
- gyp ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- Python爬虫技术--基础篇--常用第三方模块Pillow和requests
- 【Python】【PyPI】twine模块打包python项目上传pypi
- Python编程-基础知识-python项目包和文件的管理以及如何引用相对路径的包和模块
- Python isinstance() 函数含义及用法解析
- 《Python参考手册(第4版•修订版)》——1.9 字典
- 《趣学Python——教孩子学编程》——1.5 你学到了什么
- 《Python自动化运维:技术与最佳实践》一导读
- 【Python分布式服务框架】python实现gRPC服务
- python This application failed to stat could not find or load the Qt platform plugin "windows"
- windows环境下学会使用conda 创建虚拟环境,解决python版本与库不兼容问题
- python利用 WMI 库操作windows
- 【Python注意事项】如何理解python中间generator functions和yield表情
- 2.1 The Python Interpreter(python解释器)
- 【爬虫系列】【Python】python with as的用法
- [Python]python+yaml三行代码完成配置文件灵活读取与warning:YAMLLoadWarning处理
- Selenium4 Python实现Page Factory设计模式,python新的定位方法