<!doctype linuxdoc system>

<article>

<title>Keyboard scancodes
<author>Andries Brouwer, <tt/aeb@cwi.nl/
<date>v1.1d, 2000-10-26

<abstract>
This note contains some information about PC keyboard scancodes.
</abstract>

<toc>

<sect>Ordinary PC keyboards<p>
The data from a keyboard comes mainly in the form of scancodes,
produced by key presses or used in the protocol with the computer.
(<ref id="kscancodes" name="Different codes"> are used by the keyboard
firmware internally, and there also exist several
<ref id="kscancodes" name="sets of scancodes">. Here, for the
time being, we only give the default codes - those from scancode set 2.)
Each key press and key release produces between 0 and 6 scancodes.

<sect1>Key release<p>
Below I'll only mention the scancode for key press (`make').
The scancode for key release (`break') is obtained from it
by setting the high order bit (adding 0x80 = 128).
Thus, Esc press produces scancode <bf>01</bf>, Esc release
scancode <bf>81</bf> (hex).
For sequences things are similar: Keypad-/ gives <bf>e0</bf> <bf>35</bf>
when pressed, <bf>e0</bf> <bf>b5</bf> when released. Most keyboards will
repeat the make code (key down code) when the key repeats. Some will also
fake Shift down and Shift up events during the repeat.

The keys PrtSc/SysRq and Pause/Break are special.
The former produces scancode <bf>e0</bf> <bf>2a</bf> <bf>e0</bf> <bf>37</bf>
when no modifier key is pressed simultaneously, <bf>e0</bf> <bf>37</bf>
together with Shift or Ctrl, but <bf>54</bf> together with (left or right) Alt.
(And one gets the expected sequences upon release. But see
<ref id="mtek" name="below">.)
The latter produces scancode sequence
<bf>e1</bf> <bf>1d</bf> <bf>45</bf> <bf>e1</bf> <bf>9d</bf> <bf>c5</bf>
when pressed (without modifier) and nothing at all upon release.
However, together with (left or right) Ctrl, one gets
<bf>e0</bf> <bf>46</bf> <bf>e0</bf> <bf>c6</bf>,
and again nothing at release. It does not repeat.

<sect1>Protocol scancodes<p>
Most scancodes indicate a key press or release.
Some are used in the communication protocol.
<p>
<bf>00</bf> (Keyboard error - see <bf>ff</bf>)
<p>
<bf>aa</bf> (BAT [Basic Assurance Test] OK)
<p>
<bf>ee</bf> (Result of echo command)
<p>
<bf>f1</bf> (Some keyboards, as reply to command <bf>a4</bf>:
Password not installed)
<p>
<bf>fa</bf> (Acknowledge from kbd)
<p>
<bf>fc</bf> (BAT error or Mouse transmit error)
<p>
<bf>fe</bf> (Keyboard fails to ack, please resend)
<p>
<bf>ff</bf> (Keyboard error)
<newline>
Three common causes for keyboard error are:
(i) several keys pressed simultaneously,
(ii) keyboard buffer overflow,
(iii) parity error on the serial line used by keyboard
and keyboard controller for communication.
The error reported is <bf>ff</bf> in
<ref name="scancode mode" id="kscancodes"> 1,
and <bf>00</bf> in scancode modes 2 and 3.
If translation is on, both <bf>00</bf> and <bf>ff</bf>
are translated as <bf>ff</bf>.

<sect1>Escape scancodes<p>
The codes <bf>e0</bf> and <bf>e1</bf> introduce scancode sequences,
and are not usually used as isolated scancodes themselves
(but see <ref id="e0_as_key" name="below">).
<p>
This, and the above, means that scancodes
<bf>00</bf>, <bf>60</bf>, <bf>61</bf>, <bf>6e</bf>, <bf>71</bf>,
<bf>7a</bf>, <bf>7c</bf>, <bf>7e</bf>, <bf>7f</bf>
are unavailable to signify key presses (on a default keyboard;
we'll see keyboards that actually use scancode <bf>60</bf>).
<p>
Also other prefixes occur, see <ref id="prefix_80" name="below">.

<sect1>Ordinary scancodes<p>
The scancodes in scancode set 2 are given in hex.
Between parentheses the keycap on a US keyboard.
The scancodes are given in order, grouped according
to groups of keys that are usually found next to each other.
<p>
<bf>00</bf> is normally an error code
<p>
<bf>01</bf> (Esc)
<p>
<bf>02</bf> (1!), <bf>03</bf> (2@), <bf>04</bf> (3#), <bf>05</bf> (4$),
<bf>06</bf> (5%E), <bf>07</bf> (6^), <bf>08</bf> (7&amp;),
<bf>09</bf> (8*), <bf>0a</bf> (9(), <bf>0b</bf> (0)), <bf>0c</bf> (-_),
<bf>0d</bf> (=+), <bf>0e</bf> (Backspace)
<p>
<bf>0f</bf> (Tab), <bf>10</bf> (Q), <bf>11</bf> (W), <bf>12</bf> (E),
<bf>13</bf> (R), <bf>14</bf> (T), <bf>15</bf> (Y),
<bf>16</bf> (U), <bf>17</bf> (I), <bf>18</bf> (O),
<bf>19</bf> (P), <bf>1a</bf> ([{), <bf>1b</bf> (]})
<p>
<bf>1c</bf> (Enter)
<p>
<bf>1d</bf> (LCtrl)
<p>
<bf>1e</bf> (A), <bf>1f</bf> (S), <bf>20</bf> (D), <bf>21</bf> (F),
<bf>22</bf> (G), <bf>23</bf> (H), <bf>24</bf> (J), <bf>25</bf> (K),
<bf>26</bf> (L), <bf>27</bf> (;:), <bf>28</bf> ('")
<p>
<bf>29</bf> (`&tilde;)
<p>
<bf>2a</bf> (LShift)
<p>
<bf>2b</bf> (\|), on a 102-key keyboard
<p>
<bf>2c</bf> (Z), <bf>2d</bf> (X), <bf>2e</bf> (C), <bf>2f</bf> (V),
<bf>30</bf> (B), <bf>31</bf> (N), <bf>32</bf> (M), <bf>33</bf> (,&lt;),
<bf>34</bf> (.&gt;), <bf>35</bf> (/?), <bf>36</bf> (RShift)
<p>
<bf>37</bf> (Keypad-*) or (*/PrtScn) on a 83/84-key keyboard
<p>
<bf>38</bf> (LAlt), <bf>39</bf> (Space bar),
<p>
<bf>3a</bf> (CapsLock)
<p>
<bf>3b</bf> (F1), <bf>3c</bf> (F2), <bf>3d</bf> (F3), <bf>3e</bf> (F4),
<bf>3f</bf> (F5), <bf>40</bf> (F6), <bf>41</bf> (F7),
<bf>42</bf> (F8), <bf>43</bf> (F9), <bf>44</bf> (F10)
<p>
<bf>45</bf> (NumLock)
<p>
<bf>46</bf> (ScrollLock)
<p>
<bf>47</bf> (Keypad-7/Home), <bf>48</bf> (Keypad-8/Up),
<bf>49</bf> (Keypad-9/PgUp)
<p>
<bf>4a</bf> (Keypad--)
<p>
<bf>4b</bf> (Keypad-4/Left), <bf>4c</bf> (Keypad-5),
<bf>4d</bf> (Keypad-6/Right), <bf>4e</bf> (Keypad-+)
<p>
<bf>4f</bf> (Keypad-1/End), <bf>50</bf> (Keypad-2/Down),
<bf>51</bf> (Keypad-3/PgDn)
<p>
<bf>52</bf> (Keypad-0/Ins), <bf>53</bf> (Keypad-./Del)
<p>
<bf>54</bf> (Alt-SysRq) on a 84+ key keyboard
<p>
<bf>55</bf> is less common; occurs as PF1 on a Focus 9000 keyboard,
and as FN on an IBM ThinkPad.
<p>
<bf>56</bf> mostly on non-US keyboards. It is an unlabelled key
next to the space bar on a Toshiba notebook.
<p>
<bf>57</bf> (F11), <bf>58</bf> (F12) both on a 101+ key keyboard
<p>
<bf>59</bf>-<bf>5a</bf>-...-<bf>7f</bf> are less common.
Scancodes <bf>59</bf>-<bf>5c</bf> occur on the RC930 keyboard.
X calls <bf>5d</bf> `KEY_Begin'.
Scancodes <bf>55</bf>, <bf>6d</bf>, <bf>6f</bf>, <bf>73</bf>, <bf>74</bf>,
<bf>77</bf>, <bf>78</bf>, <bf>79</bf>, <bf>7a</bf>, <bf>7b</bf>,
<bf>7c</bf>, <bf>7e</bf> occur on the Focus 9000 keyboard.
Scancodes <bf>73</bf>, <bf>7d</bf> occur on a Japanese 86/106 keyboard.
<p>

<sect1>Escaped scancodes<p>
Apart from the Pause/Break key that has an escaped sequence starting
with <bf>e1</bf>, the escape used is <bf>e0</bf>. Often, the codes
are chosen in such a way that something meaningful happens when
the receiver just discards the <bf>e0</bf>.
<p>
<bf>e0</bf> <bf>1c</bf> (Keypad Enter) - <bf>1c</bf> (Enter)
<p>
<bf>e0</bf> <bf>1d</bf> (RCtrl) - <bf>1d</bf> (LCtrl)
<p>
<bf>e0</bf> <bf>2a</bf> (fake LShift) - <bf>2a</bf> (LShift)
<p>
<bf>e0</bf> <bf>35</bf> (Keypad-/) - <bf>35</bf> (/?)
<p>
<bf>e0</bf> <bf>36</bf> (fake RShift) - <bf>36</bf> (RShift)
<p>
<bf>e0</bf> <bf>37</bf> (Ctrl-PrtScn) - <bf>37</bf> (*/PrtScn)
<p>
<bf>e0</bf> <bf>38</bf> (RAlt) - <bf>38</bf> (LAlt)
<p>
<bf>e0</bf> <bf>46</bf> (Ctrl-Break) - <bf>46</bf> (ScrollLock)
<p>
<bf>e0</bf> <bf>47</bf> (Grey Home) - <bf>47</bf> (Keypad-7/Home)
<p>
<bf>e0</bf> <bf>48</bf> (Grey Up) - <bf>48</bf> (Keypad-8/UpArrow)
<p>
<bf>e0</bf> <bf>49</bf> (Grey PgUp) - <bf>49</bf> (Keypad-9/PgUp)
<p>
<bf>e0</bf> <bf>4b</bf> (Grey Left) - <bf>4b</bf> (Keypad-4/Left)
<p>
<bf>e0</bf> <bf>4d</bf> (Grey Right) - <bf>4d</bf> (Keypad-6/Right)
<p>
<bf>e0</bf> <bf>4f</bf> (Grey End) - <bf>4f</bf> (Keypad-1/End)
<p>
<bf>e0</bf> <bf>50</bf> (Grey Down) - <bf>50</bf> (Keypad-2/DownArrow)
<p>
<bf>e0</bf> <bf>51</bf> (Grey PgDn) - <bf>51</bf> (Keypad-3/PgDn)
<p>
<bf>e0</bf> <bf>52</bf> (Grey Insert) - <bf>52</bf> (Keypad-0/Ins)
<p>
<bf>e0</bf> <bf>53</bf> (Grey Delete) - <bf>53</bf> (Keypad-./Del)
<p>
These escaped scancodes occur only on 101+ key keyboards.

<sect1>Fake shifts<p>
The ten grey keys Insert, Home, PgUp, Delete, End, PgDn,
Up, Left, Down, Right are supposed to function regardless
of the state of Shift and NumLock keys. But for an old AT keyboard
the keypad keys would produce digits when Numlock was on or Shift
was down. Therefore, in order to fool old programs,
fake scancodes are sent: when LShift is down, and Insert is
pressed, <bf>e0</bf> <bf>aa</bf> <bf>e0</bf> <bf>52</bf> is sent;
upon release of Insert <bf>e0</bf> <bf>d2</bf> <bf>e0</bf> <bf>2a</bf>
is sent. In other words, a fake LShift-up and
fake LShift-down are inserted.

If the Shift key is released earlier than the repeated key,
then a real Shift-up code occurs (without preceding fake Shift-down)
so that a program ignoring <bf>e0</bf> would see one more Shift-up
than Shift-down.

When NumLock is on, no fake Shifts are sent when Shift was down,
but fake Shifts are sent when Shift was not down. Thus,
with Numlock, if Insert is pressed,
<bf>e0</bf> <bf>2a</bf> <bf>e0</bf> <bf>52</bf> is sent
and upon release <bf>e0</bf> <bf>d2</bf> <bf>e0</bf> <bf>aa</bf> is sent.
The keyboard maintains a private NumLock mode, toggled when
NumLock is pressed, and set when the NumLock LED is set.

In the same way, when Shift is down, the Grey-/ key produces
fake Shift-up and fake Shift-down sequences. However, it does
not react to the state of NumLock. The purpose of course is to
fool programs that identify Grey-/ with ordinary /, so that they
don't treat Shift-Grey-/ like Shift-/, i.e., ?.

On a Toshiba notebook, the three Windows keys are treated like
the group of ten keys mentioned, and get fake shifts when
(left or right) Shift is down. They do not react to NumLock.

<sect1>Turbo Mode<p>
On some motherboards the LCtrl-LAlt-GreyPlus and LCtrl-LAlt-GreyMinus
switch Turbo mode on/off, respectively. For these, the motherboard
may generate the same scancode sequence when the Turbo button is
pushed: Turbo Switch (High->Low):
<bf>1d</bf> <bf>38</bf> <bf>4a</bf> <bf>ce</bf> <bf>b8</bf> <bf>9d</bf>
and Turbo Switch (Low->High):
<bf>1d</bf> <bf>38</bf> <bf>4e</bf> <bf>ce</bf> <bf>b8</bf> <bf>9d</bf>.
<p>
Other peculiar combinations in this style include
LCtrl-LAlt-LShift-GreyMinus to turn off system cache.
<p>
Thio Yu Jin &lt;<tt/jin@singmail.com/&gt; complains that on his Toshiba 4010CDS
the Ctrl-Alt-Shift-T key combination brings up the Toshiba user manual.
(04 Mar 1999 - not April 1.)
<p>

<sect1>Power Saving<p>
<htmlurl url="http://www.microsoft.com/HWDEV/specs/PMref/PMinput.htm"
name="Microsoft"> recommends: "i8042-based keyboards should deploy the
following scan codes for power management buttons, i.e., POWER and SLEEP
buttons:

<table><tabular ca="c|cc">
      | Set-1 make/break                                | Set-2 make/break @@
Power | <bf>e0</bf> <bf>5e</bf> / <bf>e0</bf> <bf>de</bf> |
<bf>e0</bf> <bf>37</bf> / <bf>e0</bf> <bf>f0</bf> <bf>37</bf> @
Sleep | <bf>e0</bf> <bf>5f</bf> / <bf>e0</bf> <bf>df</bf> |
<bf>e0</bf> <bf>3f</bf> / <bf>e0</bf> <bf>f0</bf> <bf>3f</bf> @
Wake  | <bf>e0</bf> <bf>63</bf> / <bf>e0</bf> <bf>e3</bf> |
<bf>e0</bf> <bf>5e</bf> / <bf>e0</bf> <bf>f0</bf> <bf>5e</bf> @
</tabular></table>

The Power, Sleep, and Wake event scan codes are the i8042 equivalents
to the System Power Down, System Sleep, and System Wake Up HID usages".

<sect>Special keyboards<p>

<sect1>Cherry G80-0777<p>
According to <htmlurl name="FreeKEYB/kbdinfo.html"
url="http://titan.informatik.uni-bonn.de/~frinke/FreeKEYB/kbdinfo.html">
this keyboard has five additional keys with scancodes
<bf>55</bf> (F11), <bf>56</bf> (F12),
<bf>57</bf> (F13), <bf>58</bf> (F14), <bf>59</bf> (F15).

<sect1>Amstrad/Schneider PC1512<p>
This keyboard has a Del key on the keypad, and both Del-> and Del<- keys
above the Enter key. The Del-> key has scancode <bf>70</bf>.
There is an additional Enter key with scancode <bf>74</bf>.
It is possible to connect a mouse and/or joystick to the keyboard,
and then these devices also yield scancodes:
<bf>77</bf> (joystick button 1), <bf>78</bf> (joystick button 2),
<bf>79</bf> (joystick right), <bf>7a</bf> (joystick left),
<bf>7b</bf> (joystick up), <bf>7c</bf> (joystick down),
<bf>7d</bf> (mouse right), <bf>7e</bf> (mouse left).
The Amstrad keyboard is entirely incompatible with XT and AT keyboards,
and can be used only on an Amstrad; conversely, no other keyboard will
work on an older Amstrad.

<sect1>Focus KeyPro FK-9000 keyboard<p>
Raul D. Miller &lt;<tt/rockwell@nova.umd.edu/&gt;
and Timothy C. Hagman &lt;<tt/hagmanti@cps.msu.edu/&gt;
<!-- and William Setzer? -->
report:
<p>
<it>
The keyboard is a KeyPro FK-9000.  The FCC label says it's made in
Taiwan by Focus Electronic Co, Ltd.  It has a built-in calculator.
</it>
<p>
<it>
This keyboard has twelve additional keys, with scancodes
</it>
<bf>55</bf> (PF1),
<bf>6d</bf> (PF11),
<bf>6f</bf> (PF12),
<bf>73</bf> (PF2),
<bf>74</bf> (PF9),
<bf>77</bf> (PF3),
<bf>78</bf> (PF4),
<bf>79</bf> (PF5),
<bf>7a</bf>* (PF6),
<bf>7b</bf> (PF7),
<bf>7c</bf> (PF8),
<bf>7e</bf>* (PF10).
<p>
<it>
The break codes equal the make codes ORed with 0x80, as always,
but the Linux kernel eats <bf>fa</bf> and <bf>fe</bf> as
protocol bytes.
</it>
<p>
<it>
The behavior of these keys is different from that of normal keys--
they generate nothing when pressed; then generate the above scancodes
at the normal repeat time and rate, and then generate (except for the
starred ones) their scancode ORed with 0x80 when released...
</it>
<p>
<it>
These PF keys are reprogrammable -- and programming occurs as a sequence
of keyboard actions.  Therefore, the PF keys duplicate whatever
keyboard actions occurred during their programming.
You hit the "Prog" key, then the PF key you want to program; type the
string you want to store in the key (it's limited to 14 keypresses),
and then hit the PF key again. After that, when you hit the PF key,
it sends the string, and generates its own abnormal scancode upon
release. When the key is held down, it generates the scancode repeatedly,
but does not generate the string stored in it repeatedly.
</it>
<p>
<it>
When you go to program a key, the scancodes for "PF##-" are sent
to the computer, then the scancodes for each key you hit as you
hit it (the shift, etc. keys are an exception-- they send "s-"
and such :), and then, when you hit the PF## key again to end the
programming, it sends a sequence of (at least) 18 "0e 8e"s --
Backspaces...
</it>
<p>
<it>
The program key itself doesn't generate a scancode at any time.
The same applies to the CE and AC/ON keys (part of the calculator).
There is a switch to change between calculator and keyboard mode
which generates no scancodes.
</it>
<p>
<it>
When the keyboard is in calculator mode, the entire numeric
keypad (and everything else on the right side) generates no
scancodes.
</it>
<p>
<it>
When the keyboard is not in caluclator mode, the %, MC, MR, M-,
M+, and Square Root keys all generate 0xff when pressed,
0xff to repeat, and 0xff on release.
</it>
<p>
<it>
The little unlabeled key between the right Ctrl and right Alt
generates <bf>56</bf> when hit, repeats that, and then <bf>d6</bf>
when released, just like a normal key.
</it>
<p>

<sect1>BTC keyboard<p>
This keyboard has one additional key, with escaped scancode
<bf>e0</bf> <bf>6f</bf> (Macro). (Funny enough it does this
in all modes, each of the three scancode sets, translated or not.
In particular, this Macro key is the only key that generates
two bytes in scancode mode 3.)

<sect1>LK450 keyboard<p>
This keyboard has six additional keys, with escaped scancodes
<bf>e0</bf> <bf>3d</bf> (F13),
<bf>e0</bf> <bf>3e</bf> (F14),
<bf>e0</bf> <bf>3f</bf> (Help),
<bf>e0</bf> <bf>40</bf> (Do),
<bf>e0</bf> <bf>41</bf> (F17),
<bf>e0</bf> <bf>4e</bf> (Keypad-minplus).

<sect1>OmniKey keyboard<p>
This keyboard has one additional key, with escaped scancode
<bf>e0</bf> <bf>4c</bf> (Omni).

<sect1>GRiD 2260 keyboard<p>
The GRiD 2260 notebook has a key producing the
<bf>6c</bf> scancode; I do not know the keycap.

<sect1>A Japanese 86/106 keyboard<p>
Barry Yip &lt;<tt/g609296@cc.win.or.jp/&gt; reports:
<p>
<it>
This keyboard has two additional keys, with scancodes
<bf>73</bf> (\-) and <bf>7d</bf> (\|).
This kind of keyboard is rather standard in Japan. They are called 106
keyboard. Mine is a notebook so it is 86 keyboard. No specific brand
name.
</it>

<sect1>Trust Ergonomic keyboard<p>
Frank v Waveren &lt;<tt/fvw@var.cx/&gt; reports:
The Trust Ergo Track keyboard has one additional key (`application key'), with
escaped scancode <bf>e0</bf> <bf>68</bf>. The keycap is a triangle pointing left.

<sect1>Brazilian keyboard<p>
Arnaldo Moura &lt;<tt/lumbago@vnet.ibm.com/&gt; reports:
<p>
<it>
This keyboard has two unusual keys, with scancodes
<bf>73</bf> (/?) and <bf>7e</bf> (Keypad-.).
</it>
<p>
Also others mention an ABNT keyboard with <bf>73</bf> and
<bf>7e</bf> keys, mostly because these keys do not function
with Windows NT 4.0.
<p>
ABNT (Associação Brasileira de Normas Tecnicas) and ABNT2
are Brazilian keyboard layout standards. The plain Brazilian
keyboard has 103 keys. I find an ABNT 107 key keyboard announced by
<htmlurl name="gertec" url="http://www.gertec.com.br/tecpc1.htm">.
with Suspend / Wake-up / Power power management keys.
<it>For enabling these functions, run BIOS setup.</it>

<sect1>RC930 keyboard<p>
Torben Fjerdingstad &lt;<tt/tfj@olivia.ping.dk/&gt; reports:
<p>
<it>
It's an rc930 keyboard, from Regnecentralen/RC International, Now ICL.
This keyboard has four additional keys, with scancodes
</it>
<bf>59</bf> (A1),
<bf>5a</bf> (A2),
<bf>5b</bf> (A3),
<bf>5c</bf> (A4).
<p>
<it>
The rc930/rc931 keyboards are not made anymore, because they had a
problem with fast typists, writing over 400 chars/minute.
Writing 'af&lt;space&gt;', very, very fast, did a PgUp.
</it>

<sect1>Tandberg Data keyboard
<label id="prefix_80">
<p>
Kjetil Torgrim Homme &lt;<tt/kjetilho@ifi.uio.no/&gt; reports:
<p>
<it>
My Tandberg Data keyboard uses the prefix <bf>80</bf> for
its numerous (20) extra keys. The <bf>80</bf> scancodes are:
</it><p>
<bf>11</bf>, <bf>12</bf>, <bf>13</bf>, <bf>14</bf>, <bf>16</bf>,
<bf>17</bf>, <bf>18</bf>, <bf>19</bf>, <bf>1e</bf>, <bf>1f</bf>,
<bf>20</bf>, <bf>21</bf>, <bf>22</bf>, <bf>23</bf>, <bf>25</bf>,
<bf>26</bf>, <bf>2f</bf>, <bf>30</bf>, <bf>32</bf>, <bf>56</bf>.
<p><it>
For completeness, the <bf>e0</bf> scancodes:
</it><p>
<bf>1c</bf>, <bf>2a</bf>, <bf>35</bf>, <bf>37</bf>, <bf>47</bf>,
<bf>48</bf>, <bf>49</bf>, <bf>4b</bf>, <bf>4d</bf>, <bf>4f</bf>,
<bf>50</bf>, <bf>51</bf>, <bf>52</bf>, <bf>53</bf>.
<p><it>
The <bf>e1</bf> scancode: <bf>1d</bf>.
As you can see, there is no overlap on this keyboard.
</it>
<p>
Harald Arnesen &lt;<tt/gurre@start.no/&gt; gives the keycaps
for these for the Tandberg TDV5020 keyboard.
All use prefix <bf>80</bf> on both press and release.
<p>
Thirteen keys have (Norwegian) text:
<bf>11</bf> HJELP (help), <bf>14</bf> STRYK (cut),
<bf>16</bf> KOPI (copy), <bf>17</bf> FLYTT (move),
<bf>19</bf> JUST (justify), <bf>21</bf> MERK (mark),
<bf>22</bf> ANGRE (undo), <bf>23</bf> SKRIV (print),
<bf>25</bf> SLUTT (exit), <bf>26</bf> FELT (field),
<bf>2f</bf> AVSN (paragraph), <bf>30</bf> SETN (sentence),
and <bf>32</bf> ORD (word).
<p>
Seven keys have symbols: <bf>12</bf> /\/\/\ (insert soft hyphen),
<bf>13</bf> [Crossed down-arrow] (move down five lines),
<bf>18</bf> &gt;&gt; &lt;&lt; (justify left/right),
<bf>1e</bf> &lt;&gt; &gt;&lt; (justify full/center),
<bf>1f</bf> |&lt;- (backtab),
<bf>20</bf> -&gt;| (tab), and
<bf>56</bf> [Back/down arrow] (start new paragraph).
<p>
Other keycaps also occur. Those given above were meant
for use with the Notis WP word processor.

<sect1>A Chinese keyboard<p>
Bruno Haible &lt;<tt/haible@ilog.fr/&gt; reports:
The keyboard has three keys <bf>e0</bf> <bf>5e</bf> (Power),
<bf>e0</bf> <bf>5f</bf> (Sleep), <bf>e0</bf> <bf>63</bf> (WakeUp)
in the following positions:

<p><table><tabular ca="lllll">
  | F10 F11 F12 | Power  | Sleep  | WakeUp @@
..| Backspace   | PrtScr | ScrLck | Pause @
..| Return      | Ins    | Home   | PgUp @
..| Return      | Del    | End    | PgDn @
</tabular></table>

<sect1>Microsoft Natural keyboard<p>
This keyboard has three additional keys, with escaped scancodes
<bf>e0</bf> <bf>5b</bf> (LeftWindow),
<bf>e0</bf> <bf>5c</bf> (RightWindow),
<bf>e0</bf> <bf>5d</bf> (Menu).
The kscancodes (see <ref id="kscancodes" name="below">)
are <bf>e0</bf> <bf>1f</bf>, <bf>e0</bf> <bf>27</bf> and
<bf>e0</bf> <bf>2f</bf>, respectively.
The USB key codes are usage page 0x07, usage index 227, 231, 101
(decimal), respectively.
Microsoft <htmlurl name="describes"
url="http://www.microsoft.com/hwdev/download/desinit/scancode.zip">
the intended use in detail. Both Windows keys are intended to be
used as modifier keys, like both shift and control and alt keys.
The Menu key may be modified by shift etc.

<sect1>Microsoft Internet keyboard<p>
In addition to the three extra keys on the Microsoft Natural keyboard,
this keyboard has ten keys, with escaped scancodes
<bf>e0</bf> <bf>21</bf> (Calculator),
<bf>e0</bf> <bf>32</bf> (Web/Home),
<bf>e0</bf> <bf>5f</bf> (Sleep),
<bf>e0</bf> <bf>65</bf> (Search),
<bf>e0</bf> <bf>66</bf> (Favorites),
<bf>e0</bf> <bf>68</bf> (Stop),
<bf>e0</bf> <bf>69</bf> (Forward),
<bf>e0</bf> <bf>6a</bf> (Back),
<bf>e0</bf> <bf>6b</bf> (My Computer),
<bf>e0</bf> <bf>6c</bf> (Mail).
The kscancodes (see <ref id="kscancodes" name="below">) are
<bf>e0</bf> <bf>2b</bf>, <bf>e0</bf> <bf>3a</bf>,
<bf>e0</bf> <bf>3f</bf>, <bf>e0</bf> <bf>10</bf>,
<bf>e0</bf> <bf>18</bf>, <bf>e0</bf> <bf>28</bf>,
<bf>e0</bf> <bf>30</bf>, <bf>e0</bf> <bf>38</bf>,
<bf>e0</bf> <bf>40</bf>, <bf>e0</bf> <bf>48</bf>,
respectively.

<sect1>Microsoft Natural keyboard pro<p>
Marco Melgazzi &lt;<tt/marco@techie.com/&gt; reports:
The Microsoft Natural keyboard pro has 19 additional keys,
with escaped scancodes
<bf>e0</bf> <bf>6a</bf> (Back),
<bf>e0</bf> <bf>69</bf> (Forward),
<bf>e0</bf> <bf>68</bf> (Stop),
<bf>e0</bf> <bf>67</bf> (Refresh),
<bf>e0</bf> <bf>65</bf> (Search),
<bf>e0</bf> <bf>66</bf> (Favorites),
<bf>e0</bf> <bf>32</bf> (Web/Home),
<bf>e0</bf> <bf>6c</bf> (Mail),
<bf>e0</bf> <bf>20</bf> (Mute),
<bf>e0</bf> <bf>2e</bf> (Volume -),
<bf>e0</bf> <bf>30</bf> (Volume +),
<bf>e0</bf> <bf>22</bf> (Play/Pause),
<bf>e0</bf> <bf>24</bf> (Stop),
<bf>e0</bf> <bf>10</bf> (Prev Track),
<bf>e0</bf> <bf>19</bf> (Next Track),
<bf>e0</bf> <bf>6d</bf> (Media),
<bf>e0</bf> <bf>6b</bf> (My Computer),
<bf>e0</bf> <bf>21</bf> (Calculator),
<bf>e0</bf> <bf>5f</bf> (Sleep).
(That is, we have the ten extra keys of the Microsoft Internet keyboard,
with the same scancodes, and also Refresh, Mute, Volume -, Volume +,
Play/Pause, Stop, Prev Track, Next Track, Media.)

<sect1>Logitech Internet keyboard<p>
Jonathan DeBoer &lt;<tt/deboer@ugrad.cs.ualberta.ca/&gt; reports:
This keyboard has 18 unusual keys.
<p>
<bf>e0</bf> <bf>7a</bf> (WWW),
<bf>e0</bf> <bf>32</bf> (History),
<bf>e0</bf> <bf>21</bf> (Open URL),
<bf>e0</bf> <bf>23</bf> (Home),
<bf>38</bf> <bf>2a</bf> <bf>0f</bf> <bf>8f</bf> (key press)
<bf>8f</bf> <bf>b8</bf> <bf>aa</bf> (key release) (Send To Back) -
this sequence simulates Alt+Shift+Tab, but contains two Tab releases,
<bf>e0</bf> <bf>17</bf> (Print),
<bf>e0</bf> <bf>10</bf> (Back),
<bf>e0</bf> <bf>22</bf> (Forward),
<bf>e0</bf> <bf>24</bf> (Stop),
<bf>e0</bf> <bf>19</bf> (Refresh),
<bf>e0</bf> <bf>1e</bf> (Search),
<bf>e0</bf> <bf>12</bf> (Find),
<bf>e0</bf> <bf>26</bf> (Add Favourite),
<bf>e0</bf> <bf>18</bf> (Open Favourites),
<bf>e0</bf> <bf>20</bf> (Hot Links),
<bf>e0</bf> <bf>30</bf> (Scroll Up),
<bf>e0</bf> <bf>2e</bf> (Scroll Down),
<bf>e0</bf> <bf>25</bf> (Logitech).
<p>

Ryan Lortie &lt;<tt/desertangel@globalserve.net/&gt; writes:
The "Logitech" key is used as a modifier.
In windows, Logitech-Keypad+ increases volume, Logitech-Keypad- decreases.
There is a conjoined dual-button key for "scroll".
You press the top part to scroll up, the bottom to scroll down.

<sect1>Compaq Armada laptop keyboard<p>
Christian Gennerat &lt;<tt/christian.gennerat@vz.cit.alcatel.fr/&gt; writes:
There are 4 extra keys on the Compaq Armada laptops.
The four keys are located over the Esc-F1..F12, and are labelled *1-*4.
Scancodes: <bf>65</bf>, <bf>67</bf>, <bf>69</bf>, <bf>6b</bf>.

<sect1>Rapid Access keyboard<p>
Dennis Bjorklund &lt;<tt/dennisb@cs.chalmers.se/&gt; writes:
<p>
I have a Rapid Access keyboard with some (14) extra buttons and
two more leds then a normal pc keyboard. To activate the extra buttons
one has to send the sequence <bf>ea</bf> <bf>71</bf>
to the keyboard. Once that is done the extra keys generate normal
e0xx sequences. To turn off the extra keys you send <bf>ea</bf> <bf>70</bf>.

There are 14 keys:
<p>
<bf>e0</bf> <bf>25</bf> (Suspend),
<bf>e0</bf> <bf>26</bf> (Help),
<bf>e0</bf> <bf>32</bf> (Prg 1),
<bf>e0</bf> <bf>17</bf> (Prg 2),
<bf>e0</bf> <bf>30</bf> (Prg 3),
<bf>e0</bf> <bf>2e</bf> (Prg 4),
<bf>e0</bf> <bf>19</bf> (Play CD),
<bf>e0</bf> <bf>24</bf> (CD Stop),
<bf>e0</bf> <bf>22</bf> (CD Pause),
<bf>e0</bf> <bf>1e</bf> (Vol -),
<bf>e0</bf> <bf>29</bf> (Vol +),
<bf>e0</bf> <bf>23</bf> (Prev song),
<bf>e0</bf> <bf>21</bf> (Next song),
<bf>e0</bf> <bf>12</bf> (Mute).
<p>

The Suspend and Mute buttons have extra leds on them.
These are controlled by the sequence <bf>eb</bf> <bf>00</bf> <bf>xx</bf>
where the <bf>xx</bf> controls the leds. Bit 2 controls the Suspend led and
bit 5 controls the Mute led.

<sect1>Rapid Access II keyboard<p>
John Elliott &lt;<tt/jce@seasip.demon.co.uk/&gt; writes:
<p>
I have an IBM Rapid Access II keyboard (UK layout), which seems to 
generate codes that are similar - but not identical - to the Rapid Access
keycodes listed above.

Keys:
<p>
<bf>e0</bf> <bf>25</bf> (Green, "Internet"),
<bf>e0</bf> <bf>26</bf> (Blue, "Internet shopping"),
<bf>e0</bf> <bf>32</bf> (Yellow, "IBM Web support"),
<bf>e0</bf> <bf>17</bf> (Purple),
<bf>e0</bf> <bf>30</bf> (Red),
<bf>e0</bf> <bf>2e</bf> (Cyan, "Help"),
<bf>e0</bf> <bf>5f</bf> (White, "Standby" - has a LED),
<bf>e0</bf> <bf>20</bf> (CD stop),
<bf>e0</bf> <bf>22</bf> (CD play),
<bf>e0</bf> <bf>24</bf> (CD back),
<bf>e0</bf> <bf>12</bf> (CD fwd),
<bf>e0</bf> <bf>21</bf> (Volume D),
<bf>e0</bf> <bf>23</bf> (Volume U),
<bf>e0</bf> <bf>1e</bf> (Mute - no LED).
<p>

There are also "back" and "forward" keys (one could think of them as 
"page left" and "page right" :-) ). They generate ALT+left and ALT+right
respectively: <bf>38</bf> <bf>e0</bf> <bf>4b</bf> and
<bf>38</bf> <bf>e0</bf> <bf>4d</bf>.


<sect1>Chicony KBP-8993 keyboard<p>
Matthijs Melchior &lt;<tt/mmelchio@xs4all.nl/&gt; reports:
<p>
The Chicony KBP-8993 keyboard is similar. It has 14 additional
keys, enabled by sending <bf>ea</bf> <bf>71</bf> and disabled
by sending <bf>ea</bf> <bf>70</bf>.

These keys generate the following scan codes:
<p>
<bf>e0</bf> <bf>25</bf> (Moon),
<bf>e0</bf> <bf>32</bf> (WWW),
<bf>e0</bf> <bf>30</bf> (DOS),
<bf>e0</bf> <bf>17</bf> (MyDoc),
<bf>e0</bf> <bf>26</bf> (Menu),
<bf>e0</bf> <bf>1e</bf> (zzZ),
<bf>e0</bf> <bf>2e</bf> (Close),
<bf>e0</bf> <bf>24</bf> (Stop),
<bf>e0</bf> <bf>23</bf> (Back),
<bf>e0</bf> <bf>22</bf> (Play),
<bf>e0</bf> <bf>21</bf> (Forward),
<bf>e0</bf> <bf>20</bf> (Mute),
<bf>e0</bf> <bf>12</bf> (VolDown),
<bf>e0</bf> <bf>19</bf> (VolUp).

The two extra leds, above the Moon key, and next to the zzZ key
are manipulated by sending: <bf>eb</bf> <bf>00</bf> <bf>0x</bf>,
where bit 0 is the Moon led and bit 1 is the zzZ led.

<sect1>Logitech Cordless Desktop Pro keyboard<p>
Nick Rusnov &lt;<tt/nick@grawk.net/&gt; reports:
<p>
The special buttons on a Logitech Cordless Desktop Pro keyboard
produce the following scancodes:
<p>
<bf>e0</bf> <bf>5f</bf> (Moon (sleep)),
<bf>e0</bf> <bf>32</bf> (Homepage),
<bf>e0</bf> <bf>6c</bf> (Mail),
<bf>e0</bf> <bf>65</bf> (Search),
<bf>e0</bf> <bf>66</bf> (runningguuy),
<bf>e0</bf> <bf>20</bf> (Mute),
<bf>e0</bf> <bf>2e</bf> (VolDown),
<bf>e0</bf> <bf>30</bf> (VolUp),
<bf>e0</bf> <bf>22</bf> (Play/Pause),
<bf>e0</bf> <bf>24</bf> (Stop),
<bf>e0</bf> <bf>10</bf> (Rewind),
<bf>e0</bf> <bf>19</bf> (ff),
<bf>e0</bf> <bf>21</bf> (Logitech).

<sect1>Keyboards for HP Kayak and Vectra<p>
Fons Rademakers &lt;<tt/Fons.Rademakers@cern.ch/&gt; writes:
<p>
<it>
The electronics for this keyboard was first developed by HP's
Home Products Division (HPD).
They now make improved versions, which I don't know much about.
We (HP Corporate PC Divisions, in Grenoble) reused the electronics,
and changed the serigraphy printed on the keys.
</it>
<p><table>
<tabular ca="cccccccccccccccccccc">
 |Msg|TTl|WWW| ? |Lck| |
 |Msg|Phn|WWW|xxx|Slp| |
 |133|134|135|136|137| @
 |Phn|S3 |S4 |S5 | i | |
 |&lt;&lt;|&gt;&verbar;&verbar;|&lsqb;&rsqb; |&gt;&gt; |HP | |
 |138|139|140|141|142| @
 |   |   |   |   |Mut| |
 |   |   |   |   |Mut| |
 |   |   |   |   |143| @
 |   |   |   |   |Vl+| |
 |   |   |   |   |Vl+| |
 |   |   |   |   |144| @
 |   |   |   |   |VL-| |
 |   |   |   |   |VL-| |
 |   |   |   |   |145| @
</tabular>
<caption>
Grenoble keyboard ------- Old HPD keyboard -------- key numbers
</caption>
</table>

<p><table><tabular ca="ccccc">
 | Key# | Scancode | Gren. Name | HPD name | ASCII @@
 | 133 | <bf>e0 1e</bf> | Message/SC1 | Message | a @
 | 134 | <bf>e0 12</bf> | Top Tools | Phone | e @
 | 135 | <bf>e0 32</bf> | Web Browser | Internet | m @
 | 136 | <bf>e0 17</bf> | Reminder | Shortcut | i @
 | 137 | <bf>e0 25</bf> | Lock | Suspend | k @
 | 138 | <bf>e0 23</bf> | Phone/SC2 | &lt;&lt; | h @
 | 139 | <bf>e0 22</bf> | ShortCut 3 | &gt;&verbar;&verbar; | g @
 | 140 | <bf>e0 24</bf> | ShortCut 4 | &lsqb;&rsqb; | j @
 | 141 | <bf>e0 21</bf> | ShortCut 5 | &gt;&gt; | f @
 | 142 | <bf>e0 26</bf> | Information | Information | l @
 | 143 | <bf>e0 20</bf> | Mute | Mute | d @
 | 144 | <bf>e0 30</bf> | Volume + | Volume + | b @
 | 145 | <bf>e0 2e</bf> | Volume - | Volume - | c @
</tabular></table>

<it>
Note the scancodes above are those read by x86 software in port 0x60.
This is also called Scancode Set 1.
Break codes are the same, with bit 7 of the second scancode set.
Example:</it> <bf>e0 9e</bf> <it>for the Message key.
</it>

<sect1>A keyboard using e0 as ordinary scancode
<label id="e0_as_key">
<p>
Benjamin Carter &lt;<tt/bcarter@ultra5.cs.umr.edu/&gt; reports:
<p>
<it>
I recently came into possession of a 97-key keyboard with Japanese
markings on the keys.  (The keys also have the standard
qwerty-characters on them, with the exception of some of the meta-keys
(there are 3 keys near the Alt keys on either side of the spacebar with
only Japanese characters on them so I don't know what they are).
In any case, the keyboard sends out scancodes that work for all the main
keys (backspace, letters and numbers, enter, shift), but the numeric
keypad, Alt keys, and function keys don't work.
I have run the board through <tt>showkey -s</tt>, so I know what
scancodes this keyboard sends out.
However, the F9 and F10 keys send out <bf>60</bf> and <bf>61</bf>,
respectively, so their key release events send out <bf>e0</bf>
and <bf>e1</bf>, confusing the keyboard driver.
</it>
<p>
# These are across the top of the keyboard.
<p>
<bf>58</bf> (F1), <bf>59</bf> (F2), <bf>5a</bf> (F3),
<bf>5b</bf> (F4), <bf>5c</bf> (F5), <bf>5d</bf> (F6),
<bf>5e</bf> (F7), <bf>5f</bf> (F8), <bf>60</bf> (F9),
<bf>61</bf> (F10), <bf>62</bf> (F11), <bf>63</bf> (F12)
<p> 
<bf>76</bf> (Break), <bf>77</bf> (Setup).
<p> 
# top row
<p>
<bf>64</bf> (Esc),
<bf>02</bf> (1), <bf>03</bf> (2), <bf>04</bf> (3),
<bf>05</bf> (4), <bf>06</bf> (5), <bf>07</bf> (6),
<bf>08</bf> (7), <bf>09</bf> (8), <bf>0a</bf> (9),
<bf>0b</bf> (0), <bf>0c</bf> (-), <bf>0d</bf> (=),
<bf>29</bf> (`), <bf>0e</bf> (Backspace)

<p>
# 2nd row
<p>
<bf>0f</bf> (Tab),
<bf>10</bf> (Q), <bf>11</bf> (W), <bf>12</bf> (E),
<bf>13</bf> (R), <bf>14</bf> (T), <bf>15</bf> (Y),
<bf>16</bf> (U), <bf>17</bf> (I), <bf>18</bf> (O),
<bf>19</bf> (P), <bf>1a</bf> ([), <bf>1b</bf> (]),
<bf>79</bf> (Del), <bf>6e</bf> (Line Feed)

<p>
# 3rd row
<p>
<bf>38</bf> (Ctrl),
<bf>1e</bf> (A), <bf>1f</bf> (S), <bf>20</bf> (D),
<bf>21</bf> (F), <bf>22</bf> (G), <bf>23</bf> (H),
<bf>24</bf> (J), <bf>25</bf> (K), <bf>26</bf> (L),
<bf>27</bf> (;), <bf>28</bf> ('), <bf>75</bf> (\),
<bf>1c</bf> (Return)

<p>
# 4th row
<p>
<bf>2a</bf> (Shift_L),
<bf>2c</bf> (Z), <bf>2d</bf> (X), <bf>2e</bf> (C),
<bf>2f</bf> (V), <bf>30</bf> (B), <bf>31</bf> (N),
<bf>32</bf> (M), <bf>33</bf> (,), <bf>34</bf> (.),
<bf>35</bf> (/),
<bf>3a</bf> ((unknown)),
<bf>36</bf> (Shift_R)

<p>
# bottom row
<p>
<bf>1d</bf> (Caps Lock), <bf>71</bf> (Alt_L),
<bf>01</bf> ((unknown)),
<bf>39</bf> (Space),
<bf>45</bf> ((unknown)),
<bf>72</bf> (Alt_R),
<bf>46</bf> ((unknown))

<p>
# numeric keypad.  No "grey" section on the keyboard.
<p>
<bf>47</bf> (7), <bf>48</bf> (8), <bf>49</bf> (9),
<bf>54</bf> (Keypad -),
<bf>4b</bf> (4), <bf>4c</bf> (5), <bf>4d</bf> (6),
<bf>37</bf> (Keypad +),
<bf>4f</bf> (1), <bf>50</bf> (2), <bf>51</bf> (3),
<bf>4e</bf> (Keypad Enter),
<bf>52</bf> (0),
<bf>78</bf> (Up),
<bf>53</bf> (Keypad .),
<bf>56</bf> (Left),
<bf>55</bf> (Down),
<bf>7d</bf> (Right),
<bf>7e</bf> (Keypad ,).
<p>

There are more keyboards that do not use <bf>e0</bf> as escape code.
For example, Paul Schulz &lt;<tt/pauls@caemrad.com.au/&gt;
reports the same for Sun Type 5 Keyboard with PS/2 connector,
NCD model N-123NA. A kernel patch is required for such keyboards.


<sect1>IBM ThinkPad<p>
George Staikos &lt;<tt/staikos@0wned.org/&gt; writes:
<p><it>
I have an IBM ThinkPad i1460. It has the IBM EasyLaunch&lt;tm&gt; keys.
These are four multicoloured keys up at the top of the keyboard
for "Home Page", "Search", "Shop", "Mail".  They dont' seem to create
any keyboard events at all.  The keyboard interrupt doesn't trigger,
<tt>showkeys</tt> doesn't see them do anything, and in DOS, a simple
sequence of BIOS calls doesn't see them either.
Also, being a laptop, it has an FN key.  This key generates <bf>55</bf>.
</it>

<sect1>A keyboard<p>
Jon Masters &lt;<tt/jonathan@easypenguin.co.uk/&gt; writes:
<p><it>
My new 121 key keyboard has 105 keys + 16 multimedia keys
(including cool stuff like a volume jog dial that sends one scancode
when turned one way and anther when turned the opposite way).
</it>
<p>
<bf>e0</bf> <bf>5e</bf> (Power Off),
<bf>e0</bf> <bf>5f</bf> (Sleep),
<bf>e0</bf> <bf>63</bf> (Resume),
<bf>e0</bf> <bf>2e</bf> (Help),
<bf>e0</bf> <bf>20</bf> (My Favourite),
<bf>e0</bf> <bf>30</bf> (Browser),
<bf>e0</bf> <bf>32</bf> (WWW Search),
<bf>e0</bf> <bf>26</bf> (Shortcut),
<bf>e0</bf> <bf>25</bf> (Volume Down),
<bf>e0</bf> <bf>1e</bf> (Volume Up),
<bf>e0</bf> <bf>12</bf> (Mute),
<bf>e0</bf> <bf>22</bf> (Previous),
<bf>e0</bf> <bf>10</bf> (Stop),
<bf>e0</bf> <bf>24</bf> (Next),
<bf>e0</bf> <bf>21</bf> (Eject),
<bf>e0</bf> <bf>19</bf> (Play).

<sect1>Keyboards with many keys<p>
The current mechanism is unable to handle keyboards with more than
127 keys. But such keyboards seem to exist. (So far, nobody has
reported `I have one', but there are several reports saying
`I have heard about someone who has one'.)

Mark Hatle &lt;<tt/fray@kernel.crashing.org/&gt; wrote:
<p>
<it>
On some ADB keyboards there are actually 128 distinct keys.
They use scancodes 0-127.
</it><p><it>
ADB is Apple Desktop Bus.  The way that ADB works is similar to SCSI but
on a much slower level.  Specifically there is a communications chip in
the computer, ADB controller, and the same chip in the keyboard.  The
keyboard sends the scancode to its internal ADB controller, the internal
ADB controller then does any key mapping needed (not used under linux
from my understanding) and passes the data to the computer.
</it><p><it>
The ADB controller is capable of sending 256 distinct keys, but to my
knowledge only 128 are sent.  The key 0 is the 'a' and key 127 is the
"power button".
</it><p><it>
Also some of the Apple ADB keyboards have special "sound" and "function"
keys.  These keys (used in MacOS for volume up and down, screen contrast
changing, etc) also show up on the ADB scancodes.
</it><p><it>
ADB is used for both m68k and PPC Linux.  The m68k Macintosh port, and
the PPC - Power Macintosh and CHRP ports.
</it><p>
and later:
<p><it>
Basically the scancode sequences for ADB are 16 bit. so there can actually
be 65536 scancodes, currently though only 128 are defined.
</it>

<sect1>A keyboard treating PrtSc/SysRq like Pause/Break<p>
<label id="mtek">
Mike A. Harris &lt;<tt/mharris@meteng.on.ca/&gt;
reports a keyboard (an "Mtek" keyboard, model "K208")
where PrtSc/SysRq behaves like Pause/Break and also sends both make
and break sequences when pressed and nothing when released.
It does not repeat.
(Thus, he gets <bf>e0</bf> <bf>2a</bf> <bf>e0</bf> <bf>37</bf>
<bf>e0</bf> <bf>b7</bf> <bf>e0</bf> <bf>aa</bf> for PrtSc press,
and <bf>54</bf> <bf>d4</bf> for SysRq (i.e., Alt+PrtSc).)


<sect>Keyboard-internal scancodes
<label id="kscancodes">
<p>
<sect1>Three scancode sets<p>
The usual PC keyboards are capable of producing three sets of scancodes.
Writing 0xf0 followed by 1, 2 or 3 to port 0x60 will put the keyboard
in scancode mode 1, 2 or 3. Writing 0xf0 followed by 0 queries the mode,
resulting in a scancode byte 0x43, 0x41 or 0x3f from the keyboard.
<p>
Set 1 contains the values that the XT keyboard (with only one set
of scancodes) produced, with extensions for new keys. Someone
decided that another numbering was more logical and invented
scancode Set 2. However, it was realized that new scancodes
would break old programs, so the keyboard output was fed to a
8042 microprocessor on the motherboard that could translate Set 2
back into Set 1. Indeed a smart construction. This is the default today.
Finally there is the PS/2 version, Set 3, used by nobody.
<p>
Sets 2 and 3 are designed to be translated by the 8042.
Set 1 should not be translated.
<p>
Not all keyboards support all scancode sets. For example, my MyCom
laptop only supports scancode Set 2, and its keyboard does not react
at all when in mode 1 or 3.
<p>
<sect1>Make and Break codes<p>
The key press / key release is coded as follows:
For Set 1, if the make code of a key is <it>c</it>, the break code
will be <it>c</it>+0x80. If the make code is <bf>e0</bf> <it>c</it>,
the break code will be <bf>e0</bf> <it>c</it>+0x80.
The Pause key has make code <bf>e1</bf> <bf>1d</bf> <bf>45</bf>
<bf>e1</bf> <bf>9d</bf> <bf>c5</bf> and does not generate a break code.
For Set 2, if the make code of a key is <it>c</it>, the break code
will be <bf>f0</bf> <it>c</it>. If the make code is <bf>e0</bf> <it>c</it>,
the break code will be <bf>e0</bf> <bf>f0</bf> <it>c</it>.
The Pause key has make code <bf>e1</bf> <bf>14</bf> <bf>77</bf>
<bf>e1</bf> <bf>f0</bf> <bf>14</bf> <bf>f0</bf> <bf>77</bf>.
For Set 3, by default most keys do not generate a break code - only CapsLock,
LShift, RShift, LCtrl and LAlt do.
(On Microsoft keyboards, also LWin, RWin, Menu, Back, Forward, Stop,
Mail, Search, Favorites, Web/Home, MyComputer, Calculator, Sleep do.
On a BTC keyboard, also the Macro key does.)
However, in Scancode Mode 3 it is possible to enable or disable key repeat
and the production of break codes either on a key-by-key basis
or for all keys at once.
And just like for Set 2, key release is indicated by a <bf>f0</bf> prefix
in those cases where it is indicated.
There is nothing special with the Pause key in scancode mode 3.
<p>
<sect1>Translation<p>
The 8042 microprocessor translates the incoming byte stream produced
by the keyboard, and turns an <bf>f0</bf> prefix into an OR with
<bf>80</bf> for the next byte.
<label id="contagious">
(Some implementations do this for the next byte that does not have
this bit set already. A consequence is that in Set 3 the keys with Set-3
value 0x80 or more are broken in a peculiar way: hitting such a key and
then some other key turns the make code for this last key into a break code.
For example the Sleep key on a Microsoft Internet keyboard generates
<bf>54</bf> / <bf>d4</bf> for press/release. But pressing and
releasing first Menu and then Sleep produces
<bf>8d</bf> <bf>8d</bf> <bf>d4</bf> <bf>d4</bf> as translation of
<bf>8d</bf> <bf>f0</bf> <bf>8d</bf> <bf>54</bf> <bf>f0</bf> <bf>54</bf>.
Other implementations are OK.)
<p>
Unless told not to translate, the keyboard controller translates
kscancodes into scancodes using the following table (in hex):

<p><table><tabular ca="c|cccccccccccccccc">
   | 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 0a | 0b | 0c | 0d | 0e | 0f @@
00 | ff | 43 | 41 | 3f | 3d | 3b | 3c | 58 | 64 | 44 | 42 | 40 | 3e | 0f | 29 | 59 @
10 | 65 | 38 | 2a | 70 | 1d | 10 | 02 | 5a | 66 | 71 | 2c | 1f | 1e | 11 | 03 | 5b @
20 | 67 | 2e | 2d | 20 | 12 | 05 | 04 | 5c | 68 | 39 | 2f | 21 | 14 | 13 | 06 | 5d @
30 | 69 | 31 | 30 | 23 | 22 | 15 | 07 | 5e | 6a | 72 | 32 | 24 | 16 | 08 | 09 | 5f @
40 | 6b | 33 | 25 | 17 | 18 | 0b | 0a | 60 | 6c | 34 | 35 | 26 | 27 | 19 | 0c | 61 @
50 | 6d | 73 | 28 | 74 | 1a | 0d | 62 | 6e | 3a | 36 | 1c | 1b | 75 | 2b | 63 | 76 @
60 | 55 | 56 | 77 | 78 | 79 | 7a | 0e | 7b | 7c | 4f | 7d | 4b | 47 | 7e | 7f | 6f @
70 | 52 | 53 | 50 | 4c | 4d | 48 | 01 | 45 | 57 | 4e | 51 | 4a | 37 | 49 | 46 | 54 @
80 | 80?| 81 | 82 | 41 | 54 | 85 | 86 | 87 | 88 | 89 | 8a | 8b | 8c | 8d | 8e | 8f @
90 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 9a | 9b | 9c | 9d | 9e | 9f @
a0 | a0 | a1 | a2 | a3 | a4 | a5 | a6 | a7 | a8 | a9 | aa | ab | ac | ad | ae | af @
b0 | b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7 | b8 | b9 | ba | bb | bc | bd | be | bf @
c0 | c0 | c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 | ca | cb | cc | cd | ce | cf @
d0 | d0 | d1 | d2 | d3 | d4 | d5?| d6?| d7 | d8 | d9?| da?| db | dc | dd | de?| df @
e0 | e0 | e1 | e2?| e3?| e4?| e5 | e6 | e7?| e8 | e9 | ea | eb | ec | ed?| ee?| ef?@
f0 |  - | f1?| f2?| f3?| f4?| f5?| f6?| f7?| f8?| f9?| fa?| fb?| fc?| fd?| fe?| ff @
</tabular></table>

A reference for the first half of this table is the book by Gary J Konzak
<it>PC 8042 Controller</it>, ISBN 0-929392-21-3.
(Report by <tt/vojtech@suse.cz/.)

A way to check this table is: (i) put the keyboard in untranslated modes 1, 2, 3
and look at the <htmlurl name="resulting values" url="table.h">, and
(ii) put the keyboard in translated scancode modes 1, 2, 3. Now compare
the values. The entries with question marks were not checked in this way.

Note that the range <bf>01</bf>-<bf>7f</bf> of this table is 1-1.
In the second half of the table, translated and untranslated values
are equal in all known cases, with the two exceptions <bf>83</bf> and <bf>84</bf>.

One asks the controller to transmit untranslated scancodes by writing
a keyboard controller command with bit 5 set and bit 6 cleared.
E.g., use the command byte <bf>45</bf> to get translated codes,
and <bf>24</bf> to get untranslated codes that do not cause interrupts.

<sect1>Use<p>
Can these other scancode sets be used? Probably not.

(i) My MyCom laptop does not support scancode sets 1 and 3 at all.

(ii) Some laptops have special key combinations that bring one
into a setup or configuration utility. It is impossible to do
anything useful, or to get out of it again, when the scancode mode
is not translated Set 2.

(iii) Many keyboards have bugs in scancode sets 1 and/or 3 but
are fine in scancode Set 2.
Vojtech Pavlik reports that his BTC keyboard has the same codes
for the '1' and '2' keys in Set3, both having the code for '1').
On my BTC keyboard the key up value for Esc and 1 are both <bf>ff</bf>
in scancode Set 1.

(iv) A big advantage of Set 3 is that each key generates a unique code
so that one does not need to parse sequences. However, the BTC keyboard
mentioned above generates <bf>e0</bf> <bf>6f</bf> for its Macro key
also in scancode mode 3.

(v) Some keyboard controllers cannot handle Set 3 values that are
larger than 0x7f, and give <ref id="contagious" name="peculiar results">
for some keys on the Microsoft Internet keyboard in translated
scancode mode 3.

(vi) The USB legacy support only supports translated Set 2.

(vii) The <htmlurl name="Microsoft Keyboard Scan Code Specification"
url="http://www.microsoft.com/hwdev/download/desinit/scancode.zip"> writes:
<it>In the very early days of Windows NT, an attempt was made
to use the much more orthogonal Scan Code Set 3, but due to bugs
in the implementation of this Scan Code Set on numerous OEM
keyboards, the idea was abandoned.</it>
And also <it>Scan Code Set 3 is not used or required for operation
of Microsoft operating systems.</it>


<sect>USB<p>
The USB specification prescribes 16-bit keycodes for keyboard positions,
identified with key captions for the usual US layout.
Below the values are given in decimal. 0-3 are protocol values,
namely NoEvent, ErrorRollOver, POSTFail, ErrorUndefined, respectively.
The values 224-231 are for modifier keys.

<p><table><tabular ca="cccccccccccc">
  |   1 |   2 |   3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 @
- | err | err | err | A | B | C | D | E | F |  G |  H @@
12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 @
 I |  J |  K |  L |  M |  N |  O |  P |  Q |  R |  S |  T @@
24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 @
 U |  V |  W |  X |  Y |  Z |  1 |  2 |  3 |  4 |  5 |  6 @@
36 | 37 | 38 | 39 |   40  |  41 |  42 |  43 |   44  |  45 | 46 | 47 @
 7 |  8 |  9 |  0 | Enter | Esc | BSp | Tab | Space | - / &lowbar; | = / + | &lsqb; / { @@
    48     |   49         |   50  |    51    |   52  |   53        |
    54     |   55         |   56  |    57    |   58  |   59        @
&rsqb; / } | \ / &verbar; |   ... |   ; / :  | ' / " | ` / &tilde; |
  , / &lt; | . / &gt;     | / / ? | Caps Lock |   F1  |   F2 @@
60 | 61 | 62 | 63 | 64 | 65 | 66 |  67 |  68 |  69 |   70   | 71      @
F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | PrtScr | Scroll Lock @@
  72  |   73   |  74  |  75  |   76   |   77     |
  78  |   79   |  80  |  81  |   82   |   83     @
Pause | Insert | Home | PgUp | Delete |   End    |
 PgDn |  Right | Left | Down |   Up   | Num Lock @@
     84     |     85      |      86     |  87  |      88      |     89     |
     90     |     91      |      92     |  93  |      94      |     95     @
    KP /    |    KP *     |     KP -    | KP + |   KP Enter   | KP 1 / End |
KP 2 / Down | KP 3 / PgDn | KP 4 / Left | KP 5 | KP 6 / Right | KP 7 / Home @@
     96   |      97     |     98     |     99     | 100 |   101  |
    102   |     103     |    104     |    105     | 106 |   107  @
KP 8 / Up | KP 9 / PgUp | KP 0 / Ins | KP . / Del | ... | Applic |
  Power   |    KP =     |    F13     |    F14     | F15 |   F16  @@
108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 |   116   |  117 |  118 |   119 @
F17 | F18 | F19 | F20 | F21 | F22 | F23 | F24 | Execute | Help | Menu | Select @@
 120 |   121 |     122   |     123     |         124       |        125       |
 126 |   127 |     128   |     129     |         130       |        131       @
Stop | Again |    Undo   |     Cut     |        Copy       |       Paste      |
Find |  Mute | Volume Up | Volume Down | Locking Caps Lock | Locking Num Lock @@
         132        |  133 |  134 |   135    | 136 | 137 |
         138        |  139 |  140 |   141    | 142 | 143 @
Locking Scroll Lock | KP , | KP = | Internat | Internat | Internat |
         Internat        |  Internat |  Internat |   Internat    | Internat | Internat @@
 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 |    153    |  154  |   155  @
LANG | LANG | LANG | LANG | LANG | LANG | LANG | LANG | LANG | Alt Erase | SysRq | Cancel @@
 156  |  157  |   158  |  159  | 160 |  161 |     162       |     163       | 164 |165|166|167 @
Clear | Prior | Return | Separ | Out | Oper | Clear / Again | CrSel / Props | ExSel | | @@@
 224  |   225  |  226 |  227 |  228  |   229  |  230 |  231 @
LCtrl | LShift | LAlt | LGUI | RCtrl | RShift | RAlt | RGUI @@
</tabular></table>

<sect>Reporting<p>
Additions and corrections are welcome.
Use <tt>showkey -s</tt> to get the scancodes.
Mention keyboard manufacturer and type, and the keycaps.
<p>
Andries Brouwer - <tt/aeb@cwi.nl/

</article>
