40 IBM Function Keys
I have an IBM PC and have written many BASIC programs. To increase speed and minimize typing errors, I usually reassign all 10 function keys. But sometimes 10 keys is not enough. I have seen programs like Symphony that allow as many as 20 function keys. Is there any way I can use the ALT key to assign additional function keys?
As you've learned, IBM BASIC supports only 10 soft key assignments. Function keys 1–10 are called soft keys and can be reassigned with a statement like KEY 1, "CLS:FILES" + CHR$(13) in direct mode or in a program. The KEY() and ON KEY() GOSUB statements make it possible to trap as many as six additional keys (see "Readers' Feedback," September 1985), but that method can't provide a full extra set of function keys. However, you can get four sets of function keys—40 keys in all—by checking for extended scan codes. When you press a single key, it generates a single scan code (a number in the range 0–255). Extended (two-number) scan codes are generated when you press ALT, CTRL, or SHIFT with another key. This program illustrates one keyboard scanning method that works on both the PC and PCjr; it detects Fl, ALT-F1, CTRL-F1, and SHIFT-Fl, displaying the scan codes for whatever keys you press.
0 FOR J = l TO 10 : KEY J, " " : NEXT J 1 DEF FNF1 (X) = (X$ = CHR # (0) + CHR $ (59)) : DEF FNALTF1 (X) = (X $ = C HR $ (0) + CHR $ (104)) 2 DEF FNCTRF1 (X) = (X $ = CHR $ (0) + CHR $(94)) : DEF FNSHFF1 (X) = (X $ = CHR $ (0) + CHR $ (84)) 3 X $ = INKEY$ : ON (FNF1 (A) *-l) + (FNALTF1 (A) * - 2) GOSUB 6, 7 4 ON (FNCTRF1 (A) * - l) + (FNSHFF1 (A) * - 2) GOSUB 8, 9 5 FOR J = l TO LEN (X$) : PRINT ASC (MID$ (XS, J, 1)) : NEXT J : GOTO3 6 PRINT "Pressed Fl" : RETURN 7 PRINT "Pressed Alt-Fl " : RETURN 8 PRINT "Pressed Ctrl-F1 " : RETURN 9 PRINT "Pressed Shift-FI " : RETURN
Lines 1–2 define user functions for the key combinations we want to detect. The INKEY$ statement in line 3 returns the scan codes in X$; and the ON-GOSUB statements in lines 3–4 transfer control to appropriate subroutines. Detecting additional key combinations is simply a matter of adding more user functions and appropriate subroutines. Page G-7 of the IBM BASIC Manual and pages G-6-G-7 of the PCjr BASIC Manual list all the extended scan codes; note that certain key combinations don't generate extended codes.