home *** CD-ROM | disk | FTP | other *** search
-
- KEYPRESS.COM - A Tool for Interactive Batch Files
-
- I found this program in the DEBUG script form in a DOS hint booklet.
- The resulting program was KEYPRESS.COM, a small but useful program to be
- used in making interactive batch files. The usage is:
- KEYPRESS prompt [validkeys]
- For example, in a batch file, you wanted to ask a yes or no question like
- "Enter Y or N:", then you would type in:
- KEYPRESS Enter Y or N: [yn]
- The program would only proceed if Y or N was pressed, regardless of caps.
- After that, KEYPRESS would set the system variable ERRORLEVEL according to
- the key pressed. Here is the ERRORLEVEL response chart:
- -----------------------
- A 1 J 10 S 19
- B 2 K 11 T 20
- C 3 L 12 U 21
- D 4 M 13 V 22
- E 5 N 14 W 23
- F 6 O 15 X 24
- G 7 P 16 Y 25
- H 8 Q 17 Z 26
- I 9 R 18 ESC 27
- -----------------------
- The usage of the ERRORLEVEL variable is very easy. Let's review our yes or
- no program.
- First you start with an @ECHO OFF. @ECHO OFF
- Then you add the KEYPRESS line. KEYPRESS Enter Y or N: [yn]
- Then you add the ERRORLEVEL lines. IF ERRORLEVEL=25 THEN GOTO Y
- IF ERRORLEVEL=14 THEN GOTO N
- Now you need the branches of the :Y
- program. ECHO You pressed Y.
- GOTO END
- :N
- ECHO You pressed N.
- The END subtitle goes back to DOS. :END
-
- That's about all there is to it. It can become that simple, or much more
- advanced. Notice that the program checked for ERRORLEVEL to equal 25 before
- it checked for ERRORLEVEL to equal 14. You must do your IF ERRORLEVEL
- statements in descending order, or DOS will not be able to branch off to the
- subtitles correctly. A sample program, KEY.BAT, has been included in this
- archive file. Please look at it if you have any problems with your own batch
- files. If you still have questions, or this documentation confuses you, then
- write me a note on the Programmer's Corner. My ID number is 2985.
-
- Thank you for using KEYPRESS.
-
-