R.Wieser
2020-12-28 13:50:17 UTC
Hello all,
I run scripts in a console window, and sometimes need to have them wait for
a keypress before continuing. For that I found the below code :
- - - - - - - - - - - - - - - - - - - -
Wscript.StdOut.Write vbNewLine & "Press ENTER to continue. "
Do While Not WScript.StdIn.AtEndOfLine
Input = WScript.StdIn.Read(1)
Loop
- - - - - - - - - - - - - - - - - - - -
This works well the first time, but for some reason the following times it
responds as if the Enter key was already pressed.
I've been looking forr a way to flush the StdIn buffer, but could not find
anything.
At some point I changed the code to the below :
- - - - - - - - - - - - - - - - - - - -
Do While WScript.StdIn.Read(1) <> vbCR
loop
- - - - - - - - - - - - - - - - - - - -
While that works well, the problem with that is that it likely won't work
too well with any kind of redirected input (where the (last) line does not
necessarily end with a CR(LF) ...
So, my simple question (yeah, right :-) ) is : does anyone know about a way
to either only wait for just the keyboard (ignoring redirection) or flush
the input buffer before waiting for the Enter key to be pressed.
And now I think of it, I have no idea why the first bit of code waits to
begin with. Somehow not having pressed any keys yet does not register as an
AtEndOfLine state ?
Regards,
Rudy Wieser
I run scripts in a console window, and sometimes need to have them wait for
a keypress before continuing. For that I found the below code :
- - - - - - - - - - - - - - - - - - - -
Wscript.StdOut.Write vbNewLine & "Press ENTER to continue. "
Do While Not WScript.StdIn.AtEndOfLine
Input = WScript.StdIn.Read(1)
Loop
- - - - - - - - - - - - - - - - - - - -
This works well the first time, but for some reason the following times it
responds as if the Enter key was already pressed.
I've been looking forr a way to flush the StdIn buffer, but could not find
anything.
At some point I changed the code to the below :
- - - - - - - - - - - - - - - - - - - -
Do While WScript.StdIn.Read(1) <> vbCR
loop
- - - - - - - - - - - - - - - - - - - -
While that works well, the problem with that is that it likely won't work
too well with any kind of redirected input (where the (last) line does not
necessarily end with a CR(LF) ...
So, my simple question (yeah, right :-) ) is : does anyone know about a way
to either only wait for just the keyboard (ignoring redirection) or flush
the input buffer before waiting for the Enter key to be pressed.
And now I think of it, I have no idea why the first bit of code waits to
begin with. Somehow not having pressed any keys yet does not register as an
AtEndOfLine state ?
Regards,
Rudy Wieser