Skip navigation

JSI Tip 7775. Getkey and Getvar freeware.

Bill Stewart's site contains:

Download here: getkv11.zip (86,723 bytes; 03 Apr 2006)

Getkey and getvar are two handy programs that provide a batch file script author to get keystroke or line input from a user. MS-DOS and Win32 console versions of both utilities are included.

Getkey is similar to the choice utility that come free with Windows 9x/Me or in the Windows NT Resource Kit, except that it's less noisy and has more features.

Getvar allows a batch file to read a line of input into an environment variable. Some will note that the cmd.exe command set /p (in Windows 2000 and later) can do this, but it is not as flexible as getvar.

The below list summarizes why getkey might be preferable to choice:

  • Both DOS and Win32 console versions are included.
  • It doesn't beep if you type a key that's not in the list. (Personally, I find that behavior really annoying.)
  • It has a mode that waits for an Enter keystroke after typing the key (I have found many users that can't keep from pressing Enter after they type a key).
  • It has a "quiet" mode that does not display the selected keystroke or move to the next line on the screen.

The below list summarizes why getvar might be preferable to set /p:

  • Both DOS and Win32 console versions are included.
  • Supports masked (password-style) input.
  • Supports numeric-only input.
  • Allows you to limit the length of the input string.
  • Supports uppercase-only input.
  • Has a timeout feature; useful if a script needs to run unattended.

Many people have found the DOS versions to be very useful on DOS boot disks or CDs.



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish