DECLARE SUB Instructions ()
DECLARE FUNCTION Describe3$ (J AS INTEGER)
DECLARE FUNCTION Describe2$ (K AS STRING)
DECLARE FUNCTION Describe1$ (K AS STRING)
DIM K AS STRING, halt AS INTEGER, row AS INTEGER, col AS INTEGER, J AS INTEGER
DIM start AS INTEGER, show AS INTEGER
CLS : COLOR 15: PRINT TAB(25); "EXTENDED KEY & SCAN CODES"; TAB(68);
COLOR 8: PRINT "by Solitaire"
PRINT : PRINT "Press Esc twice in succession to quit. Press Backspace twice for instructions."
PRINT : COLOR 15: PRINT "Scancode"; TAB(11); "Hexcode"; TAB(20); "Release"; TAB(30); "Character"; TAB(42); "HEX"; TAB(50); "ASCII"; TAB(60); "Description"
COLOR 8: PRINT STRING$(80, "-"): COLOR 7 'underline title row
CALL Instructions
VIEW PRINT 7 TO 25: CLS 2
halt = 0
show = 0
start = 0
DO
row = CSRLIN
IF row = 25 THEN row = 24
DO
K$ = INKEY$
J = INP(&H60) 'same as INP(96)
IF J = 42 AND WAITFORIT = 1 THEN
ELSE
IF WAITFORIT = 1 THEN IF K$ <> "" THEN WAITFORIT = 0: PRINTED = 0 ELSE WAITFORIT = 0
END IF
IF J >= 128 AND J <> 224 AND J <> 250 THEN PRINTED = 0
D$ = Describe3$(J) 'control keys with no ASCII values
IF D$ <> "" AND J > 0 THEN
IF PRINTED = 0 THEN
IF J = 224 OR J = 250 THEN WAITFORIT = 1
IF WAITFORIT = 0 THEN PRINT J; TAB(11); HEX$(J); TAB(19); J + 128; TAB(60); D$; SPACE$(80 - POS(0)): PRINTED = 1
END IF
END IF
LOOP UNTIL K$ <> ""
PRINTED = 0
IF start = 0 THEN CLS : J = 0 'clear instructions
start = 1
IF halt = 1 AND J <> 1 THEN halt = 0 'Escape pressed 2x in a row
IF halt = 1 AND J = 1 THEN EXIT DO 'same as K$ = CHR$(27)
IF J = 14 THEN show = show + 1 ELSE show = 0
IF show = 2 AND J = 14 THEN 'Backspace pressed 2x in a row
CLS
CALL Instructions
start = 0
show = 0
J = 0
END IF
IF J > 0 THEN
PRINT J; TAB(11); HEX$(J); TAB(19); J + 128; TAB(30); 'keys that affect cursor location
IF ASC(K$) >= 10 AND ASC(K$) <= 13 OR ASC(K$) = 30 OR ASC(K$) = 31 THEN
row = CSRLIN
IF row = 25 AND ASC(K$) <> 11 THEN row = 24
PRINT K$; TAB(42);
IF row <> CSRLIN AND ASC(K$) <> 12 THEN LOCATE row, 42
PRINT HEX$(ASC(K$)); TAB(50); ASC(K$); TAB(60); Describe1$(K$); SPACE$(80 - POS(0))
IF ASC(K$) = 12 THEN 'clears the screen
LOCATE CSRLIN - 1, 1
PRINT J; TAB(11); HEX$(J); TAB(19); J + 128
ELSEIF ASC(K$) = 11 THEN 'vertical tab deletes part of top line
LOCATE 7, 1
PRINT SPACE$(80)
LOCATE row, 1
END IF
ELSEIF LEN(K$) = 1 THEN 'all regular keys
PRINT K$; TAB(42); HEX$(ASC(K$)); TAB(50); ASC(K$); TAB(60); Describe1$(K$); SPACE$(80 - POS(0))
ELSE 'special and combo keys
row = CSRLIN
PRINT "0 +"; K$; TAB(42);
col = POS(0)
IF row <> CSRLIN OR col <> POS(0) THEN LOCATE row, col
PRINT HEX$(CVI(K$)); TAB(50); ASC(RIGHT$(K$, 1)); TAB(60); Describe2$(K$); SPACE$(80 - POS(0))
END IF
IF K$ = CHR$(27) THEN halt = halt + 1
END IF
LOOP UNTIL halt = 2
PRINT
VIEW PRINT
SYSTEM
FUNCTION Describe1$ (K AS STRING)
DIM D AS STRING
SELECT CASE ASC(K$)
CASE 0, 255: D$ = "Null"
CASE 1 TO 6, 14 TO 16, 21 TO 26: D$ = "Transmission"
CASE 7: D$ = "Beep"
CASE 8: D$ = "Backspace"
CASE 9: D$ = "Tab"
CASE 10, 14, 15: D$ = "Printer control"
CASE 11: D$ = "Vertical tab to top"
CASE 12: D$ = "Clears the screen"
CASE 13: D$ = "Enter"
CASE 17 TO 20: D$ = "Device control"
CASE 27: D$ = "Esc"
CASE 28, 29: D$ = "Separator"
CASE 30: D$ = "Vertical tab up"
CASE 31: D$ = "Vertical tab down"
CASE 32: D$ = "Spacebar"
CASE 33 TO 47, 58 TO 64, 91 TO 96, 123 TO 127: D$ = "Symbol"
CASE 48 TO 57: D$ = "Numeric digit"
CASE 65 TO 90: D$ = "Uppercase letter"
CASE 97 TO 122: D$ = "Lowercase letter"
CASE 128 TO 154, 160 TO 165: D$ = "Extended character"
CASE 155 TO 159: D$ = "Extended currency"
CASE 166 TO 168, 171 TO 175: D$ = "Extended symbol"
CASE 169, 170, 179 TO 218: D$ = "Extended box"
CASE 176 TO 178, 219 TO 223: D$ = "Extended solid"
CASE 224 TO 248, 251 TO 253: D$ = "Extended math"
CASE 249, 250, 254: D$ = "Extended bullet"
CASE ELSE: D$ = "Undefined"
END SELECT
Describe1$ = D$
END FUNCTION
FUNCTION Describe2$ (K AS STRING)
DIM D AS STRING, x AS INTEGER, ch AS STRING
SELECT CASE ASC(RIGHT$(K$, 1))
CASE 3: D$ = "Null"
CASE 15: D$ = "Shift-Tab"
CASE 16 TO 25: ch$ = "QWERTYUIOP"
FOR x = 16 TO 25
IF x = ASC(RIGHT$(K$, 1)) THEN
D$ = "Alt-" + MID$(ch$, x - 15, 1)
END IF
NEXT x
CASE 30 TO 38: ch$ = "ASDFGHJKL"
FOR x = 30 TO 38
IF x = ASC(RIGHT$(K$, 1)) THEN
D$ = "Alt-" + MID$(ch$, x - 29, 1)
END IF
NEXT x
CASE 44 TO 50: ch$ = "ZXCVBNM"
FOR x = 44 TO 50
IF x = ASC(RIGHT$(K$, 1)) THEN
D$ = "Alt-" + MID$(ch$, x - 43, 1)
END IF
NEXT x
CASE 59 TO 68
FOR x = 59 TO 68 'F1-F10
IF x = ASC(RIGHT$(K$, 1)) THEN
D$ = "F" + LTRIM$(STR$(x - 58))
END IF
NEXT x
CASE 71: D$ = "Home"
CASE 72: D$ = "Up arrow"
CASE 73: D$ = "Page Up"
CASE 75: D$ = "Left arrow"
CASE 77: D$ = "Right arrow"
CASE 79: D$ = "End"
CASE 80: D$ = "Down arrow"
CASE 81: D$ = "Page Down"
CASE 82: D$ = "Insert"
CASE 83: D$ = "Delete"
CASE 84 TO 93 'Shift F1-F10
FOR x = 84 TO 93
IF x = ASC(RIGHT$(K$, 1)) THEN
D$ = "Shift-F" + LTRIM$(STR$(x - 83))
END IF
NEXT x
CASE 94 TO 103 'Ctrl F1-F10
FOR x = 93 TO 103
IF x = ASC(RIGHT$(K$, 1)) THEN
D$ = "Ctrl-F" + LTRIM$(STR$(x - 92))
END IF
NEXT x
CASE 104 TO 113 'Alt F1-F10
FOR x = 104 TO 113
IF x = ASC(RIGHT$(K$, 1)) THEN
D$ = "Alt-F" + LTRIM$(STR$(x - 103))
END IF
NEXT x
CASE 114: D$ = "Ctrl-PrtSc"
CASE 115: D$ = "Cursor Left"
CASE 116: D$ = "Cursor Right"
CASE 117: D$ = "Ctrl-End"
CASE 118: D$ = "Ctrl-PgDn"
CASE 119: D$ = "Ctrl-Home"
CASE 120 TO 128
FOR x = 120 TO 128
IF x = ASC(RIGHT$(K$, 1)) THEN
D$ = "Alt-" + LTRIM$(STR$(x - 119))
END IF
NEXT x
CASE 129: D$ = "Alt-0"
CASE 130: D$ = "Alt--"
CASE 131: D$ = "Alt-="
CASE 132: D$ = "Ctrl-PgUp"
CASE 133: D$ = "F11"
CASE 134: D$ = "F12"
CASE ELSE: D$ = "Undefined"
END SELECT
Describe2$ = D$
END FUNCTION
FUNCTION Describe3$ (J AS INTEGER)
SELECT CASE J
CASE 29: D$ = "Ctrl"
CASE 42: D$ = "Left Shift"
CASE 54: D$ = "Right Shift"
CASE 55: D$ = "PrtScr"
CASE 56: D$ = "Alt"
CASE 58: D$ = "Caps Lock"
CASE 69: D$ = "Num Lock"
CASE 70: D$ = "Scroll Lock"
CASE 224, 250: D$ = "Null"
END SELECT
Describe3$ = D$
END FUNCTION
SUB Instructions
PRINT "Scancode (keydown) is in Decimal. Release code (keyup) is scancode + 128."
PRINT "For extended (non-keyboard) characters, hold down the Alt key and type the ASCII"
PRINT "value (up to 255) on the numeric keypad. Also try other Ctrl or Alt key combos."
PRINT
PRINT "Each of the keyboard keys, whether shifted or not, uses the same scancode."
PRINT "ASCII values differ when shifted. Keys that are shifted with either Shift, Alt,"
PRINT "or Ctrl will display both the shift key's code and the other key's code."
PRINT
PRINT "Check status of Caps Lock and Num Lock keys as they affect other keypresses."
PRINT "Pressing an arrow key with Num Lock ON results in dual-scancodes that may"
PRINT "overwrite and cause bottom line to scroll up. Press a different key to continue."
PRINT
PRINT "When using Alt or Ctrl with another key, keep holding Alt or Ctrl down while"
PRINT "pressing and releasing the other key before releasing Alt or Ctrl."
PRINT "Some control keys do not have ASCII equivalent values. If more than one of"
PRINT "those keys are pressed in succession, they will overwrite on the same line."
PRINT : COLOR 8
PRINT "Press any key to clear. Then start pressing keys to display the codes.";
COLOR 7
A$ = INKEY$: SLEEP
END SUB
--------------------------------
Newest changes: Scan code 224 is problematic because the delete key, page keys, etc. share this code and since INP() is read before INKEY$, you cannot just use an IF K$ <> "" to get around that problem. By adding another CASE @@$ "Null" to the describe function and by adding some print/don't print IF/THEN statements and variables, maybe I discovered a way aound all of these problems. Not completely tested but on my keyboard it allowed for keys like Delete, Page keys, and right Ctrl and Alt keys, too. All combo keys wait for second key input, like Alt + S, etc. I still do'nt get why code 55 is assigned to PrtScr when it is the numeric asterisk key on my board but maybe that was something from the past.
---------------------------------
About an older edition edited out and replaced with the above.
Edited out the SLEEP version and changed to a printed variable that only prints an INP key like ctrl once. This allows for other keys to be pressed while ctrl, alt, etc. are held down. In other words, it prevents the fast print scrolling that would occur if the user pressed ctrl and took a second to select the next key. The only thing I doubt is my scan code number, IF J >= 128. I selected 225 as the number that would stop the right ctrl key from rapid scrolling but later discovered that blocks keys like Num Lock from appearing.

So far, I cannot figure out a way to stop rapid scrolling on this version if the right ctrl key or the right alt key is held down. The left crtl and alt keys only write once and wait for a second key press.
--------------------------------
Pete