166
The VIC 20
User
Guide
2.
If
no key has been pressed, the numeric variable
is
assigned a value
of
O.
The program has no way
of
determining whether no key was
pressed
or
a "0" was typed.
With a string variable, you can
GET
almost any key, including the
cursor control keys and
RETURN. (The STOP and RESTORE keys can't be
read, and the various shifts and the
CTRL key operate as usual.)
If
no key
is
pressed, GET assigns
an
empty string to the variable and your program
detects this.
If
you want to wait until something
is
typed in, use a line like the
following:
113
GET
AI
:
IF
A$
..
1111
THEN
113
Notice that there
is
no space between the quotes, resulting in
an
empty
string.
If
the variable you GET
is
equal to this empty string, then no key was
pressed.
Echoing
Keystrokes
As
mentioned earlier, characters entered with GET do not appear
on
the screen. Sometimes, however, you need to
see
what you type. This can be
accomplished
by
adding a
PRINT
statement to the program.
113
GET
AI
:
IF
AS
=
1111
THEN
113
213
PRINT
AS;
The simple program above will echo to the screen exactly what
is
typed
at
the keyboard. Pressing the STOP key will stop the program.
The
Keyboard
as
Joystick
This section
is
presented in a "case study"form. Rather than start with
the program listing,
we
will first show you some
of
the steps taken in
designing it. Following these steps will help you to understand
both
the
program listings and the programming process itself.
Our make-believe joystick will act
just
like the ones made by Commo-
dore. You can make it point in various directions (left, right, up, down, and
diagonally) by pressing different keys.
It
will also have a Fire button,
although it can't be pushed while a direction key
is
being held down.