1

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.)

M. Dou
  • 45
  • 5
  • Simulating VBScript to press a key in an Internet Browser Window is not learning VBScript. VBScript is capable of using `KeyPress` event you just have to do it in a browser that supports VBScript like IE *(not in Edge mode)*. Technically WScript isn't even VBScript, it is just another runtime that can host VBScript, so your not really learning much at all. – user692942 Feb 23 '17 at 17:23
  • @Lankymart The thing I wanted to learn is how to hold down a key without triggering the event in my browser. I thought vbs could be good for that. Looks like I was wrong. – M. Dou Feb 23 '17 at 17:27
  • That's a bit different to what you posted in the question. – user692942 Feb 23 '17 at 17:32

1 Answers1

1

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}"
Regis Desrosiers
  • 537
  • 3
  • 13