Printer Version | Table of Contents | Project Home Page |
SPECIFYING THE KEYMASK
NOTE THAT THE VALUES SPECIFIED ON THE /K PARM ARE CASE-SENSITIVE.If a keymask of "/kXx" was specified, then if the user pressed the (shifted or unshifted) "X" key, then uppercase "X" would be returned. If he pressed the ESCAPE key, then lowercase "x" would be returned.
SPECIFYING HOW MANY SECONDS TO WAIT FOR A KEYPRESS
Starting with version 10, GETK takes a /W "seconds to wait" parameter that tells it how many seconds to wait before returning the first key in the /K "keymask" parameter. Valid values are in the range of 1..36000 (10 hours). Default value of /W is 36000 (10 hours).GETK RESULTS ALSO IN ERRORLEVEL
When the GETK function returns a key, it sets the DOS errorlevel to a value corresponding to the position of that key in the keymask. For example, with keymask of "/kABx", if the user presses:"A": value returned will be "A", errorlevel will be 1 "B": value returned will be "B", errorlevel will be 2 ESCAPE: value returned will be "x", errorlevel will be 3If the user presses CONTROL+BREAK, Fdate will abort and return errorlevel 255.
.DISCUSSION..:@echo off cls echo Demonstration of Fdate's GETK (get keypress) function echo Press CONTROL+BREAK to end :top echo. Fdate /fGetK /P"You pressed: " /Q"Press a key: " /K"12ABxe " if errorlevel 1 if not errorlevel 2 echo errorlevel : 1 if errorlevel 2 if not errorlevel 3 echo errorlevel : 2 if errorlevel 3 if not errorlevel 4 echo errorlevel : 3 if errorlevel 4 if not errorlevel 5 echo errorlevel : 4 if errorlevel 5 if not errorlevel 6 echo errorlevel : 5 if errorlevel 6 if not errorlevel 7 echo errorlevel : 6 if errorlevel 7 if not errorlevel 8 echo errorlevel : 7 if errorlevel 255 echo ERRORLEVEL 255 if errorlevel 255 goto endit goto top :endit
Modifying the Keymask
It is often necessary to make program modifications during the life of a batch file. If you are using the GETK function and testing the errorlevel rather than the environment, then the insertion or deletion of characters into the existing keymask will change the errorlevels returned by the following characters in the keymask. This will force you to re-write the errorlevel tests, which may be a big job if the keymask is long.Displaying a User Prompt With GETK
The /Q (user prompt) parameter is especially handy when used in conjunction with the GETK function. If the /Q prompt-string parameter is specified (as in the example batch file, above), then the prompt string is displayed, but a NEWLINE is not written to the screen before waiting for the user's keypress.