Create a VBscript to send the keys to open up a program with specific settings

后端 未结 1 1409
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-22 03:26

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 s

相关标签:
1条回答
  • 2020-12-22 03:29

    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?

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

    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.

    0 讨论(0)
提交回复
热议问题