M. Dou
M. Dou

Reputation: 45

Permanently press key via vbs (Keep key pressed)

I wrote this little vbs script to press the left arrow key in my Chrome browser:

set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "Google Chrome"
WshShell.SendKeys "{LEFT}"

But it simulates a keypress with instant releases. Is there also a way to parse the pressed key over a longer time?

(I know that this would be easy to handle in Javascript by the Keypress even, but I am trying to learn vbs.)

Upvotes: 1

Views: 2648

Answers (1)

Regis Desrosiers
Regis Desrosiers

Reputation: 565

The WshShell object does not provide a way to send KeyUp and KeyDown events. To closest you can get to what you want to do is by doing repetitions of the same key. This can be done by putting the .SendKeys in a loop or by putting a number after the key within the braces.

set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "Google Chrome"
WshShell.SendKeys "{LEFT 40}"

Upvotes: 1

Related Questions