[Next] [Up/Previous] [Previous Section] [Home] [Other]

Playing With Scan Codes

Here's a picture of a keyboard you're not likely to see on sale for your PC compatible computer anytime soon, more's the pity...

It has 106 keys. What is a full 105-key keyboard doing with an Fn key on it? After all, those keys are used on small keyboards, such as laptop keyboards without numeric pads, for compatibility with larger keyboards.

Well, this keyboard is compatible with a larger keyboard: a 122-key keyboard, as those familiar with the IBM 3270 PC computer would recognize from the legends on many of the keys. Other versions of the 122-key Host Connected Keyboard have different legends on some of the additional keys. It has other extras; the APL character set, brightly color-coded keys with retro seventies styling.

The color coding may look familiar from my page about keyboards.

I have to admit, though, that it may be that a keyboard such as I illustrate above may be impossible. For one thing, the keyboard used with the 3270 PC was connected by means of a very special interface: the keyboard was connected to a card and then through the card to the motherboard as an ordinary keyboard. Modern 122-key keyboards that connect directly to computers usually have slightly different layouts, based on the IBM 5250 display terminal, so the way in which keys corresponding to those on the 101-key keyboard are located on the 122-key keyboard is likely to be different from what I had assumed in the creation of this diagram.

Based on the information on the previous page, here are the scan codes I thought apropriate to assign to the keyboard illustrated above:


                                                                                |-------------------------------------------------------------------|
                                                                                | E0 52 | E0 53 | E0 47 | E0 4F | E0 49 | E0 51 |           |       |
                                                                                | E0 52*| E0 53*| E0 47*| E0 4F*| E0 49*| E0 51*|           | E1/46+|
|---------------------------------------------------------------------------------------------------------------------------------------------------|
|           |       |       |    5B |    5C |    5D |    63 |    64 |    65 |    66 |    67 |    68 |    69 |    6A |    6B |       |       |    37 |
|     37/54+|    56 |    29 |    3B |    3C |    3D |    3E |    3F |    40 |    41 |    42 |    43 |    44 |    57 |    58 | E0 48*|    45 |    46+|
|---------------------------------------------------------------------------------------------------------------------------------------------------|
|       |       |       |       |       |       |       |       |       |       |       |       |       |           |       |       |       | E0 39 |
|    01 |    02 |    03 |    04 |    05 |    06 |    07 |    08 |    09 |    0A |    0B |    0C |    0D |        0E | E0 4B*| E0 50*| E0 4D*| E0 35+|
|---------------------------------------------------------------------------------------------------------------------------------------------------|
|           |       |       |       |       |       |       |       |       |       |       |       |       |       |    6E |    6F |    75 | E0 0F |
|        0F |    10 |    11 |    12 |    13 |    14 |    15 |    16 |    17 |    18 |    19 |    1A |    1B |    2B |    47 |    48 |    49 |    37+|
|---------------------------------------------------------------------------------------------------------------------------------------------------|
|          1D |       |       |       |       |       |       |       |       |       |       |       |       E0 1D |    73 |    74 |    6D | E0 4C*|
|          3A |    1E |    1F |    20 |    21 |    22 |    23 |    24 |    25 |    26 |    27 |    28 |          1C |    4B |    4C |    4D |    4A |
|---------------------------------------------------------------------------------------------------------------------------------------------------|
|                 |       |       |       |       |       |       |       |       |       |       |                 |    70 |    71 |    72 |    1C |
|              2A |    2C |    2D |    2E |    2F |    30 |    31 |    32 |    33 |    34 |    35 |              36 |    4F |    50 |    51 |    4E |
|---------------------------------------------------------------------------------------------------------------------------------------------------|
|       |       |       |                                                           |       |       |       |       |        76 |       |           |
|    1D | E0 5B |    38 |                                                        39 | E0 38 | E0 5C | E0 5D | E0 1D |        52 |    53 |     E0 1C |
|---------------------------------------------------------------------------------------------------------------------------------------------------|

In addition to helping me decide what scan codes to use for the compact keyboard above, the appropriate scan codes for an ultimate keyboard of the kind shown below might be possible to decide upon:

Note that, in the numeric keypad, there are two adjacent keys which both generate the - character. As may be obvious, though, the intent is that the numeric keypad might be used for a calculator, and the white - key (scan code E0 4A, or perhaps more likely E0 0C with forced unshift, as that scan code could be distinguished even by software designed for the 101-key keyboard) would be the "change sign" key, while the blue - key (scan code 4A) would be the "subtract" key.

Actually, in practice, it might be necessary to get just a little bit more ultimate:

while using the ten keys to the left of the main keyboard for the left-over functions is sensible, as there are different Group 3 scan codes defined for the keys involved, it seems necessary to keep the keys in the traditional 101-key keyboard positions. As well, an Fn key is added, to allow choosing between different scan code sets for compatibility with different 122-key keyboards, for example.

Note that the three keys to the right of the letter P do not have the same positions as on the 102-key keyboard. As well, if I had been designing a keyboard from scratch, rather than one to provide compatibility with a number of keyboards for the IBM PC, I would have interchanged the backslash (\) and tilde (~) characters, so that the \ ` key would be at a remote position on the keyboard, while the | ~ key would be the one key with less common characters within the main 44-key area of the keyboard. (Of course, having an [ ] key in that position would have the advantage of providing the uppercase subset of ASCII, along with the lower-case letters, in that area, as was done on the TRS-80 Model 100 notebook computer, but as that loses the arrangement of { [ and } ] keys, I would not consider it.)

Thus, the first keyboard shown here was a 130-key keyboard; the 122-key keyboard with five calculator keys and three Windows keys added, and this keyboard is now a 139-key keyboard, with five keys from the 101-keyboard returned to the array, and three keys from the 84-key keyboard of the IBM Personal Computer AT added for total compatibility with really old computer games, and with an Fn key added.

One possible set of scan codes for the keys of this keyboard might run as follows:

In Scan Code Set 1:

                 ---------------   ---------------   ---------------   -----------
                | 5B| 5C| 5D| 63| | 64| 65| 66| 67| | 68| 69| 6A| 6B| | 37| 46| 54|
           ---  |---------------| |---------------| |---------------| |-----------|
          | 01| | 3B| 3C| 3D| 3E| | 3F| 40| 41| 42| | 43| 44| 57| 58| |+37|+46|+45| 
           ---   ---------------   ---------------   ---------------   -----------

 -------   ---------------------------------------------------------   -----------   -------------------
|-3B|-3C| | 29| 02| 03| 04| 05| 06| 07| 08| 09| 0A| 0B| 0C| 0D|   0E| |*52|*47|*49| |+0A|+0B|+33|-39|+35|
|-------| |---------------------------------------------------------| |-----------| |-------------------|
|-3D|-3E| |   0F| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 2B| 1A| 1B| |*53|*4F|*51| | 47| 48| 49|+0F|+37|
|-------| |---------------------------------------------------------|  -----------  |-------------------|
|-3F|-40| |    3A| 1E| 1F| 20| 21| 22| 23| 24| 25| 26| 27| 28|    1C|     |*48|     | 4B| 4C| 4D|+0C| 4A|
|-------| |---------------------------------------------------------|  -----------  |-------------------|
|-41|-42| | 56|  2A| 2C| 2D| 2E| 2F| 30| 31| 32| 33| 34| 35|      36| |*4B|*4C|*4D| | 4F| 50| 51|   | 4E|
|-------| |---------------------------------------------------------| |-----------| |-----------|-1C|---|
|-43|-44| |   1D|-5B|   38|                       39|-38|-5C|-5D|-1D| |***|*50| 45| |     52| 53|   |+0D|
 -------   ---------------------------------------------------------   -----------   -------------------

Thus, we have keypad =, (, ), tab, space, and comma using the E0 code combined with forced unshift in the same manner as keypad /; the key in the middle of the cursor cluster corresponds to the 5 key in the numeric keypad in the same way that the other cursor cluster keys correspond to their counterparts.

As to the appropriate codes for the keys to the left of the main alphabetic area, they are derived by adding E0 to the codes for F1 through F10, since the purpose they serve when used with a computer running as a PC is to provide an alternate set of function keys. Originally, it was only envisaged these keys would be used when the keyboard is functioning as a 122-key keyboard, and so it was more difficult to determine what scan codes should be used; not having found the appropriate documentation, I had settled for this series of scan codes: 70, 71, 72, 73, 74, 6D, 6E, 6F, E0 43, and E0 44 for the keys in the F1 through F10 positions respectively for the diagram above for scan code set 1.

In Scan Code Set 3:

                 ---------------   ---------------   ---------------   -----------
                | 08| 10| 1B| 20| | 2B| 30| 38| 40| | 48| 50| 57| 5F| | 97| 98| 99|
           ---  |---------------| |---------------| |---------------| |-----------|
          | 8E| | 07| 0F| 17| 1F| | 27| 2F| 37| 3F| | 47| 4F| 58| 5E| | 8F| 90| 91| 
           ---   ---------------   ---------------   ---------------   -----------

 -------   ---------------------------------------------------------   -----------   -------------------
| 05| 06| | 0E| 18| 1E| 26| 25| 2E| 36| 3D| 3E| 46| 45| 4E| 55|   66| | 67| 6E| 6F| | 76| 77| 7E| 84| 96|
|-------| |---------------------------------------------------------| |-----------| |-------------------|
| 04| 0C| |   0D| 15| 1D| 24| 2D| 2C| 35| 3C| 43| 44| 4D| 5B| 54| 53| | 64| 65| 6D| | 6C| 75| 7D| 7C| 95|
|-------| |---------------------------------------------------------|  -----------  |-------------------|
| 03| 0E| |    14| 1C| 1B| 23| 2B| 34| 33| 3B| 42| 43| 4C| 52|    5A|     | 63|     | 6B| 73| 74| 7B| 94|
|-------| |---------------------------------------------------------|  -----------  |-------------------|
| 83| 0A| | 13|  12| 1A| 22| 21| 2A| 32| 31| 3A| 41| 49| 4A|      59| | 61| 62| 6A| | 69| 72| 7A|   | 93|
|-------| |---------------------------------------------------------| |-----------| |-----------| 79|---|
| 01| 09| |   11| 8B|   19|                       29| 39| 8C| 8D| 58| |***| 60| 8D| |     70| 71|   | 92|
 -------   ---------------------------------------------------------   -----------   -------------------

The codes in Scan Code Set 3 are shown as being assigned to this keyboard so as to favor the use of the keyboard as a 122-key keyboard for communications purposes, while the ones for sets 1 (and 2) are assigned so as to favor use as a keyboard compatible with a 101-key PC keyboard. Of course, the way in which the codes from 8D to 99 run is completely arbitrary here, and there may be reasons to make other assignments.

This short table shows how I have assigned these codes:

                    assigned   not
Num Lock              8D        76
Esc                   8E        08
Print Screen/Sys Req  8F        57
Scroll Lock           90        5F
Pause/Break           91        62
= KP                  92
+ KP                  93        7C
- KP                  94        84
* KP                  95        7E
/ KP                  96        77
*/Print               97
Scroll Lock/Break     98
Sys Req               99

The fact that there are no distinct scan codes in Group 3 for the five keys taken out of the group of ten keys to the left of the main alphabetic keyboard almost suggests that it might be possible to leave those keys there; however, in that case, since there are Set 1 and Set 2 scan codes for those keys, incompatibilities with 122-key terminal software would arise; of course, such incompatibilities would still be present for the numeric keypad area for such software that relied on those sets of scan codes. This is what makes the Fn key necessary; the keyboard would have to have the ability of being switched to alternate scan code sets.

Of course, it is also envisaged that the keyboard could have, in addition to the keys shown, keys for the Internet and multimedia functions offered by many keyboards.

What scan codes, then, would be assigned to this keyboard:

In addition to INT 1, the INT 3, 4, and 5 keys would all be needed for the extra keys added to the main area of the keyboard. Since INT 2 is equivalent to a key in the regular keyboard in Scan Code Set 1, it could not be of assistance.

So the required scan codes, as they would appear to the programmer in Scan Code set 1 (from which the codes actually sent, in Scan Code set 2, could be easily derived) would be something like this:

                      ---------------   ---------------   ---------------
                     | 5B| 5C| 5D| 63| | 64| 65| 66| 67| | 68| 69| 6A| 6B|
 -------             |---------------| |---------------| |---------------|  ----------- 
|     72|            | 3B| 3C| 3D| 3E| | 3F| 40| 41| 42| | 43| 44| 57| 58| |+37|+46|+45| 
 -------              ---------------   ---------------   ---------------   -----------
                                         | 73| 7D| 7E|
 -------   --------------------------------------------------------------   -----------   -------------------
|-3B|-3C| |  01| 29| 02| 03| 04| 05| 06| 07| 08| 09| 0A| 0B| 0C| 0D|   0E| |*52|*47|*49| |+0A|+0B|+33|-39|+35|
|-------| |--------------------------------------------------------------| |-----------| |-------------------|
|-3D|-3E| |-2B|    0F| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 1A| 1B| 2B| |*53|*4F|*51| | 47| 48| 49|+0F|+37|
|-------| |--------------------------------------------------------------|  -----------  |-------------------|
|-3F|-40| | 3A| 56| 7B| 1E| 1F| 20| 21| 22| 23| 24| 25| 26| 27| 28|    1C|     |*48| 45| | 4B| 4C| 4D|+0C| 4A|
|-------| |---------------------------------------------------------------  -----------  |-------------------|
|-41|-42| |-5D| 70|   2A| 2C| 2D| 2E| 2F| 30| 31| 32| 33| 34| 35|   36|-70||*4B|*4C|*4D| | 4F| 50| 51|   | 4E|
|-------| -----------------------------------------------------------------------------  |-----------|-1C|---|
|-43|-44||-5B|  1D| 79| 77|  38|                       39|-38 |-77|-79|-1D |-5D|*50|     |     52| 53|   |+0D|
 -------  -------------------------------------------------------------------------       -------------------

Many of the scan codes used on the Japanese keyboard have to be pressed into service. Thus, the code for Hiragana is used for the third control key, that for Furigana (similar to Ruby for Chinese) is used for Super, that for Kanji is used for Hyper, and that for Katakana is used for the Symbol shift. The extra :, (, and ) keys get INT 3, INT 4, and INT 5.

Since E0 5E is used for power on, although 5E seems to be a conveniently available code, it is probably safer to avoid it. E0 56, a code for an alternate version of the international key, seems to be a suitable code for the extra printable character key required. However, even better, I think, is E0 2B. This would allow it to be given the distinctive code for the INT 2 key in Scan Code Set 3 and the USB scan code set.

As well, since alternate codes for F1 through F10 are used for the special keys to the left of the main keyboard, since codes for the complete set of those keys are not certain, code 72 can be used instead for the Help key.

Of course, this keyboard will require a special keyboard driver, despite the attempt to be as compatible as possible.

Copyright (c) 2003, 2005, 2007, 2009 John J. G. Savard


[Next] [Up/Previous] [Previous Section] [Home] [Other]