<?xml version="1.0" encoding="UTF-8"?>
<!-- **************************************************************************
.... For copyright and licensing terms, see the file named COPYING.
.... **************************************************************************
.-->
<?xml-stylesheet href="docbook-xml.css" type="text/css"?>

<refentry id="console-keyboard-map">

<refmeta xmlns:xi="http://www.w3.org/2001/XInclude">
<refentrytitle>console-keyboard-map</refentrytitle>
<manvolnum>5</manvolnum>
<refmiscinfo class="manual">file formats</refmiscinfo>
<refmiscinfo class="source">nosh</refmiscinfo>
<xi:include href="version.xml" />
</refmeta>

<refnamediv>
<refname>console-keyboard-map</refname>
<refpurpose>format of keyboard map files for user-space virtual terminals</refpurpose>
</refnamediv>

<refsection><title>Description</title>

<para>
Unfortunately, Linux and the BSDs do not agree on a single set of keycode numbers, and cannot share one another's keyboard layout definitions.
So the user-space virtual terminal subsystem uses its own portable keyboard map file, stored in machine-readable form, with a common keyboard matrix that is a superset of USB HID keyboards, PC/AT keyboards, and others.
A keyboard input realizer (<citerefentry><refentrytitle>console-ugen-hid-realizer</refentrytitle><manvolnum>1</manvolnum></citerefentry>, <citerefentry><refentrytitle>console-evdev-realizer</refentrytitle><manvolnum>1</manvolnum></citerefentry>, <citerefentry><refentrytitle>console-uhid-realizer</refentrytitle><manvolnum>1</manvolnum></citerefentry>, <citerefentry><refentrytitle>console-wscons-realizer</refentrytitle><manvolnum>1</manvolnum></citerefentry>, or <citerefentry><refentrytitle>console-pcat-keyboard-realizer</refentrytitle><manvolnum>1</manvolnum></citerefentry>) translates from the non-portable Linux and BSD keyboard codes, or (portable, but insufficient) USB HID "usages", provided by the various devices to this set of common codes.
It then uses a portable keyboard map, supplied to it, to determine what actions to take; which may range from internal state changes to sending key events to an input FIFO of a user-space virtual terminal.
</para>

<para>
FreeBSD keymaps can be compiled from the BSD/SCO <citerefentry><refentrytitle>kbdmap</refentrytitle><manvolnum>5</manvolnum></citerefentry> human-readable form to this portable machine-readable form with the <citerefentry><refentrytitle>console-convert-kbdmap</refentrytitle><manvolnum>1</manvolnum></citerefentry> command.
There is no tool for converting Linux keymaps, which are syntactically a lot more complex than BSD/SCO ones, requiring complex parsers for pre-processing include files and X11-like or old 8-bit non-Unicode features that aren't applicable to user-space virtual terminals anyway (e.g. composition is handled by <citerefentry><refentrytitle>console-input-method</refentrytitle><manvolnum>1</manvolnum></citerefentry> and CIN files, not keymaps, and both user-space virtual terminals and BSD/SCO keymaps are native Unicode).
See <ulink url="terminal-resources.html">the <citetitle>terminal resources</citetitle> section of the nosh Guide</ulink> for detailed information about systems where FreeBSD keymaps are not supplied with the operating system.
</para>

<refsection><title>Uniform common keyboard matrix</title>

<para>
In machine-readable form, a map is a simple 2-dimensional array of 96-octet map entries, representing 17 "rows" of 16 "columns" per row, in row-major order.
This is the "matrix" of a common keyboard denoted by the aforementioned common codeset.
It is modelled on the ISO 9995 keyboard standard.
It has extra rows for the many USB keys not covered by ISO 9995.
It also has accomodations for the keys that have different physical ISO 9995 positions on 101/104-key, 102/105-key, 103/106-key, 104/107-key, and 106/109-key keyboards but that are actually the same PC/AT or USB key code; and vice versa, keys that are in the same physical locations on those keyboards that are actually different PC/AT or USB key codes.
</para>

<para>
These rows are, in order:
</para>
<variablelist>
<varlistentry>
<term>ISO 9995 "E" row</term>
<listitem><para>
The <keycap>&#x238b;&#160;Escape</keycap> key; positions E01 to E12; the additional key from the 106/109-key PC keyboard at E13; one more unused position; then position E14.
</para><note><para>
E00 is a source of much confusion.
</para><para>
On PC/XT keyboards it was the <keycap>&#x238b;&#160;Escape</keycap> key.
In BSD/SCO keyboard map files (c.f. <citerefentry><refentrytitle>kbdmap</refentrytitle><manvolnum>5</manvolnum></citerefentry>) it remains at E00.
It is at E00 here.
</para><para>
IBM PC/AT, Model M, and Windows keyboards move <keycap>&#x238b;&#160;Escape</keycap> to the function row, and misleadingly place the language-variant key (called <keycap>grave</keycap> in the USB specification) at position E00.
That key is here is grouped with other similar keys in the "C" row after C11 (q.v.), where the IBM PC/AT keyboard code numbering in reality placed it.
</para>
</note></listitem>
</varlistentry>
<varlistentry>
<term>ISO 9995 "D" row</term>
<listitem><para>
Positions D00 to D12; two unused positions; then position D14.
</para><note>
The key sometimes found at position D13 is grouped with other similar keys in the third row, where most IBM PC/AT layouts actually place it.
</note></listitem>
</varlistentry>
<varlistentry>
<term>ISO 9995 "C" row</term>
<listitem><para>
An unused position; positions C01 to C11; the language-variant key usually found in position E00; the key usually found in position C12; then two more unused positions.
</para><note>
The key usually found at position C12 on 102/105-key, 103/106-key, 104/107-key, and 106/109-key PC keyboards is sometimes found in position D13 on 101/104-key PC keyboards, but is placed in this row per the majority.
</note><note>
The language-variant (a.k.a. <keycap>grave</keycap>) key from 106/109-key PC keyboards, physically at E00 but (in accordance with the true IBM PC/AT numbering under the covers) placed here, is engraved misleadingly on those keyboards, implying that it is is USB's <keycap>&#x534a;&#x89d2;/&#x5168;&#x89d2;</keycap> (Zenkaku/Hankaku) key.
That latter in fact is a <emphasis>different key</emphasis> in the USB specification, and is in the sixth row.
Despite the engraving, on 106/109-key PC keyboards the key is still the language-variant (<keycap>grave</keycap>) key in hardware and on the wire from the keyboard.
</note></listitem>
</varlistentry>
<varlistentry>
<term>ISO 9995 "B" row</term>
<listitem><para>
An unused position; the additional "Europe 2" key from the 102/105-key and 104/107-key PC keyboards at B00; positions B01 to B10; the additional key from the 104/107-key and 106/109-key PC keyboards at B11; and three more unused positions.
</para><note>
Modifier keys that are on this row per ISO 9995 are factored out into a separate modifiers row.
</note></listitem>
</varlistentry>
<varlistentry>
<term>Modifiers</term>
<listitem><para>
1st <keycap>&#x21e7;&#160;Level&#160;2&#160;shift</keycap>; 2nd <keycap>&#x21e7;&#160;Level&#160;2&#160;shift</keycap>; <keycap>&#x21ee;&#160;Level&#160;3&#160;shift</keycap>; 1st <keycap>&#x2388;&#160;Control</keycap>; 2nd <keycap>&#x2388;&#160;Control</keycap>; 3rd <keycap>&#x2388;&#160;Control</keycap>; 1st <keycap>&#x2318;&#160;Super</keycap>; 2nd <keycap>&#x2318;&#160;Super</keycap>; 1st <keycap>&#x2387;&#160;Alt</keycap>; three unused positions; <keycap>&#x21ec;&#160;Caps&#160;Lock</keycap>; <keycap>Scroll&#160;Lock</keycap>; <keycap>&#x21ed;&#160;Num&#160;Lock</keycap>; and an unused position.
</para><note>
<keycap>&#x21ee;&#160;Level&#160;3&#160;shift</keycap> is also known as <keycap>&#x2325;&#160;Option</keycap> or <keycap>AltGr</keycap>, and there is only 1 such key; as there is only 1 <keycap>&#x2387;&#160;Alt</keycap>.
No keyboard has two of either.
</note><note>
The 3rd <keycap>&#x2388;&#160;Control</keycap> key is fakery employed by PC/AT and later keyboards for compound sequences that used to involve an actual <keycap>&#x2388;&#160;Control</keycap> key on the PC/XT keyboard, so that those compound sequences did not erroneously affect the recorded state of the modifiers for the two real <keycap>&#x2388;&#160;Control</keycap> keys.
This has no USB HID equivalent.
</note></listitem>
</varlistentry>
<varlistentry>
<term>ISO 9995 "A" row</term>
<listitem><para>
An unused position; the <keycap>&#x3072;&#x3089;&#x30c4;&#x306a;/&#x30ab;&#x30bf;&#x30ab;&#x30ca;/&#x30ed;&#x30fc;&#x30de;&#x5b57;</keycap> (Hiragana/Katakana/Romaji) key from USB; the <keycap>&#x534a;&#x89d2;/&#x5168;&#x89d2;</keycap> (Zenkaku/Hankaku) key from USB; the <keycap>&#x3072;&#x3089;&#x30c4;&#x306a;</keycap> (Hiragana) key from USB; the <keycap>&#x30ab;&#x30bf;&#x30ab;&#x30ca;</keycap> (Katakana) key from USB; the <keycap>&#x5909;&#x63db;</keycap> (Henkan) or <keycap>XFER</keycap> key from the 106/109-key PC keyboard; the <keycap>&#x7121;&#x5909;&#x63db;</keycap> (Muhenkan) or <keycap>NFER</keycap> key from the 106/109-key PC keyboard; an unused position; the <keycap>&#xd55c;/&#xc601;</keycap> (Han/Yeong) key from the 103/106-key PC keyboard; the <keycap>&#x5909;&#x63db;</keycap> (Kanji) or <keycap>&#xd55c;&#xc601;</keycap> (Hanja) key, from the 106/109-key or 103/106-key PC keyboards; three unused positions; <keycap>Alternate Erase</keycap>; <keycap>&#x2384;&#160;Compose</keycap>; and <keycap>&#x2423;&#160;Space</keycap>.
</para><note>
Modifier keys that are on this row per ISO 9995 are factored out into a separate modifiers row, so as not to cause ambiguity with the various additional input method keys that can be on this row.
</note><note>
The <keycap>&#x534a;&#x89d2;/&#x5168;&#x89d2;</keycap> (Zenkaku/Hankaku) key from USB is not to be confused with the PC keyboard key at E00, which is a language-variant (<keycap>grave</keycap>) key and a different key with a different identity in the USB specification.
</note><note>
The <keycap>&#x3072;&#x3089;&#x30c4;&#x306a;</keycap> (Hiragana) and <keycap>&#x30ab;&#x30bf;&#x30ab;&#x30ca;</keycap> (Katakana) keys are separate keys in the USB specification, and not to be confused with the <keycap>&#x3072;&#x3089;&#x30c4;&#x306a;/&#x30ab;&#x30bf;&#x30ab;&#x30ca;/&#x30ed;&#x30fc;&#x30de;&#x5b57;</keycap> key in the USB specification; thus all three have separate key identities.
The key with the <keycap>&#x3072;&#x3089;&#x30c4;&#x306a;/&#x30ab;&#x30bf;&#x30ab;&#x30ca;/&#x30ed;&#x30fc;&#x30de;&#x5b57;</keycap> engraving on the 106/109-key PC keyboard is in fact the language-variant key (called <keycap>grave</keycap> in the USB specification) in the "C" row (q.v.).
</note><note>
There is no <keycap>&#x30ed;&#x30fc;&#x30de;&#x5b57;</keycap> (Romaji) key in the USB specification or on the PC keyboard, so there is no map for it; although an extended key message code for it exists, to permit realizers to generate it by some other means.
</note><note>
The <keycap>&#x5909;&#x63db;</keycap> (Kanji) key from the 106/109-key PC keyboard and the <keycap>&#xd55c;&#xc601;</keycap> (Hanja) key from the 103/106-key PC keyboard are considered identical, a single key with only the latter having an identity in the USB specification; no keyboard anywhere having them both.
</note></listitem>
</varlistentry>
<varlistentry>
<term>Cursor/Editing keypad</term>
<listitem><para>
<keycap>&#x21f1;&#160;Home</keycap>; <keycap>&#x2b61;&#160;Up&#160;Arrow</keycap>; <keycap>&#x2397;&#160;Page&#160;Up</keycap>; <keycap>&#x2b60;&#160;Left&#160;Arrow</keycap>; <keycap>&#x2b62;&#160;Right&#160;Arrow</keycap>; <keycap>&#x21f2;&#160;End</keycap>; <keycap>&#x2b63;&#160;Down&#160;Arrow</keycap>; <keycap>&#x2398;&#160;Page&#160;Down</keycap>; <keycap>&#x2380;&#160;Insert</keycap>; <keycap>Delete</keycap>; <keycap>Cut</keycap>; <keycap>Copy</keycap>; <keycap>Paste</keycap>; <keycap>Find</keycap>; <keycap>&#x238c;&#160;Undo</keycap>; and <keycap>Redo</keycap>.
</para><note>
The final 6 keys are found on Sun Microsystems and "Office" keyboards.
</note></listitem>
</varlistentry>
<varlistentry>
<term>Calculator keypad 1</term>
<listitem><para>
<keycap>*&#160;Multiply</keycap>; <keycap>7</keycap>; <keycap>8</keycap>; <keycap>9</keycap>; <keycap>-&#160;Minus</keycap>; <keycap>4</keycap>; <keycap>5</keycap>; <keycap>6</keycap>; <keycap>+&#160;Plus</keycap>; <keycap>1</keycap>; <keycap>2</keycap>; <keycap>3</keycap>; <keycap>0</keycap>; <keycap>.&#160;Decimal&#160;Point</keycap>; <keycap>Enter</keycap>; and <keycap>/&#160;Divide</keycap>.
</para></listitem>
</varlistentry>
<varlistentry>
<term>Calculator keypad 2</term>
<listitem><para>
<keycap>,&#160;Thousands&#160;Separator</keycap> from the Apple Pro JIS and 104/107-key (ABNT2) PC keyboards; <keycap>,&#160;JP&#160;Comma</keycap>; <keycap>=</keycap> from the Apple Pro JIS keyboard; AS/400 <keycap>=</keycap>; <keycap>&#x00b1;&#160;Sign&#160;Change</keycap>; <keycap>(</keycap>; <keycap>)</keycap>; <keycap>{</keycap>; <keycap>}</keycap>; and 7 unused positions.
</para></listitem>
</varlistentry>
<varlistentry>
<term>Function row 1</term>
<listitem><para>
<keycap>F0</keycap> to <keycap>F15</keycap>.
</para><note>
In reality, <keycap>F0</keycap> does not exist and the lowest real function key is <keycap>F1</keycap>.
The <keycap>&#x238b;&#160;Escape</keycap> key is not considered part of this row.
</note></listitem>
</varlistentry>
<varlistentry>
<term>Function row 2</term>
<listitem><para>
<keycap>F16</keycap> to <keycap>F31</keycap>.
</para></listitem>
</varlistentry>
<varlistentry>
<term>Function row 3</term>
<listitem><para>
<keycap>F32</keycap> to <keycap>F47</keycap>.
</para></listitem>
</varlistentry>
<varlistentry>
<term>Function row 4</term>
<listitem><para>
An unused position; Fn-Locked <keycap>F1</keycap> to <keycap>F12</keycap>; and 7 unused positions.
</para><note>
Various PS/2 "Office" keyboards report modified scancodes for the <keycap>F1</keycap> to <keycap>F12</keycap> keys when <keycap>Fn</keycap> lock is on.
PS/2 HID realizers use this part of the keyboard map in order to allow the function keys in that mode to have alternative mappings.
</note></listitem>
</varlistentry>
<varlistentry>
<term>System Commands keypad</term>
<listitem><para>
<keycap>Task&#160;Manager</keycap>; <keycap>&#x23fc;&#160;Power</keycap>; <keycap>&#x23fe;&#160;Sleep</keycap>; <keycap>Wake</keycap>; <keycap>Debug</keycap>; <keycap>Lock</keycap>; <keycap>Logoff</keycap>; <keycap>Logon</keycap>; <keycap>Hibernate</keycap>; <keycap>Next&#160;Task</keycap>; <keycap>Previous&#160;Task</keycap>; <keycap>Select&#160;Task</keycap>; <keycap>Halt&#160;Task</keycap>; and 3 more unused positions.
</para></listitem>
</varlistentry>
<varlistentry>
<term>Application shortcuts keypad 1</term>
<listitem><para>
<keycap>Calculator</keycap>; <keycap>File&#160;Manager</keycap>; <keycap>WWW&#160;Browser</keycap>; <keycap>&#x2302;&#160;Home&#160;Page</keycap>; <keycap>Mail</keycap>; <keycap>Computer</keycap>; <keycap>CLI</keycap>; <keycap>Word&#160;Processor</keycap>; <keycap>Spreadsheet</keycap>; <keycap>My&#160;Computer</keycap>; <keycap>Instant&#160;Messaging</keycap>; <keycap>Media&#160;Player</keycap>; <keycap>My&#160;Pictures</keycap>; <keycap>Text&#160;Editor</keycap>; <keycap>Spell</keycap>; and <keycap>Calendar</keycap>.
</para><note>
These are present on "Office", "Internet", and "Multimedia" keyboards.
In the USB HID specification they are consumer keys.
</note></listitem>
</varlistentry>
<varlistentry>
<term>Application shortcuts keypad 2</term>
<listitem><para>
16 unused positions reserved for future shortcuts.
</para><note>
The USB HID specification defines many more shortcuts as consumer keys.
</note></listitem>
</varlistentry>
<varlistentry>
<term>Application Commands keypad 1</term>
<listitem><para>
<keycap>&#x2bc9;&#160;Popup menu</keycap>; <keycap>&#x23f9;&#160;Stop&#160;Playing</keycap>; <keycap>&#x23ed;&#160;Next&#160;Track</keycap>; <keycap>&#x23ee;&#160;Previous&#160;Track</keycap>; <keycap>&#x23ef;&#160;Play/Pause</keycap>; <keycap>Mute</keycap>; <keycap>Volume&#160;Up</keycap>; <keycap>Volume&#160;Down</keycap>; <keycap>&#x23ea;&#160;Rewind</keycap>; <keycap>&#x23e9;&#160;Fast&#160;Forward</keycap>; <keycap>&#x23cf;&#160;Eject</keycap>; <keycap>&#x23fa;&#160;Record</keycap>; <keycap>Application&#160;Back</keycap>; <keycap>Application&#160;Forward</keycap>; <keycap>Application&#160;Left</keycap>; and <keycap>Application&#160;Right</keycap>.
</para><note>
These are present on "Multimedia" keyboards.
These are primarily media player control keys.
</note></listitem>
</varlistentry>
<varlistentry>
<term>Application Commands keypad 2</term>
<listitem><para>
<keycap>Help</keycap>; <keycap>Pause</keycap>; <keycap>&#x2399;&#160;Print&#160;Screen</keycap>; <keycap>Attention</keycap>; <keycap>Refresh</keycap>; <keycap>New</keycap>; <keycap>Exit</keycap>; <keycap>Save</keycap>; <keycap>Stop/Break</keycap>; <keycap>Search</keycap>; <keycap>Bookmarks</keycap>; <keycap>Stop&#160;Loading</keycap>; <keycap>Execute</keycap>; <keycap>Menu</keycap>; <keycap>Open</keycap>; and <keycap>Close</keycap>.
</para><note>
This is a mixture of long-standing PC/AT command keys (usually located on row "F") and keys found on "Office" and "Internet" keyboards.
</note></listitem>
</varlistentry>
<varlistentry>
<term>Application Commands keypad 3</term>
<listitem><para>
<keycap>Select</keycap>; <keycap>Stop</keycap>; <keycap>Again</keycap>; <keycap>Cancel</keycap>; <keycap>Clear</keycap>; <keycap>Prior</keycap>; <keycap>App&#160;Return</keycap>; <keycap>Separator</keycap>; <keycap>Out</keycap>; <keycap>Oper</keycap>; <keycap>Clear/again</keycap>; <keycap>Properties</keycap>; <keycap>Ex&#160;Sel</keycap>; and 3 unused positions.
</para></listitem>
</varlistentry>
</variablelist>

</refsection>

<refsection><title>Map file entries</title>

<para>
Each 96-octet map entry comprises twenty-four big-endian 32-bit integers.
</para>

<para>
A map entry describes two things: a set of possible actions to be taken when the key is pressed and released, and how to select which action based upon the momentary keyboard modifier state.
A selection class determines how the set of modifiers is reduced to a four-bit action index (giving sixteen possible combinations) by combining modifiers with one another.
</para>

<para>
Keyboard modifiers comprise (in ISO 9995-1 terminology) modifiers for level 2, level 3, and group 2; for caps, num, level2 shift, and level3 shift locks; and for super, alt, and control.
What keys act as these modifiers is of course determined by the keyboard layout: but often the level 2 modifiers are the <keycap>&#x21e7;&#160;Shift</keycap> keys; the level 3 modifier is the right <keycap>&#x2325;&#160;Option</keycap>/<keycap>Closed&#160;Apple</keycap> (Apple keyboards) or <keycap>&#x21ee;&#160;AltGr</keycap> (Windows and IBM PC/AT keyboards) key; the alt modifier is the left <keycap>&#x2325;&#160;Option</keycap>/<keycap>Closed&#160;Apple</keycap> (Apple keyboards) or <keycap>&#x2387;&#160;Alt</keycap> (Windows and IBM PC/AT keyboards) key; and super is the <keycap>&#x2318;&#160;Command</keycap>/<keycap>Open&#160;Apple</keycap> (Apple keyboards), <keycap>Meta</keycap> (Sun keyboards), or <keycap>Windows</keycap> (Windows keyboards) key.
The initial state of all locks is off.
</para>

<para>
The selection class code is first in each entry, and the code values are here designated by their UCS-4 code points.
</para>

<variablelist>
<varlistentry>
<term>'<code>p</code>' (U+00000070, "plain")</term>
<listitem><para>
The keyboard modifier state is entirely ignored and the first action is always chosen.
</para></listitem>
</varlistentry>
<varlistentry>
<term><quote><code>s</code></quote> (U+00000073, "shiftable")</term>
<listitem><para>
When selecting an action, the sense of the level2 modifier state is inverted by the level2 shift lock state, and the sense of the level3 modifier state is inverted by the level3 shift lock state.
This is generally used for non-alphabetic keys that obey shift lock but not caps lock.
</para></listitem>
</varlistentry>
<varlistentry>
<term><quote><code>l</code></quote> (U+0000006C, "semi-shiftable")</term>
<listitem><para>
When selecting an action, the sense of the level2 and level 3 modifier states are taken as they are.
This is generally used for non-alphabetic keys that ignore all locks but obey pressed modifiers.
In particular, this is used for lock keys that involve modifiers being pressed, as otherwise their own locks would affect them.
</para></listitem>
</varlistentry>
<varlistentry>
<term><quote><code>c</code></quote> (U+00000063, "capsable")</term>
<listitem><para>
When selecting an action, the sense of the level2 modifier state is inverted by the OR-combined caps lock and shift lock states.
This is generally used for alphabetic keys that obey caps lock and shift lock.
</para></listitem>
</varlistentry>
<varlistentry>
<term><quote><code>n</code></quote> (U+0000006E, "numable")</term>
<listitem><para>
When selecting an action, the sense of the level2 modifier state is inverted by the OR-combined num lock and shift lock states.
This is generally used for auxiliary keys that obey num lock and shift lock.
</para></listitem>
</varlistentry>
<varlistentry>
<term><quote><code>f</code></quote> (U+00000066, "funcable")</term>
<listitem><para>
When selecting an action, the sense of the level2 modifier state is inverted by the shift lock state, and the level3 modifier state is replaced by the alt state.
This is generally used for function block keys that obey shift lock but not caps lock.
</para></listitem>
</varlistentry>
</variablelist>

<para>
The next seven 32-bit numbers are reserved, and should be set to zero.
The remaining sixteen 32-bit numbers are the actions, chosen according to the selection class.
These denote the actions for various combinations of modifiers: none, level2, control, control+level2, level3, level2+level3, control+level3, control+level2+level3, group2, group2+level2, group2+control, group2+control+level2, group2+level3, group2+level2+level3, group2+control+level3, and group2+control+level2+level3, with inversions and replacements as aforementioned.
</para>

</refsection>

<refsection><title>Map file actions</title>

<para>
An individual action in a map entry is a big-endian 32-bit integer, which comprises three or four sub-fields.
</para>

<para>
The most significant byte denotes the action type and the interpretation of the remainder of the action.
(These are, intentionally, similar to the input protocol used by user-space virtual terminals (c.f. <citerefentry><refentrytitle>user-vt</refentrytitle><manvolnum>5</manvolnum></citerefentry>), aimed at making debugging and trace analysis simpler.
They are two distinct and separate protocols, however.)
</para>

<variablelist>
<varlistentry>
<term><code>0x00<replaceable>xxxxxx</replaceable></code></term>
<listitem><para>
No-operation,
Take no action.
This is used for keys that have no action in the key map.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>0x01<replaceable>nnnnnn</replaceable></code></term>
<listitem><para>
UCS-3 key.
On press or autorepeat, a Unicode character message for the code point <code>U+00<replaceable>nnnnnn</replaceable></code> is sent to the input FIFO.
If the alt modifier is in effect, a Unicode accelerator message is sent instead.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>0x03<replaceable>nnnn</replaceable><replaceable>cc</replaceable></code></term>
<listitem><para>
Modifier key.
Modifiers do not autorepeat.
On press or release, the modifier key <code><replaceable>nnnn</replaceable></code> is enacted against the current keyboard modifier state according to the <code><replaceable>cc</replaceable></code> command.
Commands are:
</para>
<variablelist>
<varlistentry>
<term><code>0x01</code></term>
<listitem><para>
Momentary.
The modifier is on when the key is pressed, and off when the key is released.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>0x02</code></term>
<listitem><para>
Latching.
Pressing the key latches the modifier on until a non-modifier key is pressed.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>0x03</code></term>
<listitem><para>
Locking.
Pressing the key locks the modifier on; releasing and pressing it again locks
it back off.
</para></listitem>
</varlistentry>
</variablelist>
</listitem>
</varlistentry>
<varlistentry>
<term><code>0x0A<replaceable>nnnn</replaceable><replaceable>zz</replaceable></code></term>
<listitem><para>
Session selection key.
On press or autorepeat, a session selection message for the session number <code><replaceable>nnnn</replaceable></code> is sent to the input FIFO.
<code><replaceable>zz</replaceable></code> is ignored and should be set to zero for upwards compatibility.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>0x0C<replaceable>nnnn</replaceable><replaceable>zz</replaceable></code></term>
<listitem><para>
Consumer key.
On press or autorepeat, a consumer key message for the consumer key number <code><replaceable>nnnn</replaceable></code> is sent to the input FIFO.
<code><replaceable>zz</replaceable></code> is ignored and should be set to zero for upwards compatibility.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>0x0E<replaceable>nnnn</replaceable><replaceable>zz</replaceable></code></term>
<listitem><para>
Extended key.
On press or autorepeat, an extended key message for the extended key number <code><replaceable>nnnn</replaceable></code> is sent to the input FIFO.
<code><replaceable>zz</replaceable></code> is ignored and should be set to zero for upwards compatibility.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>0x1E<replaceable>nnnn</replaceable><replaceable>zz</replaceable></code></term>
<listitem><para>
Unshiftable extended key.
On press or autorepeat, an extended key message for the extended key number <code><replaceable>nnnn</replaceable></code> is sent to the input FIFO.
<code><replaceable>zz</replaceable></code> is ignored and should be set to zero for upwards compatibility.
The accompanying keyboard modifier state does not incorporate the level 2 modifier, which will never be seen by the terminal emulator or processes connected to the terminal.
This is used for keyboard layouts where shift inverts the sense of numlock on calculator keys, and that shift is not considered to further modify the key or be visible to applications.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>0x0F<replaceable>nnnn</replaceable><replaceable>zz</replaceable></code></term>
<listitem><para>
Function key.
On press or autorepeat, a function key message for the function key number <code><replaceable>nnnn</replaceable></code> is sent.
<code><replaceable>zz</replaceable></code> is ignored and should be set to zero for upwards compatibility.
This is used for keyboard layouts where the function key block has a large number of actual keys.
The terminal emulator, and processes connected to the terminal, will see function keys with modifiers.
</para></listitem>
</varlistentry>
<varlistentry>
<term><code>0x1F<replaceable>nnnn</replaceable><replaceable>zz</replaceable></code></term>
<listitem><para>
Unmodifiable function key.
On press or autorepeat, a function key message for the function key number <code><replaceable>nnnn</replaceable></code> is sent.
<code><replaceable>zz</replaceable></code> is ignored and should be set to zero for upwards compatibility.
The accompanying keyboard modifier state does not incorporate the level or group modifiers, which will never be seen by the terminal emulator or processes connected to the terminal.
This is used for keyboard layouts where the function key block has a small number of actual keys and the level+group modifiers are used "locally" (within the realizer) to simulate a larger key block.
</para></listitem>
</varlistentry>
</variablelist>

</refsection>

<refsection><title>Function keys</title>

<para>
It is (of course) the keyboard map that handles function key mapping.
The function key entries in the matrix represent physical function keys, not composed keys created by combining modifiers with function keys.
Those are, after all, represented by the individual actions in each function key's entry.
</para>

<para>
A keyboard map defines what input messages a combination of modifiers and a function key generates.
It will usually be one of:
</para>
<itemizedlist>
<listitem><para>
a function key (if the map maps physical function keys straight to terminal emulator function keys, passing the modifier state through to the terminal emulator);
</para></listitem>
<listitem><para>
an unmodified function key (if the map uses modifiers to extend the function key set, and thus does not pass the modifier state that it has already consumed through to the terminal emulator); or
</para></listitem>
<listitem><para>
an extended key.
</para></listitem>
</itemizedlist>

<para>
See <citerefentry><refentrytitle>console-terminal-emulator</refentrytitle><manvolnum>1</manvolnum></citerefentry> for why usually keyboard maps map function keys <keycap>F1</keycap> to <keycap>F5</keycap> to the cursor keypad extended keys PAD_F1 to PAD_F5 in input messages, and not to the input messages for function keys 1 to 5.
</para>

</refsection>

<refsection><title>Example keyboard map entries</title>

<para>
Keyboard maps are tailored, of course, to country, layout (QWERTY, AZERTY, Dvorak, Maltron, and so forth), and the physical layout of the keyboard (104 keys, 109 keys, 124 keys, and so forth).
Here are some example keymap entries:
</para>
<variablelist>
<varlistentry>
<term>
<code>0x00000063</code>,
<code>0x00000000</code>,
<code>0x00000000</code>,
<code>0x00000000</code>,
<code>0x00000000</code>,
<code>0x00000000</code>,
<code>0x00000000</code>,
<code>0x00000000</code>,
<code>0x01000073</code>,
<code>0x01000053</code>,
<code>0x01000013</code>,
<code>0x01000013</code>,
<code>0x010000DF</code>,
<code>0x010000A7</code>,
<code>0x01000013</code>,
<code>0x01000013</code>.
<code>0x01000073</code>,
<code>0x01000053</code>,
<code>0x01000013</code>,
<code>0x01000013</code>,
<code>0x010000DF</code>,
<code>0x010000A7</code>,
<code>0x01000013</code>,
<code>0x01000013</code>.
</term>
<listitem><para>
'<code>S</code>' on the U.S. International IBM PC/AT keyboard, QWERTY layout.
It varies according to caps lock, and produces '<code>&#xdf;</code>' and '<code>&#xa7;</code>' with the level 3 modifier.
The control modifier always produces <code>DC3</code> (U+0013).
</para></listitem>
</varlistentry>
<varlistentry>
<term>
<code>0x00000066</code>,
<code>0x00000000</code>,
<code>0x00000000</code>,
<code>0x00000000</code>,
<code>0x00000000</code>,
<code>0x00000000</code>,
<code>0x00000000</code>,
<code>0x00000000</code>,
<code>0x0E0F0100</code>,
<code>0x1F000D00</code>,
<code>0x1F001900</code>,
<code>0x1F002500</code>,
<code>0x0A000100</code>,
<code>0x0A000D00</code>,
<code>0x0A001900</code>,
<code>0x0A002500</code>.
<code>0x0E0F0100</code>,
<code>0x1F000D00</code>,
<code>0x1F001900</code>,
<code>0x1F002500</code>,
<code>0x0A000100</code>,
<code>0x0A000D00</code>,
<code>0x0A001900</code>,
<code>0x0A002500</code>.
</term>
<listitem><para>
F1 on the U.S. International IBM PC/AT keyboard, QWERTY layout.
It ignores level 3, varying according to the level 2, alt, and control modifiers to produce either PAD_F1, F13, F25, and F37 or session switch commands
for sessions 1, 13, 25, and 37.
</para></listitem>
</varlistentry>
</variablelist>

</refsection>

</refsection>

<refsection><title>Author</title>
<para><author><personname><firstname>Jonathan</firstname> <surname>de Boyne Pollard</surname></personname></author></para>
</refsection>

</refentry>
