Inputting Data With Thegetkey Command - Commodore 128D User Manual

Hide thumbs Also See for 128D:
Table of Contents

Advertisement

Inputting Data
with the GETKEY
Command
You have learned to use INPUT and GET commands to enter DATA
during a program. Another way for you to enter data while a program
is being RUN is with the GETKEY statement. The GETKEY statement
accepts only one key at a time. GETKEY is usually followed by a
string variable (A$, for example). Any key that is pressed is assigned
to that string variable. GETKEY is useful because it allows you to
enter data one character at a time wihtout having to press the
RETURN key after each character. The GETKEY statement may only
be used in a program.
Here is an example of using GETKEY in a program:
1000 PRINT "PLEASE CHOOSE A, B, G, D, E, OR F"
1010 GETKEY A$
1020 PRINT A$;" WAS THE KEY YOU PRESSED."
The computer waits until a single key is pressed; when the key is
pressed, the character is assigned to variable A$, and printed out in
line 1020. The following program features GETKEY in more complex
and useful fashions: for answering a multiple-choice question and
also asking if the question should be repeated. If the answer given is
incorrect, the user has the option to try again by pressing the "Y"
key (line 90). The key pressed for the multiple choice answer is
assigned to variable A$ while the "TRY AGAIN" answer is assigned
to B$, through the GETKEY statements in lines 60 and 90. IF/THEN
statements-are used for loops in the program to get the proper com
puter reaction to the different keyboard inputs.
10 PRINT "WHO WROTE THE RAVEN'?"
20 PRINT "A. EDGAR ELLEN POE"
30 PRINT "B. EDGAR ALLAN POE"
40 PRINT "C. IGOR ALLEN POE"
50 PRINT "D. ROB RAVEN"
60 GETKEY A$
70IFA$ = "B" THEN 150
80 PRINT "WRONG. TRY AGAIN? (Y OR N)"
90 GETKEY B$
100 IF B$ = "Y" THEN PRINT "A,B,C, OR D?":GOTO 60
110IFB$ = "N"THEN 140
120 PRINT 'TYPE EITHER Y OR N—TRY AGAIN"
130 GOTO 90
140 PRINT 'THE CORRECT ANSWER IS B."
145 GOTO 160
150 PRINT "CORRECT!"
160 END
LJ
U
i
(
\
!
USING C128 MODE—Some BASIC Commands and Keyboard Operations Unique to
80
C128Mode

Advertisement

Table of Contents
loading

Table of Contents