Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.scripting.vbscript > #12312

Waiting for keypress in a console - I've got problems.

From "R.Wieser" <address@not.available>
Newsgroups microsoft.public.scripting.vbscript
Subject Waiting for keypress in a console - I've got problems.
Date 2020-12-28 14:50 +0100
Organization Aioe.org NNTP Server
Message-ID <rscnqt$346$1@gioia.aioe.org> (permalink)

Show all headers | View raw


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


Back to microsoft.public.scripting.vbscript | Previous | NextNext in thread | Find similar


Thread

Waiting for keypress in a console - I've got problems. "R.Wieser" <address@not.available> - 2020-12-28 14:50 +0100
  Re: Waiting for keypress in a console - I've got problems. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-12-28 17:16 +0100
    Re: Waiting for keypress in a console - I've got problems. "R.Wieser" <address@not.available> - 2020-12-28 18:18 +0100
      Re: Waiting for keypress in a console - I've got problems. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-12-29 00:21 +0100
        Re: Waiting for keypress in a console - I've got problems. "R.Wieser" <address@not.available> - 2020-12-29 08:28 +0100
          Re: Waiting for keypress in a console - I've got problems. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-12-29 13:26 +0100
            Re: Waiting for keypress in a console - I've got problems. "R.Wieser" <address@not.available> - 2020-12-29 14:46 +0100
  Re: Waiting for keypress in a console - I've got problems. JJ <jj4public@gmail.com> - 2020-12-29 11:44 +0700
    Re: Waiting for keypress in a console - I've got problems. "R.Wieser" <address@not.available> - 2020-12-29 08:26 +0100

csiph-web