问题描述
我需要做一些宏,我想知道最推荐的做法是什么.
I need to do some macros and I wanna know what is the most recommended way to do it.
所以,我需要写一些东西并用它点击一些地方,我需要模拟 TAB 键.
So, I need to write somethings and click some places with it and I need to emulate the TAB key to.
推荐答案
我用 Python 做自动化测试.我倾向于使用以下内容:
I do automated testing stuff in Python. I tend to use the following:
链接已失效,存档版本:https://web.archive.org/web/20100224025508/http://www.tizmoi.net/watsup/intro.html
Link is dead, archived version: https://web.archive.org/web/20100224025508/http://www.tizmoi.net/watsup/intro.html
http://www.mayukhbose.com/python/IEC/index.php
我并不总是(几乎从不)模拟按键和鼠标移动.我通常使用 COM 来设置 windows 对象的值并调用它们的 .click() 方法.
I do not always (almost never) simulate key presses and mouse movement. I usually use COM to set values of windows objects and call their .click() methods.
你可以用这个发送按键信号:
You can send keypress signals with this:
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 中.如果你在另一个环境中,我不知道.
This is all in Windows. If you're in another environment, I have no clue.
这篇关于在 Python 上模拟键盘和鼠标的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!