Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBS - How to pause a script until a key is pressed?

How to pause the script until a key is pressed in VBScript? I need something that would pause the flow of the program and wait until 'left_arrow' key is pressed.

like image 210
TypicalHog Avatar asked Jun 26 '15 09:06

TypicalHog


People also ask

How do I stop a VBS script from running?

Start Task Manager, click on the Processes tab, right-click on wscript.exe and select End Process, and confirm in the dialog that follows. This will terminate the wscript.exe that is executing your script.

What is WScript echo in VBScript?

You can use WScript. Echo to see exactly what VBScript passes out; if the string you see in the result of WScript. Echo works in a command-prompt window, it will work as the first argument for the Run method.

What is WScript sleep?

A script can force itself to pause by calling the WScript Sleep method. The Sleep method accepts a single parameter that indicates how long, in milliseconds, to pause the script. (There are 1,000 milliseconds in a second and 60,000 milliseconds in a minute.)


1 Answers

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.

like image 67
Bond Avatar answered Sep 20 '22 11:09

Bond