The INKEY$ function, though more obscure than commands like SAVE and RUN, is simple to use and adds a nice touch to your programs.
INKEY$ plus a PAUSE command causes your ZX81 to wait, watching the keyboard until the user presses a key. That key is then accepted as input and the program proceeds.
Substitute INKEY$ for an INPUT line. Say your program asks the user to choose between 3 options. Line 100 might read:
100 PRINT "CHOOSE THE MONTH YOU WISH: 1. JAN 2. FEB 3. MAR"
You could follow this with
110 INPUT X
120 IF X=1 THEN GOTO...
130 IF X=2 THEN GOTO... etc.
The user must press his desired number, then ENTER or NEWLINE.
When the input is a single digit, you can use the INKEY$ function instead:
110 IF INKEY$="1" THEN GOTO...
120 IF INKEY$="2" THEN GOTO...etc.
Note that you must include ” ” marks in the INKEY$ statement.
With this kind of input, the user just presses his choice and the ZX81 carries on. Reducing the time and steps for input makes the program simpler for the user.
You must also include a PAUSE statement BEFORE the INKEY$ lines. The PAUSE makes the computer wait. Add a line like:
105 PAUSE 500
The ZX81 waits about 10 seconds for input. Vary this time by changing the number after the PAUSE. Experiment to find a good time for your program. If you have an old 8K ROM, add a POKE 16437,255 line after the PAUSE. (To check your ROM, see p.19.)
Keep this in mind: INKEY$ doesn’t wait, so the user cannot correct a mistake using the RUBOUT key. Use INKEY$ for input when you want a fast-moving program and your user has little chance of error.