31 March 2003

Appendix A: Key identifiers for keyboard events.

Editor:
Philippe Le Hégaret, W3C

A.1: Introduction

Each keyboard event references a key using a DOMString key identifier. The set contained in this appendix is based on the sets of keycodes from:

While implementations are recommended to use the most relevant identifier for a key independently of the platform or keyboard layout mappings, DOM applications should not make assumption on the ability of keyboard devices to generate them. When using keyboard events, "consider using numbers and function keys (F4, F5, and so on) instead of letters in shortcut-key combinaisons" ([DWW95]) given that most keyboard layouts will provide keys for those.

"U+000000", "U+000001", ..., "U+FFFFFF" are Unicode based key identifiers ([Unicode 3.0]). When a key cannot be mapped to Unicode, a specific identifier is used (see also Guidelines for defining key identifiers). In any case, no assumption should be made between the sequence of keyboard events and the text events. The following three examples illustrated the concept of keyboard layout mappings and its relation with keyboard events.

The keystroke "U+000051" (Latin Capital Letter Q key) will produce (on a PC/AT US keyboard using a US keyboard layout mapping and without any modifier activated) the Unicode character q (Latin Small Letter Q):

  1. {"http://www.w3.org/2001/xml-events", "keydown"}: "U+000051" (Latin Capital Letter Q key)
  2. {"http://www.w3.org/2001/xml-events", "textInput"}: "q"
  3. {"http://www.w3.org/2001/xml-events", "keyup"}: "U+000051" (Latin Capital Letter Q key)

If the keyboard layout mapping is switched to a french mapping, pressing the same key will produce:

  1. {"http://www.w3.org/2001/xml-events", "keydown"}: "U+000041"
  2. {"http://www.w3.org/2001/xml-events", "textInput"}: "a"
  3. {"http://www.w3.org/2001/xml-events", "keyup"}: "U+000041"

If the keyboard layout mapping is switched to a serbian (cyrillic) mapping, pressing the same key will produce:

  1. {"http://www.w3.org/2001/xml-events", "keydown"}: "U+000409"
  2. {"http://www.w3.org/2001/xml-events", "textInput"}: "љ"
  3. {"http://www.w3.org/2001/xml-events", "keyup"}: "U+000409"

Note: The order between the text event and keyboard events may differ depending on the keyboard devices.

A.1.1: Modifier keys

Keyboard input use modifier keys to change the normal behavior of a key. The KeyboardEvent interface provides specific attributes for them: KeyboardEvent.ctrlKey, KeyboardEvent.shiftKey, KeyboardEvent.altKey, KeyboardEvent.metaKey, and KeyboardEvent.altGraphKey.

The following example describes a possible sequence of keys to generate the Unicode character Q (Latin Capital Letter Q) on a PC/AT US keyboard using a US mapping:

  1. {"http://www.w3.org/2001/xml-events", "keydown"}: "Shift", shiftKey
  2. {"http://www.w3.org/2001/xml-events", "keydown"}: "U+000051" (Latin Capital Letter Q key), shiftKey
  3. {"http://www.w3.org/2001/xml-events", "textInput"}: "Q"
  4. {"http://www.w3.org/2001/xml-events", "keyup"}: "U+000051" (Latin Capital Letter Q key), shiftKey
  5. {"http://www.w3.org/2001/xml-events", "keyup"}: "Shift"

The following example describes a possible sequence of keys that does not generate a Unicode character (using the same configuration):

  1. {"http://www.w3.org/2001/xml-events", "keydown"}: "Control", ctrlKey
  2. {"http://www.w3.org/2001/xml-events", "keydown"}: "U+000056" (Latin Capital Letter V key), ctrlKey
  3. {"http://www.w3.org/2001/xml-events", "keyup"}: "U+000056" (Latin Capital Letter V key), ctrlKey
  4. {"http://www.w3.org/2001/xml-events", "keyup"}: "Control"

A.1.2: Dead keys

Keyboard input use dead keys for the input of composed character sequences. Unlike the handwriting sequence, in which users type the base character first, keyboard input require to enter a special state when a dead key is pressed and emit the character(s) only when one of a limited number of "legal" base character is entered.

The dead keys are represented in the key identifiers set using combining diacritical marks. The sequence of keystrokes "U+000302" (Combining Circumflex Accent key) and "U+000045" (Latin Capital Letter E key) will likely produce (on a PC/AT french keyboard using a french mapping and without any modifier activated) the Unicode character é (Latin Small Letter E With Acute) or the composed Unicode character sequence e (Latin Small Letter E) and 000302 (Combining Circumflex Accent). In practice, french keyboard input will generate the Unicode character é instead of the composed Unicode character sequence, as shown in the following example:

  1. {"http://www.w3.org/2001/xml-events", "keydown"}: "U+000302" (Combining Circumflex Accent key)
  2. {"http://www.w3.org/2001/xml-events", "keyup"}: "U+000302" (Combining Circumflex Accent key)
  3. {"http://www.w3.org/2001/xml-events", "keydown"}: "U+000045" (Latin Capital Letter E key)
  4. {"http://www.w3.org/2001/xml-events", "textInput"}: "é"
  5. {"http://www.w3.org/2001/xml-events", "keyup"}: "U+000045" (Latin Capital Letter E key)

A.1.3: Input Method Editors

Also known as front end processor, an input method editor (IME) is an application that performs the conversion between keystrokes and ideographs or other characters, usually by user-guided dictionary lookup.

The IMEs function keys are not represented in this set. As an example, receiving an keydown for the "Accept" key identifier does not necessarily implies that the text currently selected in the IME is being accepted. It only indicates that a keystroke happened, disconnected from the IME Accept functionality. Depending on the device in use, the IME Accept functionality can be obtain using the Accept key or the Return key. Keyboard events cannot be used to determine the current state of the input method editor.

Keyboard events correspond to the events generated by the input device after the keyboard layout mapping but before the processing of the input method editor.

The following example describes a possible sequence of keys to generate the Unicode character し (Hiragana Letter SI) using Japanese input methods. This assumes that the input method editor is activated and in the Japanese-Romaji input mode. The keys "Convert" and "Accept" may be replaced by others depending on the input device in use and the configuration of the IME, e.g. it could be respectively "U+000020" (Space key) and "Enter".

  1. {"http://www.w3.org/2001/xml-events", "keydown"}: "U+000053" (Latin Capital Letter S key)
  2. {"http://www.w3.org/2001/xml-events", "keyup"}: "U+000053" (Latin Capital Letter S key)
  3. {"http://www.w3.org/2001/xml-events", "keydown"}: "U+000049" (Latin Capital Letter I key)
  4. {"http://www.w3.org/2001/xml-events", "keyup"}: "U+000049" (Latin Capital Letter I key)
  5. {"http://www.w3.org/2001/xml-events", "keydown"}: "Convert"
  6. {"http://www.w3.org/2001/xml-events", "keyup"}: "Convert"
  7. {"http://www.w3.org/2001/xml-events", "keydown"}: "Accept"
  8. {"http://www.w3.org/2001/xml-events", "textInput"}: "し"
  9. {"http://www.w3.org/2001/xml-events", "keyup"}: "Accept"

Note: This specification does not provide a representation of the input method editor (IME) events, e.g. representing the input context.

A.1.4: Guidelines for defining key identifiers

Note: This section is informative.

The list of key identifiers contained in this appendix is not exhaustive and input devices may have to define their own key identifiers. Here is a algorithm to determine which key identifier to use:

  1. Determine a representation for the key by looking at the keyboard layout mapping in use (and not the keyboard device in use). This representation should be unique, as human friendly as possible, platform independent, and consistent. For example, on PC/AT US keyboards with a US mapping, the 'Q' key is mapped to the key identifier "U+000051" (Latin Capital Letter Q key), the '1/!' key is mapped to the key identifier "U+000031" (Digit One key), the key '`/~' is mapped to the key identifier "U+000060" (Grave Accent key), and the 'Enter' key is mapped to the key identifier "Enter".
  2. Find an appropriate mapping in the Unicode character set. There might not always be an appropriate and obvious mapping: the Unicode set contains characters and symbols, the key might generate different characters depending on the operating system, ... In general, unless the representation of the key can be mapped to a unique Unicode character, it is better to create a new one.
  3. If no appropriate mapping was found, create an key identifier as human friendly as possible. As an example, the Enter key is mapped to the key identifier "Enter" and not to "U+00000A" (Line Feed), given that this key generates the character 00000A on Unix operating systems and the characters 00000D and 00000A on Windows operating systems.

A.2: Key identifiers set

Note: The keycodes Multiply, Add, Substract, Decimal, Separator, Divide, NumPad0, NumPad1, NumPad2, NumPad3, NumPad4, NumPad5, NumPad6, NumPad7, NumPad8, and NumPad9 are not part of this set. Use KeyBoard.keyLocation to know if a key originated from the numeric keypad.

"Accept"
The Accept (Commit) key.
"Again"
The Again key.
"AllCandidates"
The All Candidates key.
"Alphanumeric"
The Alphanumeric key.
"Alt"
The Alt (Menu) key.
"AltGraph"
The Alt-Graph key.
"Apps"
The Application key.
"Attn"
The ATTN key.
"BrowserBack"
The Browser Back key.
"BrowserFavorites"
The Browser Favorites key.
"BrowserForward"
The Browser Forward key.
"BrowserHome"
The Browser Home key.
"BrowserRefresh"
The Browser Refresh key.
"BrowserSearch"
The Browser Search key.
"BrowserStop"
The Browser Stop key.
"CapsLock"
The Caps Lock (Capital) key.
"Clear"
The Clear key.
"CodeInput"
The Code Input key.
"Compose"
The Compose key.
"Control"
The Control (Ctrl) key.
"Crsel"
The Crsel key.
"Convert"
The Convert key.
"Copy"
The Copy key.
"Cut"
The Cut key.
"Down"
The Down Arrow key.
"End"
The End key.
"Enter"
The Enter key.

Note: This key identifier is also used for the Return (Macintosh numpad) key.

"EraseEof"
The Erase EOF key.
"Execute"
The Execute key.
"Exsel"
The Exsel key.
"F1"
The F1 key.
"F2"
The F2 key.
"F3"
The F3 key.
"F4"
The F4 key.
"F5"
The F5 key.
"F6"
The F6 key.
"F7"
The F7 key.
"F8"
The F8 key.
"F9"
The F9 key.
"F10"
The F10 key.
"F11"
The F11 key.
"F12"
The F12 key.
"F13"
The F13 key.
"F14"
The F14 key.
"F15"
The F15 key.
"F16"
The F16 key.
"F17"
The F17 key.
"F18"
The F18 key.
"F19"
The F19 key.
"F20"
The F20 key.
"F21"
The F21 key.
"F22"
The F22 key.
"F23"
The F23 key.
"F24"
The F24 key.
"FinalMode"
The Final Mode (Final) key used on some asian keyboards.
"Find"
The Find key.
"FullWidth"
The Full-Width Characters key.
"HalfWidth"
The Half-Width Characters key.
"HangulMode"
The Hangul (Korean characters) Mode key.
"HanjaMode"
The Hanja (Korean characters) Mode key.
"Help"
The Help key.
"Hiragana"
The Hiragana (Japanese Kana characters) key.
"Home"
The Home key.
"Insert"
The Insert (Ins) key.
"JapaneseHiragana"
The Japanese-Hiragana key.
"JapaneseKatakana"
The Japanese-Katakana key.
"JapaneseRomaji"
The Japanese-Romaji key.
"JunjaMode"
The Junja Mode key.
"KanaMode"
The Kana Mode (Kana Lock) key.
"KanjiMode"
The Kanji (Japanese name for ideographic characters of Chinese origin) Mode key.
"Katakana"
The Katakana (Japanese Kana characters) key.
"LaunchApplication1"
The Start Application One key.
"LaunchApplication2"
The Start Application Two key.
"LaunchMail"
The Start Mail key.
"Left"
The Left Arrow key.
"Meta"
The Meta key.
"MediaNextTrack"
The Media Next Track key.
"MediaPlayPause"
The Media Play Pause key.
"MediaPreviousTrack"
The Media Previous Track key.
"MediaStop"
The Media Stok key.
"ModeChange"
The Mode Change key.
"Nonconvert"
The Nonconvert (Don't Convert) key.
"NumLock"
The Num Lock key.
"PageDown"
The Page Down (Next) key.
"PageUp"
The Page Up key.
"Paste"
The Paste key.
"Pause"
The Pause key.
"Play"
The Play key.
"PreviousCandidate"
The Previous Candidate function key.
"PrintScreen"
The Print Screen (PrintScrn, SnapShot) key.
"Process"
The Process key.
"Props"
The Props key.
"Right"
The Right Arrow key.
"RomanCharacters"
The Roman Characters function key.
"Scroll"
The Scroll Lock key.
"Select"
The Select key.
"SelectMedia"
The Select Media key.
"Shift"
The Shift key.
"Stop"
The Stop key.
"Up"
The Up Arrow key.
"Undo"
The Undo key.
"VolumeDown"
The Volume Down key.
"VolumeMute"
The Volume Mute key.
"VolumeUp"
The Volume Up key.
"Win"
The Windows Logo key.
"Zoom"
The Zoom key.
"U+000008"
The Backspace (Back) key.
"U+000009"
The Horizontal Tabulation (Tab) key.
"U+000018"
The Cancel key.
"U+00001B"
The Escape (Esc) key.
"U+000020"
The Space (Spacebar) key.
"U+000021"
The Exclamation Mark (Factorial, Bang) key (!).
"U+000022"
The Quotation Mark (Quote Double) key (").
"U+000023"
The Number Sign (Pound Sign, Hash, Crosshatch, Octothorpe) key (#).
"U+000024"
The Dollar Sign (milreis, escudo) key ($).
"U+000026"
The Ampersand key (&).
"U+000027"
The Apostrophe (Apostrophe-Quote, APL Quote) key (').
"U+000028"
The Left Parenthesis (Opening Parenthesis) key (().
"U+000029"
The Right Parenthesis (Closing Parenthesis) key ()).
"U+00002A"
The Asterix (Star) key (*).
"U+00002B"
The Plus Sign (Plus) key (+).
"U+00002C"
The Comma (decimal separator) sign key (,).
"U+00002D"
The Hyphen-minus (hyphen or minus sign) key (-).
"U+00002E"
The Full Stop (period, dot, decimal point) key (.).
"U+00002F"
The Solidus (slash, virgule, shilling) key (/).
"U+000030"
The Digit Zero key (0).
"U+000031"
The Digit One key (1).
"U+000032"
The Digit Two key (2).
"U+000033"
The Digit Three key (3).
"U+000034"
The Digit Four key (4).
"U+000035"
The Digit Five key (5).
"U+000036"
The Digit Six key (6).
"U+000037"
The Digit Seven key (7).
"U+000038"
The Digit Eight key (8).
"U+000039"
The Digit Nine key (9).
"U+00003A"
The Colon key (:).
"U+00003B"
The Semicolon key (;).
"U+00003C"
The Less-Than Sign key (<).
"U+00003D"
The Equals Sign key (=).
"U+00003E"
The Greater-Than Sign key (>).
"U+00003F"
The Question Mark key (?).
"U+000040"
The Commercial At (@) key.
"U+000041"
The Latin Capital Letter A key (A).
"U+000042"
The Latin Capital Letter B key (B).
"U+000043"
The Latin Capital Letter C key (C).
"U+000044"
The Latin Capital Letter D key (D).
"U+000045"
The Latin Capital Letter E key (E).
"U+000046"
The Latin Capital Letter F key (F).
"U+000047"
The Latin Capital Letter G key (G).
"U+000048"
The Latin Capital Letter H key (H).
"U+000049"
The Latin Capital Letter I key (I).
"U+00004A"
The Latin Capital Letter J key (J).
"U+00004B"
The Latin Capital Letter K key (K).
"U+00004C"
The Latin Capital Letter L key (L).
"U+00004D"
The Latin Capital Letter M key (M).
"U+00004E"
The Latin Capital Letter N key (N).
"U+00004F"
The Latin Capital Letter O key (O).
"U+000050"
The Latin Capital Letter P key (P).
"U+000051"
The Latin Capital Letter Q key (Q).
"U+000052"
The Latin Capital Letter R key (R).
"U+000053"
The Latin Capital Letter S key (S).
"U+000054"
The Latin Capital Letter T key (T).
"U+000055"
The Latin Capital Letter U key (U).
"U+000056"
The Latin Capital Letter V key (V).
"U+000057"
The Latin Capital Letter W key (W).
"U+000058"
The Latin Capital Letter X key (X).
"U+000059"
The Latin Capital Letter Y key (Y).
"U+00005A"
The Latin Capital Letter Z key (Z).
"U+00005B"
The Left Square Bracket (Opening Square Bracket) key ([).
"U+00005C"
The Reverse Solidus (Backslash) key (\).
"U+00005D"
The Right Square Bracket (Closing Square Bracket) key (]).
"U+00005E"
The Circumflex Accent key (^).
"U+00005F"
The Low Sign (Spacing Underscore, Underscore) key (_).
"U+000060"
The Grave Accent (Back Quote) key (`).
"U+00007B"
The Left Curly Bracket (Opening Curly Bracket, Opening Brace, Brace Left) key ({).
"U+00007C"
The Vertical Line (Vertical Bar, Pipe) key (|).
"U+00007D"
The Right Curly Bracket (Closing Curly Bracket, Closing Brace, Brace Right) key (}).
"U+00007F"
The Delete (Del) Key.
"U+0000A1"
The Inverted Exclamation Mark key (¡).
"U+000300"
The Combining Grave Accent (Greek Varia, Dead Grave) key.
"U+000301"
The Combining Acute Accent (Stress Mark, Greek Oxia, Tonos, Dead Eacute) key.
"U+000302"
The Combining Circumflex Accent (Hat, Dead Circumflex) key.
"U+000303"
The Combining Tilde (Dead Tilde) key.
"U+000304"
The Combining Macron (Long, Dead Macron) key.
"U+000306"
The Combining Breve (Short, Dead Breve) key.
"U+000307"
The Combining Dot Above (Derivative, Dead Above Dot) key.
"U+000308"
The Combining Diaeresis (Double Dot Abode, Umlaut, Greek Dialytika, Double Derivative, Dead Diaeresis) key.
"U+00030A"
The Combining Ring Above (Dead Above Ring) key.
"U+00030B"
The Combining Double Acute Accent (Dead Doubleacute) key.
"U+00030C"
The Combining Caron (Hacek, V Above, Dead Caron) key.
"U+000327"
The Combining Cedilla (Dead Cedilla) key.
"U+000328"
The Combining Ogonek (Nasal Hook, Dead Ogonek) key.
"U+000345"
The Combining Greek Ypogegrammeni (Greek Non-Spacing Iota Below, Iota Subscript, Dead Iota) key.
"U+0020AC"
The Euro Currency Sign key (€).
"U+003099"
The Combining Katakana-Hiragana Voiced Sound Mark (Dead Voiced Sound) key.
"U+00309A"
The Combining Katakana-Hiragana Semi-Voiced Sound Mark (Dead Semivoiced Sound) key.