User`s manual
5-7
INKEY$
Returns a one-character string determined by an instantaneous keyboard
strobe. The last key pressed before the strobe is returned. If no key is pressed
during the strobe, a null string (length zero) is returned. This is a very
powerful function because it lets you input values while the Computer is
executing - without using the
[ENTER]
key. The popular video games which
let you fire at will, guide a moving dot through a maze, play tennis, etc., may
all be simulated using the INKEY$ function (plus a lot of other program logic,
of course).
Characters typed to an INKEY$ are not automatically displayed on the
screen.
Because of the short duration of the strobe cycle (on the order of
microseconds) INKEY$ is invariably placed inside some sort of loop, so that
the Keyboard is scanned repeatedly.
Example Program:
10
CLS
100
PRINT @540,INKEY$: GOTO 100
RUN the program; notice that the screen remains blank until the first time
you hit a key. The last key hit remains on the screen until you hit another
one. (The last key hit is always saved. The INKEY$ function uses it until it is
replaced by a new value.)
INKEY$ may be used in sequences of loops to allow the user to build up a
longer string.
Example:
90 PRINT "ENTER THREE CHARACTERS"
100 A$=INKEY$: IF A$=""THEN 100 ELSE PRINT A$;
110 B$=INKEY$: IF B$=""THEN 110 ELSE PRINT B$;
120 C$=INKEY$: IF C$=""THEN 120 ELSE PRINT C$;
130 D$=A$+B$+C$
A three-character string D$ can now be entered via the keyboard without
using the
[ENTER]
key.
NOTE:
The statement
IF A$=""
compares A$ to the null string.










