Copyright © 2015 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and document use rules apply.
This specification defines the values for the
KeyboardEvent.code
attribute, which is defined as part of the
UI Events Specification [UIEvents].
The code
value contains information about the key event that
can use used identify the physical key being pressed by the user.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
Implementers should be aware that this document is not stable. Implementers who are not taking part in the discussions are likely to find the specification changing out from under them in incompatible ways. Vendors interested in implementing this document before it eventually reaches the Candidate Recommendation stage should join the aforementioned mailing lists and take part in the discussions.
This document was published by the Web Applications Working Group as a Working Draft. This document is intended to become a W3C Recommendation. If you wish to make comments regarding this document, please send them to www-dom@w3.org (subscribe, archives). All comments are welcome.
Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This document is governed by the 1 August 2014 W3C Process Document.
This section is informative
Alphanumeric keyboards are the most common way for users to generate keyboard events. This section provides an overview of standard keyboards and their physical layouts.
This section describes the physical layouts found on commonly available keyboards.
When discussing keyboard layouts, it is convenient to divide the standard keyboard into distinct sections and to label each row.
These keyboard sections are:
To make it easier to identify keys, the rows on the keyboard are named starting with "A" for the bottom row up to "E" for the top row. The row of keys in the Function section are considered to be in row "K". These row names are consistent with those given in the ISO/IEC 9995-1 specification.
Note that many keyboards (both modern and legacy) have extra keys that do not fit neatly into the above sections. Some of these keys are covered in the Media Keys section.
The standard "101" keyboard (commonly referred to as the "US layout") is the only layout that uses the 'Backslash'
code.
All the other layouts omit this key and expand the 'Enter'
key to occupy
two-rows.
Modern standard "101"-layout keyboards actually contain 104 keys: 61 keys in the alphanumeric section
and 43 keys in the numpad, control pad, arrow pad and function sections.
The "101" name for this keyboard layout dates to the time when this standard keyboard did in fact contain
101 keys. The two 'OS'
keys,
and the 'Menu'
key were
added later to bring the total to 104 keys.
The alternate "101" keyboard removes the 'Backslash'
key to create a
large 'Enter'
key and shrinks the 'Backspace'
key to make room for the 'IntlYen'
key (The 'IntlYen'
name comes from the
Japanese layout — in the Russian layout shown above this key maps to a '\'
.
Modern alternate "101"-layout keyboards contain 104 keys: 61 keys in the alphanumeric section and 43 keys in the numpad, control pad, arrow pad and function sections.
The standard "102" keyboard is common throughout Europe and adds two keys that don't exist on the
"101" layouts:
The 'IntlBackslash'
key next to the left shift key,
and the 'IntlHash'
key which is partially tucked under the
'Enter'
key.
Modern "102"-layout keyboards contain 105 keys: 62 keys in the alphanumeric section and 43 keys in the numpad, control pad, arrow pad and function sections.
The Korean "103" keyboard is based on the alternate 101 layout and adds two additional keys
(one on each side of the spacebar) to handle Korean-specific input modes.
These keys are
'Hanja'
(labelled 한자
hanja) and
'HangulMode'
(labelled 한/영
han/yeong).
Modern "103"-layout keyboards contain 106 keys: 63 keys in the alphanumeric section and 43 keys in the numpad, control pad, arrow pad and function sections.
The "104" layout used in Brazil adds 4 new keys: the two non-US keys from the "102" layout
('IntlHash'
and 'IntlBackslash'
)
plus the 'IntlRo'
key (next to the right shift
key) and an extra key on the numeric keypad. This new keypad key is called
'KeypadComma'
because it represents the thousands separator. On the
Brazilian key layout, this key has a keycap of .
and the 'KeypadPeriod'
key has a keycap of ,
.
Modern "104"-layout keyboards contain 107 keys: 63 keys in the alphanumeric section and 44 keys in the numpad, control pad, arrow pad and function sections. Some Brazilian keyboards lack the extra keypad key and have only 106 keys.
The Japanese "106" keyboard layout adds 3 new keys:
'IntlYen'
,
'IntlHash'
and
'IntlRo'
.
It also shrinks the 'Space'
key to make room for 3 input mode keys:
'NonConvert'
(labelled 無変換
muhenkan),
'Convert'
(labelled 変換
henkan),
'KanaMode'
(labelled カタカナ/ひらがな/ローマ字
katakana/hiragana/romaji).
Modern "106"-layout keyboards contain 109 keys: 66 keys in the alphanumeric section and 43 keys in the numpad, control pad, arrow pad and function sections.
In general, Apple keyboards follow the same layout as PC keyboards, but there are some differences as noted in the following figure.
In this figure, the green keys are those that have been moved to a new location while the blue keys indicate keys that have been added.
The limited space available on laptop keyboards often means that the physical key layout needs to be adjusted to fit all the required keys. The writing system keys in the Alphanumeric section tend to remain intact, but the other keyboard sections are usually combined with other keys or removed altogether.
In this Apple laptop keyboard, the right control key has been removed to make room for half-height
arrow keys and a 'Fn'
key is added on the left.
PC laptop keyboards vary considerably, but this sample keyboard demonstrates some commonly found aspects. The control pad keys are added along the right-hand side with the arrow keys tucked in along the bottom. The right shift key is often shrunk to make room for the up arrow key and the right OS key is typically removed altogether.
In the case where a content author wishes to rely on the mechanical layout of a mobile keypad, this specification suggests the keyboard configuration specified
in ISO/IEC 9995-8:2006 [ISO9995-8], which defines a numeric keypad layout and secondary assignment
of Unicode characters in the range '\u0061'
..'\u007A'
to the number keys 2
through 9
, as a common layout appropriate to some
international uses.
This keypad layout, and in particular the distribution of letters is for English devices, and will not match the keypads or configurations of many users. Content authors cannot rely upon any particular configuration, and are expected to create content in an internationalized and localizable manner.
Many keyboards contain special keys to control media functions. Increasingly, many media devices, especially televisions, are Web-enabled. Hybrid keyboard/remote-control devices are becoming more common. To meet the needs of these hybrid Web/media devices, this specification defines keys that are common as remote control buttons, in addition to traditional keyboard keys.
Because of the smaller form factor, keys (or buttons) on a remote control will often be modal, with one key performing different functions based on the context of the on-screen content. Additionally, many keys serve as toggles, to change back and forth between two or more states (see toggling keys). These remote control buttons typically do not have modifier states so each button is assigned a single function (like "Play", "Pause", "Up", "Menu" or "Exit").
Virtual keyboards are software-based sets of keys, in a variety of different arrangements, commonly found on touch-screen devices. They are often modal, with the ability to switch between different dynamic sets of keys, such as alphabetic, numeric, or symbolic keys. Because of the lack of physical constraints, these keyboards MAY present the widest range of characters, including emoticons and other symbols, and MAY have keys not represented by Unicode [Unicode] or by the key values [DOM-Level-3-Events-key]. Wherever possible, however, virtual keyboards SHOULD produce the normal range of keyboard events and values, for ease of authoring and compatibility with existing content.
Chording keyboards, also know as chorded keysets or chord keyboards, are key input devices which produce values by pressing several keys in combination or sequence, normally to simulate a full range of characters or commands on a reduced set of keys, often for single-handed use. A chording keyboard MAY have additional mode keys to switch between key values, and the number and type of keys pressed to produce a key value will vary, but the final key values produced by such keyboards SHOULD match the range of key values described in this specification.
For these and other alternative modal keyboards, the key values
'Alphanumeric'
,
'CapsLock'
,
'NumLock'
,
and
'SymbolLock'
are RECOMMENDED for the keys which switch between different modes.
code
Value TablesThis section defines a list of code
values which implementations MUST support.
This section describes the various keyboard sections in more detail and defines the code
values that should be used for each key.
The Alphanumeric section keys fall into two general categories: "writing system" keys whose meaning changes based on the current keyboard layout, and "functional" keys which are (mostly) the same for all layouts.
The "writing system" keys are those that change meaning based on the current keyboard layout.
This figure shows a hypothetical keyboard that combines all the writing system keys (shown in blue and green) found on the various keyboards. Blue keys are present on all standard keyboards while green keys are only available on some keyboards.
The name shown on each key is the code
assigned to that key.
Wherever possible, the code
names are based on the name for the US key
in that position (i.e., they are based on the US keyboard layout). For keys that don't
exist on the US keyboard, names from the UK or Japanese layouts are used instead.
Code Value | USB Usage ID Page 0x07 (Informative) | Notes (Informative) |
---|---|---|
'Backquote' |
0x35 | ` and ~ on a US keyboard. This is the 半角/全角/漢字 (hankaku/zenkaku/kanji) key on Japanese keyboards |
'Backslash' |
0x31 | \ and | on a US keyboard. Found only on standard 101-key layouts. |
'Backspace' |
0x2a | Labelled Delete on Macintosh keyboards. |
'BracketLeft' |
0x2f | [ and { on a US keyboard. |
'BracketRight' |
0x30 | ] and } on a US keyboard. |
'Comma' |
0x36 | , and < on a US keyboard. |
'Digit0' |
0x27 | 0 and ) on a US keyboard. |
'Digit1' |
0x1e | 1 and ! on a US keyboard. |
'Digit2' |
0x1f | 2 and @ on a US keyboard. |
'Digit3' |
0x20 | 3 and # on a US keyboard. |
'Digit4' |
0x21 | 4 and $ on a US keyboard. |
'Digit5' |
0x22 | 5 and % on a US keyboard. |
'Digit6' |
0x23 | 6 and ^ on a US keyboard. |
'Digit7' |
0x24 | 7 and & on a US keyboard. |
'Digit8' |
0x25 | 8 and * on a US keyboard. |
'Digit9' |
0x26 | 9 and ( on a US keyboard. |
'Equal' |
0x2e | = and + on a US keyboard. |
'IntlBackslash' |
0x64 | Located between the 'ShiftLeft' and 'KeyZ' keys. The \ and | key on a UK keyboard. |
'IntlHash' |
0x32 | Located between the 'Quote' and 'Enter' keys on row E of the keyboard. The # and ~ key on a UK keyboard. |
'IntlRo' |
0x87 | Located between the 'Slash' and 'ShiftRight' keys. The \ and ろ (ro) key on a Japanese keyboard. |
'IntlYen' |
0x89 | Located between the 'Equal' and 'Backspace' keys. The ¥ (yen) key on a Japanese keyboard. The \ and / key on a Russian keyboard. |
'KeyA' |
0x04 | a on a US keyboard. Labelled q on an AZERTY (e.g., French) keyboard. |
'KeyB' |
0x05 | b on a US keyboard. |
'KeyC' |
0x06 | c on a US keyboard. |
'KeyD' |
0x07 | d on a US keyboard. |
'KeyE' |
0x08 | e on a US keyboard. |
'KeyF' |
0x09 | f on a US keyboard. |
'KeyG' |
0x0a | g on a US keyboard. |
'KeyH' |
0x0b | h on a US keyboard. |
'KeyI' |
0x0c | i on a US keyboard. |
'KeyJ' |
0x0d | j on a US keyboard. |
'KeyK' |
0x0e | k on a US keyboard. |
'KeyL' |
0x0f | l on a US keyboard. |
'KeyM' |
0x10 | m on a US keyboard. |
'KeyN' |
0x11 | n on a US keyboard. |
'KeyO' |
0x12 | o on a US keyboard. |
'KeyP' |
0x13 | p on a US keyboard. |
'KeyQ' |
0x14 | q on a US keyboard. Labelled a on an AZERTY (e.g., French) keyboard. |
'KeyR' |
0x15 | r on a US keyboard. |
'KeyS' |
0x16 | s on a US keyboard. |
'KeyT' |
0x17 | t on a US keyboard. |
'KeyU' |
0x18 | u on a US keyboard. |
'KeyV' |
0x19 | v on a US keyboard. |
'KeyW' |
0x1a | w on a US keyboard. Labelled z on an AZERTY (e.g., French) keyboard. |
'KeyX' |
0x1b | x on a US keyboard. |
'KeyY' |
0x1c | y on a US keyboard. Labelled z on a QWERTZ (e.g., German) keyboard. |
'KeyZ' |
0x1d | z on a US keyboard. Labelled w on an AZERTY (e.g., French) keyboard, and y on a QWERTZ (e.g., German) keyboard. |
'Minus' |
0x2d | - and _ on a US keyboard. |
'Period' |
0x37 | . and > on a US keyboard. |
'Quote' |
0x34 | ' and " on a US keyboard. |
'Semicolon' |
0x33 | ; and : on a US keyboard. |
'Slash' |
0x38 | / and ? on a US keyboard. |
The Functional keys (not to be confused with the Function keys described later) are those keys in the Alphanumeric section that provide general editing functions that are common to all locales (like Shift, Tab, Enter and Backspace). With a few exceptions, these keys do not change meaning based on the current keyboard layout.
Code Value | USB Usage ID Page 0x07 (Informative) | Notes (Informative) |
---|---|---|
'AltLeft' |
0xe2 | Labelled Alt or Option . |
'AltRight' |
0xe6 | Labelled Alt or Option . This is the AltGr key on many keyboard layouts. |
'CapsLock' |
0x39 | |
'ContextMenu' |
0x65 | The application context menu key, which is typically found between the right OS key and the right Control key. |
'ControlLeft' |
0xe0 | |
'ControlRight' |
0xe4 | |
'Enter' |
0x28 | Labelled Enter and Return on Macintosh keyboards. |
'OSLeft' |
0xe3 | The Windows, ⌘ , Command or other OS symbol key. |
'OSRight' |
0xe7 | The Windows, ⌘ , Command or other OS symbol key. |
'ShiftLeft' |
0xe1 | |
'ShiftRight' |
0xe5 | |
'Space' |
0x2c | The key. |
'Tab' |
0x2b |
On some keyboards (notably Japanese and Korean) the spacebar is reduced in size to make room
for extra keys on the bottom row. These keys typically allow the users to change the current input
mode. Note that even though some of these Japanese and Korean keys occupy the same physical location on the
keyboard, they use different code
values.
Code Value | USB Usage ID Page 0x07 (Informative) | Notes (Informative) |
---|---|---|
'Convert' |
0x8a | Japanese: 変換 (henkan) |
'KanaMode' |
0x88 | Japanese: カタカナ/ひらがな/ローマ字 (katakana/hiragana/romaji) |
'Lang1' |
0x90 | Korean: 한/영 (han/yeong)Japanese (Mac keyboard): かな (kana)
|
'Lang2' |
0x91 | Korean: 한자 (hanja)Japanese (Mac keyboard): 英数 (eisu)
|
'Lang3' |
0x92 | Japanese (word-processing keyboard): Katakana |
'Lang4' |
0x93 | Japanese (word-processing keyboard): Hiragana |
'Lang5' |
0x94 | Japanese (word-processing keyboard): Zenkaku/Hankaku |
'NonConvert' |
0x8b | Japanese: 無変換 (muhenkan) |
On Apple keyboards, some keys on the bottom row are omitted and others are arranged in a different order.
The Control Pad contains keys for navigating and editing documents.
Code Value | USB Usage ID Page 0x07 (Informative) | Notes (Informative) |
---|---|---|
'Delete' |
0x4c | |
'End' |
0x4d | |
'Help' |
0x75 | Not present on standard PC keyboards. |
'Home' |
0x4a | |
'Insert' |
0x49 | Not present on Apple keyboards. |
'PageDown' |
0x4e | |
'PageUp' |
0x4b |
Note: The code
for the 'Fn'
key (found on
some Apple keyboards) is defined below in the Function Section.
The Arrow Pad section contains the 4 arrow keys.
Code Value | USB Usage ID Page 0x07 (Informative) | Notes (Informative) |
---|---|---|
'ArrowDown' |
0x51 | |
'ArrowLeft' |
0x50 | |
'ArrowRight' |
0x4f | |
'ArrowUp' |
0x52 |
The Numpad Section contains numeric and mathematical operator keys arranged in a calculator-grid to facilitate numeric data entry. This section also covers phone keypads and remote control devices that arrange number keys in a grid.
The standard Numpad is sometimes extended with additional keys for parentheses, operators, hexadecimal symbols, or calculator functions (like backspace). Some of the commonly added keys are listed in the table below.
Code Value | USB Usage ID Page 0x07 (Informative) | Notes (Informative) |
---|---|---|
'NumLock' |
0x53 | On the Mac, the 'NumLock' code should be used for the numpad 'Clear' key. |
'Numpad0' |
0x62 |
0 /Insert on a keyboard0 on a phone or remote control
|
'Numpad1' |
0x59 |
1 /End on a keyboard1 or 1 /QZ on a phone or remote control
|
'Numpad2' |
0x5a |
2 /ArrowDown on a keyboard2 /ABC on a phone or remote control
|
'Numpad3' |
0x5b |
3 /PageDown on a keyboard3 /DEF on a phone or remote control
|
'Numpad4' |
0x5c |
4 /ArrowLeft on a keyboard4 /GHI on a phone or remote control
|
'Numpad5' |
0x5d |
5 on a keyboard5 /JKL on a phone or remote control
|
'Numpad6' |
0x5e |
6 /ArrowRight on a keyboard6 /MNO on a phone or remote control
|
'Numpad7' |
0x5f |
7 /Home on a keyboard7 /PQRS or 7 /PRS on a phone or remote control
|
'Numpad8' |
0x60 |
8 /ArrowUp on a keyboard8 /TUV on a phone or remote control
|
'Numpad9' |
0x61 |
9 /PageUp on a keyboard9 /WXYZ or 9 /WXY on a phone or remote control
|
'NumpadAdd' |
0x57 | + |
'NumpadBackspace' |
0xbb | Found on the Microsoft Natural Keyboard. |
'NumpadClear' |
0xd8 | For use with numpads that have a 'Clear' key that is separate from the 'NumLock' key.
On the Mac, the numpad 'Clear' key should always be encoded as 'NumLock' . |
'NumpadClearEntry' |
0xd9 | |
'NumpadComma' |
0x85 | , (thousands separator). For locales where the thousands separator is a '.' (e.g., Brazil), this key may generate a '.' . |
'NumpadDecimal' |
0x63 | . (decimal separator) and Delete . For locales where the decimal separator is ',' (e.g., Brazil), this key may generate a ',' . |
'NumpadDivide' |
0x54 | / |
'NumpadEnter' |
0x58 | |
'NumpadEqual' |
0x67 | = |
'NumpadHash' |
# on a phone or remote control device.
This key is typically found below the 9 key and to the right of the 0 key.
| |
'NumpadMemoryAdd' |
0xd3 | |
'NumpadMemoryClear' |
0xd2 | |
'NumpadMemoryRecall' |
0xd1 | |
'NumpadMemoryStore' |
0xd0 | |
'NumpadMemorySubtract' |
0xd4 | |
'NumpadMultiply' |
0x55 |
* on a keyboard. For use with numpads that provide mathematical operations
(+ , - , * and / ).
See 'NumpadStar' for the * key on phones and
remote controls.
|
'NumpadParenLeft' |
0xb6 | ( Found on the Microsoft Natural Keyboard. |
'NumpadParenRight' |
0xb7 | ) Found on the Microsoft Natural Keyboard. |
'NumpadStar' |
* on a phone or remote control device.
This key is typically found below the 7 key and to the left of the 0 key.
See 'NumpadMultiply' for the * key on numeric keypads.
| |
'NumpadSubtract' |
0x56 | - |
For Numpads that provide keys not listed here, a code
value string should be created by
starting with 'Numpad' and appending an appropriate description of the key.
The Function section runs along the top of the keyboard and contains the function keys and
a few additional special keys (for example, 'Escape'
and
'PrintScreen'
).
On some keyboards (especially those found on laptops or other portable computers), the function keys
('F1'
... 'F12'
)
are defined to have other primary functions (like controlling display brightness or
audio volume) and require that a separate 'Fn'
key
be pressed to make them act as function keys.
Unfortunately, the primary functions assigned to these keys varies widely from one manufacturer to the next.
Because of this, the code
is always set to the function key name.
Code Value | USB Usage ID Page 0x07 (Informative) | Notes (Informative) |
---|---|---|
'Escape' |
0x29 | |
'F1' |
0x3a | |
'F2' |
0x3b | |
'F3' |
0x3c | |
'F4' |
0x3d | |
'F5' |
0x3e | |
'F6' |
0x3f | |
'F7' |
0x40 | |
'F8' |
0x41 | |
'F9' |
0x42 | |
'F10' |
0x43 | |
'F11' |
0x44 | |
'F12' |
0x45 | |
'Fn' |
This is typically a hardware key that does not generate a separate code. Most keyboards do not place this key in the Function section, but it is included here to keep with related keys. | |
'FnLock' |
Found on the Microsoft Natural Keyboard. | |
'PrintScreen' |
0x46 | PrintScreen and SysReq |
'ScrollLock' |
0x47 | |
'Pause' |
0x48 | Pause and Break |
For keyboards that provide more than 12 function keys, the code
value follows the pattern
shown above with 'F' followed by the function key number - 'F13'
, 'F14'
,
'F15'
, and so on.
Note: Apple keyboards may have 'Eject'
or 'Power'
keys in the Function section. The code
values
for these keys are defined in the Media Keys section.
Keys that fall outside the sections listed above are referred to as "media keys" since they commonly provide "media" functions like play, pause or volume control.
These are extra keys that many keyboard manufacturers add, but do not have a consistent location. These keys are often distinct from normal typing keys in appearance and may be recessed in the keyboard.
On laptop keyboards, these keys are often merged with the Function keys, with the "media" interpretation
being the primary function of the key and the "function key" interpretation requiring the
'Fn'
key to be pressed at the same time. In this configuration the
code
should be set to match the function key ('F1'
...
'F12'
). When the keys are merged in this fashion, the code
values are taken from the function key value since the "media" value is not consistent across
keyboards.
Code Value | Notes (Informative) |
---|---|
'BrowserBack' |
Some laptops place this key to the left of the 'ArrowUp' key. |
'BrowserFavorites' |
|
'BrowserForward' |
Some laptops place this key to the right of the 'ArrowUp' key. |
'BrowserHome' |
|
'BrowserRefresh' |
|
'BrowserSearch' |
|
'BrowserStop' |
|
'Eject' |
This key is placed in the Function section on some Apple keyboards. |
'LaunchApp1' |
Sometimes labelled My Computer on the keyboard |
'LaunchApp2' |
Sometimes labelled Calculator on the keyboard |
'LaunchMail' |
|
'MediaPlayPause' |
|
'MediaSelect' |
|
'MediaStop' |
|
'MediaTrackNext' |
|
'MediaTrackPrevious' |
|
'Power' |
This key is placed in the Function section on some Apple keyboards, replacing the 'Eject' key. |
'Sleep' |
|
'VolumeDown' |
|
'VolumeMute' |
|
'VolumeUp' |
|
'WakeUp' |
These keys are not found on modern standard keyboards. They are listed here for reference purposes.
Code Value | Notes (Informative) |
---|---|
'Hyper' |
|
'Super' |
|
'Turbo' |
Code Value | Notes (Informative) |
---|---|
'Abort' |
|
'Resume' |
|
'Suspend' |
Code Value | Notes (Informative) |
---|---|
'Again' |
Found on Sun's USB keyboard. |
'Copy' |
Found on Sun's USB keyboard. |
'Cut' |
Found on Sun's USB keyboard. |
'Find' |
Found on Sun's USB keyboard. |
'Open' |
Found on Sun's USB keyboard. |
'Paste' |
Found on Sun's USB keyboard. |
'Props' |
Found on Sun's USB keyboard. |
'Select' |
Found on Sun's USB keyboard. |
'Undo' |
Found on Sun's USB keyboard. |
The following keys may be found on non-standard international keyboards.
Code Value | Notes (Informative) |
---|---|
'Hiragana' |
Use for dedicated ひらがな key found on some Japanese word processing keyboards. |
'Katakana' |
Use for dedicated カタカナ key found on some Japanese word processing keyboards. |
Considerable thanks are due to the following participants of the WebApps Working Group for providing substantial material contributions in the process of developing this specification.
Gary Kacmarcik (Google), Masayuki Nakano (Mozilla)