您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Python上模拟键盘和鼠标的最简单方法是什么?

在Python上模拟键盘和鼠标的最简单方法是什么?

我在Python中进行自动化测试。我倾向于使用以下内容

http://www.tizmoi.net/watsup/intro.html 链接已消失,存档版本: https ://web.archive.org/web/20100224025508/http : //www.tizmoi.net/watsup/ intro.html

http://www.mayukhbose.com/python/IEC/index.php

我并不总是(几乎从不)模拟按键和鼠标移动。我通常使用COM来设置Windows对象的值并调用它们的.click()方法

您可以通过以下方式发送按键信号:

import win32com.client

shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys("^a") # CTRL+A may "select all" depending on which window's focused
shell.SendKeys("{DELETE}") # Delete selected text?  Depends on context. :P
shell.SendKeys("{TAB}") #Press tab... to change focus or whatever

这一切都在Windows中。如果您在另一个环境中,我不知道。

python 2022/1/1 18:34:42 有216人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶