VBScript - How to pause a script until a specific key is pressed?
Asked Answered
B

1

9

How to pause a VBScript program until the user presses a specific key?
I need to pause the execution of the script and make it wait until a key such as 'left_arrow' is pressed.

Burroughs answered 26/6, 2015 at 9:43 Comment(1)
MsgBox Function, see VBScript Language ReferenceMcbee
S
21

You don't have a lot of choices. If you have a console script, and I'm assuming you do, you can read input from the user but it only registers when you press [ENTER]. So you could pause until the enter key is pressed. For example:

WScript.Echo "Press [ENTER] to continue..."

' Read dummy input. This call will not return until [ENTER] is pressed.
WScript.StdIn.ReadLine

WScript.Echo "Done."

There's also the old pause command from DOS days. However, shelling a new console window to run pause would cause a second window to appear. You'd need to press a key in that window to return to your script. Probably not what you want.

But apart from third-parties, VBScript has no methods to read keypresses at run-time.

Samos answered 26/6, 2015 at 11:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.