Copyright © 2015 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and permissive document license 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 specification was formerly titled DOM Level 3 KeyboardEvent code Values.
This document was published by the Web Platform Working Group as an Working Draft. If you wish to make comments regarding this document, please send them to [email protected] (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 September 2015 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 [uievents-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 | Notes (Informative) |
---|---|
'Backquote' |
` and ~ on a US keyboard. This is the 半角/全角/漢字 (hankaku/zenkaku/kanji) key on Japanese keyboards |
'Backslash' |
\ and | on a US keyboard. Found only on standard 101-key layouts. |
'Backspace' |
Labelled Delete on Macintosh keyboards. |
'BracketLeft' |
[ and { on a US keyboard. |
'BracketRight' |
] and } on a US keyboard. |
'Comma' |
, and < on a US keyboard. |
'Digit0' |
0 and ) on a US keyboard. |
'Digit1' |
1 and ! on a US keyboard. |
'Digit2' |
2 and @ on a US keyboard. |
'Digit3' |
3 and # on a US keyboard. |
'Digit4' |
4 and $ on a US keyboard. |
'Digit5' |
5 and % on a US keyboard. |
'Digit6' |
6 and ^ on a US keyboard. |
'Digit7' |
7 and & on a US keyboard. |
'Digit8' |
8 and * on a US keyboard. |
'Digit9' |
9 and ( on a US keyboard. |
'Equal' |
= and + on a US keyboard. |
'IntlBackslash' |
Located between the 'ShiftLeft' and 'KeyZ' keys. The \ and | key on a UK keyboard. |
'IntlHash' |
Located between the 'Quote' and 'Enter' keys on row E of the keyboard. The # and ~ key on a UK keyboard. |
'IntlRo' |
Located between the 'Slash' and 'ShiftRight' keys. The \ and ろ (ro) key on a Japanese keyboard. |
'IntlYen' |
Located between the 'Equal' and 'Backspace' keys. The ¥ (yen) key on a Japanese keyboard. The \ and / key on a Russian keyboard. |
'KeyA' |
a on a US keyboard. Labelled q on an AZERTY (e.g., French) keyboard. |
'KeyB' |
b on a US keyboard. |
'KeyC' |
c on a US keyboard. |
'KeyD' |
d on a US keyboard. |
'KeyE' |
e on a US keyboard. |
'KeyF' |
f on a US keyboard. |
'KeyG' |
g on a US keyboard. |
'KeyH' |
h on a US keyboard. |
'KeyI' |
i on a US keyboard. |
'KeyJ' |
j on a US keyboard. |
'KeyK' |
k on a US keyboard. |
'KeyL' |
l on a US keyboard. |
'KeyM' |
m on a US keyboard. |
'KeyN' |
n on a US keyboard. |
'KeyO' |
o on a US keyboard. |
'KeyP' |
p on a US keyboard. |
'KeyQ' |
q on a US keyboard. Labelled a on an AZERTY (e.g., French) keyboard. |
'KeyR' |
r on a US keyboard. |
'KeyS' |
s on a US keyboard. |
'KeyT' |
t on a US keyboard. |
'KeyU' |
u on a US keyboard. |
'KeyV' |
v on a US keyboard. |
'KeyW' |
w on a US keyboard. Labelled z on an AZERTY (e.g., French) keyboard. |
'KeyX' |
x on a US keyboard. |
'KeyY' |
y on a US keyboard. Labelled z on a QWERTZ (e.g., German) keyboard. |
'KeyZ' |
z on a US keyboard. Labelled w on an AZERTY (e.g., French) keyboard, and y on a QWERTZ (e.g., German) keyboard. |
'Minus' |
- and _ on a US keyboard. |
'Period' |
. and > on a US keyboard. |
'Quote' |
' and " on a US keyboard. |
'Semicolon' |
; and : on a US keyboard. |
'Slash' |
/ 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 | Notes (Informative) |
---|---|
'AltLeft' |
Labelled Alt or Option . |
'AltRight' |
Labelled Alt or Option . This is the AltGr key on many keyboard layouts. |
'CapsLock' |
|
'ContextMenu' |
The application context menu key, which is typically found between the right OS key and the right Control key. |
'ControlLeft' |
|
'ControlRight' |
|
'Enter' |
Labelled Enter and Return on Macintosh keyboards. |
'OSLeft' |
The Windows, ⌘ , Command or other OS symbol key. |
'OSRight' |
The Windows, ⌘ , Command or other OS symbol key. |
'ShiftLeft' |
|
'ShiftRight' |
|
'Space' |
The key. |
'Tab' |
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 | Notes (Informative) |
---|---|
'Convert' |
Japanese: 変換 (henkan) |
'KanaMode' |
Japanese: カタカナ/ひらがな/ローマ字 (katakana/hiragana/romaji) |
'Lang1' |
Korean: 한/영 (han/yeong)Japanese (Mac keyboard): かな (kana)
|
'Lang2' |
Korean: 한자 (hanja)Japanese (Mac keyboard): 英数 (eisu)
|
'Lang3' |
Japanese (word-processing keyboard): Katakana |
'Lang4' |
Japanese (word-processing keyboard): Hiragana |
'Lang5' |
Japanese (word-processing keyboard): Zenkaku/Hankaku |
'NonConvert' |
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 | Notes (Informative) |
---|---|
'Delete' |
|
'End' |
|
'Help' |
Not present on standard PC keyboards. |
'Home' |
|
'Insert' |
Not present on Apple keyboards. |
'PageDown' |
|
'PageUp' |
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 | Notes (Informative) |
---|---|
'ArrowDown' |
|
'ArrowLeft' |
|
'ArrowRight' |
|
'ArrowUp' |
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 | Notes (Informative) |
---|---|
'NumLock' |
On the Mac, the 'NumLock' code should be used for the numpad 'Clear' key. |
'Numpad0' |
0 /Insert on a keyboard0 on a phone or remote control
|
'Numpad1' |
1 /End on a keyboard1 or 1 /QZ on a phone or remote control
|
'Numpad2' |
2 /ArrowDown on a keyboard2 /ABC on a phone or remote control
|
'Numpad3' |
3 /PageDown on a keyboard3 /DEF on a phone or remote control
|
'Numpad4' |
4 /ArrowLeft on a keyboard4 /GHI on a phone or remote control
|
'Numpad5' |
5 on a keyboard5 /JKL on a phone or remote control
|
'Numpad6' |
6 /ArrowRight on a keyboard6 /MNO on a phone or remote control
|
'Numpad7' |
7 /Home on a keyboard7 /PQRS or 7 /PRS on a phone or remote control
|
'Numpad8' |
8 /ArrowUp on a keyboard8 /TUV on a phone or remote control
|
'Numpad9' |
9 /PageUp on a keyboard9 /WXYZ or 9 /WXY on a phone or remote control
|
'NumpadAdd' |
+ |
'NumpadBackspace' |
Found on the Microsoft Natural Keyboard. |
'NumpadClear' |
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' |
|
'NumpadComma' |
, (thousands separator). For locales where the thousands separator is a '.' (e.g., Brazil), this key may generate a '.' . |
'NumpadDecimal' |
. (decimal separator) and Delete . For locales where the decimal separator is ',' (e.g., Brazil), this key may generate a ',' . |
'NumpadDivide' |
/ |
'NumpadEnter' |
|
'NumpadEqual' |
= |
'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' |
|
'NumpadMemoryClear' |
|
'NumpadMemoryRecall' |
|
'NumpadMemoryStore' |
|
'NumpadMemorySubtract' |
|
'NumpadMultiply' |
* on a keyboard. For use with numpads that provide mathematical operations
(+ , - , * and / ).
See 'NumpadStar' for the * key on phones and
remote controls.
|
'NumpadParenLeft' |
( Found on the Microsoft Natural Keyboard. |
'NumpadParenRight' |
) 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' |
- |
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 | Notes (Informative) |
---|---|
'Escape' |
|
'F1' |
|
'F2' |
|
'F3' |
|
'F4' |
|
'F5' |
|
'F6' |
|
'F7' |
|
'F8' |
|
'F9' |
|
'F10' |
|
'F11' |
|
'F12' |
|
'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' |
PrintScreen and SysReq |
'ScrollLock' |
|
'Pause' |
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)