创建一个 VB 脚本以发送密钥以打开具有特定设置的程序 [英] Create a VB script to send the keys to open up a program with specific settings

查看:18
本文介绍了创建一个 VB 脚本以发送密钥以打开具有特定设置的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 VB 脚本来发送密钥以打开具有特定设置的程序/应用程序.因此,在应用程序启动后,选择那些非常具体的设置将涉及按下应用程序 UI 中的 2 个按钮(第一个按钮用于选择特定的选项集,第二个按钮用于保存这些选项).

I am trying to create a VB script to send the keys to open up a program/application with specific settings. So, after the application has been started, choosing those very specific settings would involve pressing 2 buttons inside the application UI (1st button to choose specific set of options, and 2nd button to save those options).

然后我将创建一个批处理文件以在启动时调用提到的 VB 脚本.

I will then create a batch file to call the mentioned VB script on boot.

到目前为止,我得到了这个:

So far, I got this:

Set WshShell = WScript.CreateObject("WScript.Shell")WshShell.SendKeys "^%1"

我进行了搜索和搜索,但不知道如何在应用启动后选择/保存选项(如果可能的话)?

I've searched and searched, but couldn't figure out how to be able choose/save options once the app has been started, if it's even possible?

提前感谢您的帮助!

免责声明:我不是技术人员,如果菜鸟问题请见谅:)

Disclaimer: I am not a technical person, so forgive me if noob question :)

推荐答案

这是启动应用程序(记事本),然后向其发送一些按键的脚本:

Here's a script to start an application (notepad), then send some keystrokes to it:

'VBScript Example
Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run "c:\windows\notepad.exe"

' add delay here

WshShell.AppActivate "Notepad"

WshShell.SendKeys "Hello World!"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "abc"
WshShell.SendKeys "{CAPSLOCK}"
WshShell.SendKeys "def"

也许这可以适应您的需求?

Perhaps this can be adapted to your needs?

WshShell.AppActivate 命令用于将程序(具有指定窗口标题)置于前台.

The WshShell.AppActivate command is used to bring the program (with the specified window title) to the foreground.

您可能想要添加延迟,以便在发送按键之前让程序有时间启动.这可以通过在 Wshell.Run 之后添加 sleep() 调用来完成:

You might want to add a delay to allow the program time to start before sending the keystrokes. This can be done by adding a sleep() call just after Wshell.Run:

' Sleep for 5 seconds (5000 msec)
WScript.Sleep(5000)

此外,这里有一个密钥代码列表可以使用.

Also, here's a list of key-codes that you can use.

这篇关于创建一个 VB 脚本以发送密钥以打开具有特定设置的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆