Up to now, we've been using INPUT to get things from
the keyboard. The problem with INPUT is that our program
stops until the user presses the enter key. Wouldn't it
be nice to keep the program running and still be able to
get input from the keyboard? INKEY$ will let
you do this. Using INKEY$ is very important if you want
to make "real-time" game programs.
Let's fix the clock program to let the user press any
key to stop the program. This way the user doesn't have
to know about the Break key.
LOCATE 3, 1
PRINT "Press any key to exit"
LOCATE 1, 1
LOOP WHILE INKEY$ = ""
Not bad at all. Now we don't need to teach the user
about the Break key. We can do the same thing in any of
our other programs that need the Break key. If the user
does not press a key, INKEY$ returns nothing or "".
This next program will sit in a loop getting keys from
the keyboard with INKEY$ and printing them to the screen:
Key$ = INKEY$
IF Key$ <> "" THEN
That little program can be used to find the various
secret codes used by INKEY$ to let you know the arrow
keys have been pressed. This is very useful in game programming
where the arrow keys might control a player in a game.
If you press an arrow key, you'll see that a space and
a letter are generated.