The
IBM PC keyboard does not generate ASCII codes directly. The keys
are each identified with a number, starting with the keys that are
located in the upper left of the original PC keyboard. 1 for the
"ESC'' key, 2 for the "1'', and so on. Each key is
assigned a number, including modifier keys like the left SHIFT and
right SHIFT keys, numbers 42 and 54. When a key is pressed, ELKS
receives the key number as a scan code. A scan code is also
generated when a key is released, but the code generated upon
release has the most significant bit set (equivalent to adding 128
to the key number). Thus a key press and a key release can be
distinguished. By keeping track of which modifier keys have been
pressed and not yet released, a large number of combinations are
possible.
Because the keyboard delivers scan codes
rather than the character codes used by application software, the
keyboard driver must convert between the scan codes and the ASCII
codes by using a table. To support international keyboards the
driver must map the different keyboards with different tables.
For
the ELKS operating system, these tables are in the
elks/arch/i86/drivers/char/KeyMaps directory. The keyboard driver,
xt_key.c, includes the KeyMaps/Keymaps.h
file which is automatically created. This includes alle the keymap
files in the KeyMaps directory for the different keyboard layouts
needed for different languages. The xt_key.c keyboard driver has
been extended to support AT keyboards as well.
The
keycode tables in the keymap header files are arranged with
ascending scancode values. These are specified in hex codes after
each line. There are four tables in each header file, one for
normal keys, one for shifted keys, one for keys being pressed in
combination with the ALT+CTRL keys and one in combination with the
caps lock key. The ASCII value can be entered in the table as a
character or as an octal code. For the extended or grey keys,
these have to have an octal value of 200 or higher. This are no
ASCII codes, the driver will translate these keys as needed to
handle the extended keys.
Here is a list of the octal
codes used in the keymaps tables:
Scan
- ASCII - Octal
code - code – code
2A –
l.SHIFT - 0200
2B
- '\'
2C - 'z'
...
35 - '/'
36 – r.SHIFT
- 0201
37
- '*'
38 - ALT
-
0203
39 - ' '
3A - CapsLock
-0204
3B
- F1
-
0241
3C
- F2
-
0242
3D
- F3
-
0243
3E
- F4
-
0244
3F
- F5
-
0245
40
- F6
-
0246
41 - F7
-
0247
42 - F8
-
0250
43 - F9
-
0251
44 - F10
-
0252
45 - NumLock
- 0205
46 - ScrLock
- 0210
47 - Home
-
0267
48
- CurUp
-
0270
49
- PgUp
-
0271
4A
- '-'
-
0211
4B
- Left
-
0264
4C
- MID
-
0265
4D
- Right
-
0266
4E
- '+'
-
0214
4F
- End
-
0261
50
- Down
-
0262
51
- PgDown
-
0263
52
- Insert
-
0272
53
- Delete
-
0177
54
- Enter
Shifted keys
40 - F6
-
0226
41 - F7
-
0227
42 - F8
-
0230
43 - F9
-
0231
44 - F10
-
0232
45 - NumLock
- 0204
46 - ScrLock
-
0213
Each of the
keyboard tables defines up to 89 scancode entries. Most keyboards
do not feature more keys.
If “ANSI console terminal
emulation“ has been selected in “make menuconfig“, the
keyboard driver will translate the HOME, END, INSERT, PageUP and
PageDown keys to ANSI terminal sequences.
Thus the HOME key
is defined in the keymap table with the octal code of 267 which is
0xb7 in hex. The driver will then send “ESC[H“ to the
application for the code 0xb7.
6th of July 2020 Georg
Potthast
|