I cut this from the header of my source code. It explains the decoding somewhat.
The nice thing is the behaviors can be modified. You can even modifiy the code to modify the keyboards parameters, using the SEND routine. On SBC-3, I used the Scroll-Lock LED to signal when the keyboard was being scanned by software, that way the user would know why his keyboard was not responding.
Since the SBC-3 AVR had two functions (keyboard decoding and RS-232 port), I modified the code to allow
multitasking between the two, as well as monitoring the SPI port for host commands. That code can be found in the SBC-3 support file, found at the bottom of this page:
http://sbc.rictor.org/info3.htmlCheers!
Daryl
Code:
;/******************************************************************************/
;/ PC Keyboard decoder /
;/ /
;/ Designed and written by Daryl Rictor (c)2004 /
;/******************************************************************************/
;
; All standard keys and control keys are decoded to 7 bit (bit 7=0) standard ASCII.
; Control key note: It is being assumed that if you hold down the ctrl key,
; you are going to press an alpha key (A-Z) with it (except break key defined below.)
; If you press another key, its ascii code's lower 5 bits will be send as a control
; code. For example, Ctrl-1 sends $11, Ctrl-; sends $2B (Esc), Ctrl-F1 sends $01.
;
; The following non-standard keys are decoded with bit 7=1, bit 6=0 if not shifted,
; bit 6=1 if shifted, and bits 0-5 identify the key.
;
; Function key translation:
; ASCII / Shifted ASCII
; F1 - 81 / C1
; F2 - 82 / C2
; F3 - 83 / C3
; F4 - 84 / C4
; F5 - 85 / C5
; F6 - 86 / C6
; F7 - 87 / C7
; F8 - 88 / C8
; F9 - 89 / C9
; F10 - 8A / CA
; F11 - 8B / CB
; F12 - 8C / CC
;
; The Print screen and Pause/Break keys are decoded as:
; ASCII Shifted ASCII
; Ctrl-Break - 02 02 (Ctrl-B) (can be changed to AE/EE)(non-repeating key)
; Pause/Brk - 03 03 (Ctrl-C) (can change to 8E/CE)(non-repeating key)
; Scrl Lck - 8D CD
; PrtScn - 8F CF
;
; The Alt key is decoded as a hold down (like shift and ctrl) but does not
; alter the ASCII code of the key(s) that follow. Rather, it sends
; a Alt key-down code and a seperate Alt key-up code. The user program
; will have to keep track of it if they want to use Alt keys.
;
; Alt down - A0
; Alt up - E0
;
; Example byte stream of the Alt-F1 sequence: A0 81 E0. If Alt is held down longer
; than the repeat delay, a series of A0's will preceeed the 81 E0.
; i.e. A0 A0 A0 A0 A0 A0 81 E0.
;
; The special windows keys are decoded as follows:
; ASCII Shifted ASCII
; Left Menu Key - A1 E1
; Right Menu Key - A2 E2
; Right option Key - A3 E3
; Power Key - A4 E4
; Sleep Key - A5 E5
; Wake Key - A6 E6
;
;
; The following "cursor" keys ignore the shift key and return their special key code
; when numlock is off or their direct labeled key is pressed. When numlock is on, the digits
; are returned reguardless of shift key state.
; keypad(NumLck off) or Direct - ASCII Keypad(NumLck on) ASCII
; Keypad 0 Ins - 90 30
; Keypad . Del - 7F 2E
; Keypad 7 Home - 97 37
; Keypad 1 End - 91 31
; Keypad 9 PgUp - 99 39
; Keypad 3 PgDn - 93 33
; Keypad 8 UpArrow - 98 38
; Keypad 2 DnArrow - 92 32
; Keypad 4 LfArrow - 94 34
; Keypad 6 RtArrow - 96 36
; Keypad 5 (blank) - 95 35
;
_________________
Please visit my website ->
https://sbc.rictor.org/