Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize sendkeys simulated keystroke by VBS

Shulou Source: shulou.com Published: 2022-06-03 06:07:17 09月22日 Update

Editor to share with you how to achieve VBS sendkeys simulation keystroke operation, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The code is as follows:

'= =

'SendKeys simulates keyboard keystrokes in VBS

'2009-07-26

'= =

Dim WshShell

Set WshShell=WScript.CreateObject ("WScript.Shell")

WshShell.Run "cmd"

'Let the script wait 1000 milliseconds, that is, 1 second before executing the next statement

WScript.Sleep 1000

When sending characters, the input method must be in the English file state

'send semicolon

WshShell.SendKeys ";"

WScript.Sleep 1000

'send a colon

WshShell.SendKeys ":"

WScript.Sleep 1000

'send double quotes-use chr to convert double quotation marks

WshShell.SendKeys Chr (34)

WScript.Sleep 1000

'send a string with double quotation marks

WshShell.SendKeys Chr (34) & "this is a string" & Chr (34)

WScript.Sleep 1000

Remember, this is a simulated keystroke operation, so it cannot be sent in Chinese

'WshShell.SendKeys Chr (34) & "this is a string" & Chr (34)

WScript.Sleep 1000

'=

'--how to simulate enter, upper key, Alt key?

'=

'--how to simulate enter,-- {enter} this means that it is sent to enter.

WshShell.SendKeys "this is an enter! {enter}"

WScript.Sleep 1000

'--how to simulate the upfile key Shift,-+ this means sending shift

WshShell.SendKeys "this is + a" result is this is A

WScript.Sleep 1000

'--how to simulate Alt,--% this means sending Alt

WshShell.SendKeys "this is% {TAB}" 'result is a toggle window

WScript.Sleep 1000

'=

'--so how to send%, + ^ murmur

WshShell.SendKeys "this is {+} {^} {%}" 'result is a toggle window

WScript.Sleep 1000

You may already understand here, when sending special characters, please put them in {}

'=

'= =

For more information, see the VBS help documentation 2009-07-26

'= =

The above is all the content of the article "how to achieve sendkeys simulated keystroke operation by VBS". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Characters representations quotes articles results content strings more toggle help special not so much that is code information colons semicolons most files documents Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker OPPO Reno Redmi macOS Microsoft