Vintage Computing
10 REM KEYNUM.BAS ***
20 COLOR 63,22
30 CLS
40 LOCATE 10,0: PRINT “>>> Keycode Values <<<”
50 LOCATE 1,2: PRINT “Press Any Key, or <CTRL> Q
to Return…”
60 REM —- Get Keystroke —-
70 A=INKEY
80 IF A=0 THEN GOTO 70 REM <- No Key Pressed
90 REM —- Show Value and Glyph —-
100 LOCATE 18,18: PRINT “INKEY = “;
110 PRINT A,
120 LOCATE 16,20: PRINT “DISPLAY = “;
130 DISPLAY A
140 REM —- Again? —-
150 IF A<>593 AND A<>625 THEN GOTO 70 REM <-
CTRL Q?
160 CLS: END
(for Remark) to provide some internal documentation to
explain what’s going on. It is good programming practice
to provide “enough” documentation in your code. Also
note the REM at the end of Line 150 — some (but not all!)
Color BASIC commands allow a following REM on the
same program line. Color BASIC ignores everything on a
program line after the REM.
• Lines 20-50 set the screen color to white text on a
blue background, clear the screen, and print the app title
and user instructions. The LOCATE command positions
the cursor at a specified column and row, where column
is between 0 and 49 and row is between 0 and 36,
inclusive. Note the use of the colon in lines 40 and 50 to
place more than one Color BASIC command on the same
program line.
• Line 70 uses the INKEY command to get an integer
value from the keyboard buffer and store it in variable A.
• Line 80 checks the value in A. If it is 0, no key has
been pressed, and program flow jumps back to line 70 to
check again. If it is not 0, program flow continues at line 90.
After you’ve explored the keyboard for a bit, press
<CTRL-Q> to end the program. (In Color BASIC, you can
also press <Esc> at any time to interrupt program flow.)
Then, enter SAVE “ KEYNUM.BAS” at the prompt. That will
save your program to the SD card, so you can LOAD
“ KEYNUM.BAS” and RUN it when you wish. Remember
• Lines 100-130 print the assigned integer and
character glyph of the keystroke value in variable A. The
semicolon at the end of lines 100 and 120 keeps the
cursor positioned immediately after the printed text (no
line feed/carriage return). The comma at the end of line
110 appends a tab character to ensure previous entries
are completely erased. Note that PRINT A shows the
integer in variable A, while DISPLAY A shows the assigned
character glyph.