home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / batch / keyprs1.arj / KEYPRESS.DOC < prev   
Encoding:
Text File  |  1992-01-29  |  2.4 KB  |  49 lines

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