我需要在名为Arthropod的Adobe Air应用程序中单击一个名为"save"的按钮.我可以使用以下命令在bat文件中启动应用程序:
cd C:\Program Files\Arthropod
start /w Arthropod.exe
Run Code Online (Sandbox Code Playgroud)
弹出后,UI上有一个保存按钮.如何使用bat文件单击它?
我正在读这个:
http://www.ehow.com/how_7788761_press-buttons-batch-file.html
它展示了如何模拟MS Word中文件菜单和其他标签的点击,但是如何在任何其他按钮上执行此操作?
PS按钮上的文字是"保存",这是我能想到的唯一标识符.有没有什么是批处理我可以说(伪代码):
$('button[text="Save"]').click();
Run Code Online (Sandbox Code Playgroud)
Jam*_*s K 14
没有本地方式可以干净利落地完成这项工作.
但是VBS如果你愿意,可以用来模拟击键,类似于AutoIT,但是没有灵活性.在Plus方面,您无需下载VBS.它自95年以来一直包含在Windows的每个版本中.
我将包含一个启动的示例notepad.exe,然后在其中键入以下内容:
Hello World!
abcDEF
Run Code Online (Sandbox Code Playgroud)
.
调用以下单行LaunchNotepad.bat:
cscript /nologo LaunchNotepad.vbs
Run Code Online (Sandbox Code Playgroud)
.
以下是内容LaunchNotepad.vbs:
' Create WScript Shell Object to access filesystem.
Set WshShell = WScript.CreateObject("WScript.Shell")
' Start / Run NOTEPAD.EXE
WshShell.Run "%windir%\notepad.exe"
' Select, or bring Focus to a window named `NOTEPAD`
WshShell.AppActivate "Notepad"
' Wait for 5 seconds
WScript.Sleep 5000
WshShell.SendKeys "Hello World!"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "abc"
WshShell.SendKeys "{CAPSLOCK}"
WshShell.SendKeys "def"
Run Code Online (Sandbox Code Playgroud)
请注意,如果有一个或多个Notepad.exe已打开的实例,并且打开记事本需要5秒以上,则上面的代码可以选择记事本的最后一个活动实例并输入.
为了使VBS代码按您的需要工作,您需要学习如何通过键盘在Adobe Air中导航.通常选项卡和/或箭头键就足够了.有时您可能需要使用ALT键进入菜单.
此外,您实际上可以使用一系列键盘命令,如ALT+ FSENTER,甚至键盘快捷键如CTRL+ S.
要发送TAB,ALT+ F和CTRL+ S:
WshShell.SendKeys "{TAB}" ' TAB TAB Key
WshShell.SendKeys "%F" ' ALT-F (F)ile Menu
WshShell.SendKeys "^S" ' CTRL-S Save File
WshShell.SendKeys "%(Fa){ENTER}" ' ALT-F+ALT-A ENTER (F)ile -> Save (A)s -> (ENTER)
WshShell.SendKeys "{UP}" ' Up Arrow Up Arrow
WshShell.SendKeys "{DOWN}" ' Down Arrow Down Arrow
WshShell.SendKeys "{LEFT}" ' Left Arrow Left Arrow
WshShell.SendKeys "{RIGHT}" ' Right Arrow Right Arrow
Run Code Online (Sandbox Code Playgroud)