KeyboardEvent

  • Revision slug: DOM/KeyboardEvent
  • Revision title: KeyboardEvent
  • Revision id: 303131
  • Created:
  • Creator: Masayuki
  • Is current revision? No
  • Comment

Revision Content

KeyboardEvent objects describe a user interaction with the keyboard. Each event describes a key; the event type ({{domevent('keydown')}}, {{domevent('keypress')}}, or {{domevent('keyup')}}) identifies what kind of activity was performed.

Note: The KeyboardEvent indicates just what's happening on a key. When you need to handle text input, use HTML5 input event instead. For example, if user inputs text from hand-writing system like tablet PC, key events may not be fired.

Method overview

boolean getModifierState(in DOMString keyArg);
void initKeyboardEvent(in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in views::AbstractView viewArg, in DOMString charArg, in DOMString keyArg, in unsigned long locationArg, in DOMString modifiersListArg, in boolean repeat, in DOMString localeArg);

Attributes

Attribute Type Description
altKey boolean true if the Alt (or Option, on Mac) key was active when the key event was generated. Read only.
char DOMString

The character value of the key. If the key corresponds to a printable character, this value is a non-empty Unicode string containing that character. If the key doesn't have a printable representation, this is an empty string. See key names and char values for the detail. Read only.

Note: If the key is used as a macro that inserts multiple characters, this attribute's value is the entire string, not just the first character.

{{gecko_callout_unimplemented("680830")}}

This attribute is not implemented in Gecko at this time.

charCode {{deprecated_inline()}} unsigned long

The Unicode reference number of the key; this attribute is used only by the {{domevent('keypress')}} event. For keys whose char attribute contains multiple characters, this is the Unicode value of the first character in that attribute. Read only.

Warning: This attribute is deprecated; you should use char instead, if available.
ctrlKey boolean true if the Control key was active when the key event was generated. Read only.
key DOMString

The key value of the key represented by the event. If the value has a printed representation, this attribute's value is the same as the char attribute. Otherwise, it's one of the key value strings specified in {{anch("Key values")}}. If the key can't be identified, this is the string "Unidentified". See key names and char values for the detail. Read only.

{{gecko_callout_unimplemented("680830")}}

This attribute is not implemented in Gecko at this time.

keyCode {{deprecated_inline()}}

unsigned long

A system and implementation dependent numerical code identifying the unmodified value of the pressed key. This is usually the decimal ASCII ({{RFC(20)}}) or Windows 1252 code corresponding to the key; see {{anch("Virtual key codes")}} for a list of Gecko's keyCode values. If the key can't be identified, this value is 0. Read only.

Warning: This attribute is deprecated; you should use key instead, if available.
locale DOMString

A locale string indicating the locale the keyboard is configured for. This may be the empty string if the browser or device doesn't know the keyboard's locale. Read only.

Note: This does not describe the locale of the data being entered. A user may be using one keyboard layout while typing text in a different language.

location {{dom_level("3")}} {{gecko_minversion_inline("15.0")}}

unsigned long

The location of the key on the keyboard or other input device; see {{anch("Key location constants")}} below. Read only.

metaKey boolean true if the Meta (or Command, on Mac) key was active when the key event was generated. Read only.
repeat boolean

true if the key is being held down such that it is automatically repeating. Read only.

{{gecko_callout_unimplemented("600117")}}

This attribute is not implemented in Gecko at this time.

shiftKey boolean true if the Shift key was active when the key event was generated. Read only.
which {{deprecated_inline()}} unsigned long

A system and implementation dependent numeric code identifying the unmodified value of the pressed key; this is usually the same as keyCode. Read only.

Warning: This attribute is deprecated; you should use key instead, if available.

Constants

Virtual key codes

{{deprecated_header()}}

These constants represent virtual key codes as reported by the deprecated keyCode attribute; that is, keys that do not correspond to printable characters. The diagram below represents a standard ANSI US keyboard; Mac and most PC keyboards have the same layout for the printable characters, and a similar layout for the remaining keys.

Starting in Gecko 15 {{geckoRelease("15.0")}}, Gecko decides keycode by following rules for printable keys:

  1. If the system is Windows and native keycode of pressed key indicates that the key is a-z or 0-9, uses a keycode for it.
  2. If the system is Mac and native keycode of pressed key indicates that the key is 0-9, uses a keycode for it.
  3. If pressed key inputs an ASCII alphabet or numeric with no modifier key, uses a keycode for it.
  4. If pressed key inputs an ASCII alphabet or numeric with Shift key, uses a keycode for it.
  5. If pressed key inputs another ASCII character with no modifier key, uses a keycode for it.
  6. If pressed key inputs another ASCII character with Shift key, users a keycode for it.
  7. Otherwise, i.e., pressed key inputs a Unicode character:
    1. If the keyboard layout is ASCII capable keyboard layout (i.e., can input ASCII alphabets), uses 0.
    2. Otherwise, i.e., the keyboard layout isn't ASCII capable, using ASCII capable keyboard layout which is installed on the environment and has highest priority:
      1. If pressed key on the alternative keyboard layout inputs an ASCII alphabet or numeric, uses a keycode for it.
      2. Otherwise, uses 0.
Note: Web developers shouldn't use keycode attribute of printable keys in keydown and keyup event handlers. As described above, keycode is not usable for checking character which will be inputted especially when Shift key or AltGr key is pressed. When web developers implement shortcut key handler, keypress event is better event for that purpose on Gecko at least. See Gecko Keypress Event for the detail.
Constant Value Description
DOM_VK_CANCEL 3 Cancel key.
DOM_VK_HELP 6 Help key.
DOM_VK_BACK_SPACE 8 Backspace key.
DOM_VK_TAB 9 Tab key.
DOM_VK_CLEAR 12 "5" key on Numpad when NumLock is unlocked. Or on Mac, clear key which is positioned at NumLock key.
DOM_VK_RETURN 13 Return/enter key on the main keyboard.
DOM_VK_ENTER 14 Reserved, but not used.
DOM_VK_SHIFT 16 Shift key.
DOM_VK_CONTROL 17 Control key.
DOM_VK_ALT 18 Alt (Option on Mac) key.
DOM_VK_PAUSE 19 Pause key.
DOM_VK_CAPS_LOCK 20 Caps lock.
DOM_VK_ESCAPE 27 Escape key.
DOM_VK_SPACE 32 Space bar.
DOM_VK_PAGE_UP 33 Page Up key.
DOM_VK_PAGE_DOWN 34 Page Down key.
DOM_VK_END 35 End key.
DOM_VK_HOME 36 Home key.
DOM_VK_LEFT 37 Left arrow.
DOM_VK_UP 38 Up arrow.
DOM_VK_RIGHT 39 Right arrow.
DOM_VK_DOWN 40 Down arrow.
DOM_VK_SELECT 41  
DOM_VK_PRINT 42  
DOM_VK_EXECUTE 43  
DOM_VK_PRINTSCREEN 44 Print Screen key.
DOM_VK_INSERT 45 Ins(ert) key.
DOM_VK_DELETE 46 Del(ete) key.
DOM_VK_0 48  
DOM_VK_1 49  
DOM_VK_2 50  
DOM_VK_3 51  
DOM_VK_4 52  
DOM_VK_5 53  
DOM_VK_6 54  
DOM_VK_7 55  
DOM_VK_8 56  
DOM_VK_9 57  
DOM_VK_COLON 58 Colon (":") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_SEMICOLON 59 Semicolon (";") key.
DOM_VK_LESS_THAN 60 Less-than ("<") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_EQUALS 61 Equals ("=") key.
DOM_VK_GREATER_THAN 62 Greater-than (">") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_QUESTION_MARK 63 Question mark ("?") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_AT 64 Atmark ("@") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_A 65  
DOM_VK_B 66  
DOM_VK_C 67  
DOM_VK_D 68  
DOM_VK_E 69  
DOM_VK_F 70  
DOM_VK_G 71  
DOM_VK_H 72  
DOM_VK_I 73  
DOM_VK_J 74  
DOM_VK_K 75  
DOM_VK_L 76  
DOM_VK_M 77  
DOM_VK_N 78  
DOM_VK_O 79  
DOM_VK_P 80  
DOM_VK_Q 81  
DOM_VK_R 82  
DOM_VK_S 83  
DOM_VK_T 84  
DOM_VK_U 85  
DOM_VK_V 86  
DOM_VK_W 87  
DOM_VK_X 88  
DOM_VK_Y 89  
DOM_VK_Z 90  
DOM_VK_CONTEXT_MENU 93  
DOM_VK_NUMPAD0 96 0 on the numeric keypad.
DOM_VK_NUMPAD1 97 1 on the numeric keypad.
DOM_VK_NUMPAD2 98 2 on the numeric keypad.
DOM_VK_NUMPAD3 99 3 on the numeric keypad.
DOM_VK_NUMPAD4 100 4 on the numeric keypad.
DOM_VK_NUMPAD5 101 5 on the numeric keypad.
DOM_VK_NUMPAD6 102 6 on the numeric keypad.
DOM_VK_NUMPAD7 103 7 on the numeric keypad.
DOM_VK_NUMPAD8 104 8 on the numeric keypad.
DOM_VK_NUMPAD9 105 9 on the numeric keypad.
DOM_VK_MULTIPLY 106 * on the numeric keypad.
DOM_VK_ADD 107 + on the numeric keypad.
DOM_VK_SEPARATOR 108  
DOM_VK_SUBTRACT 109 - on the numeric keypad.
DOM_VK_DECIMAL 110 Decimal point on the numeric keypad.
DOM_VK_DIVIDE 111 / on the numeric keypad.
DOM_VK_F1 112 F1 key.
DOM_VK_F2 113 F2 key.
DOM_VK_F3 114 F3 key.
DOM_VK_F4 115 F4 key.
DOM_VK_F5 116 F5 key.
DOM_VK_F6 117 F6 key.
DOM_VK_F7 118 F7 key.
DOM_VK_F8 119 F8 key.
DOM_VK_F9 120 F9 key.
DOM_VK_F10 121 F10 key.
DOM_VK_F11 122 F11 key.
DOM_VK_F12 123 F12 key.
DOM_VK_F13 124 F13 key.
DOM_VK_F14 125 F14 key.
DOM_VK_F15 126 F15 key.
DOM_VK_F16 127 F16 key.
DOM_VK_F17 128 F17 key.
DOM_VK_F18 129 F18 key.
DOM_VK_F19 130 F19 key.
DOM_VK_F20 131 F20 key.
DOM_VK_F21 132 F21 key.
DOM_VK_F22 133 F22 key.
DOM_VK_F23 134 F23 key.
DOM_VK_F24 135 F24 key.
DOM_VK_NUM_LOCK 144 Num Lock key.
DOM_VK_SCROLL_LOCK 145 Scroll Lock key.
DOM_VK_CIRCUMFLEX 160 Circumflex ("^") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_EXCLAMATION 161 Exclamation ("!") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_DOUBLE_QUOTE 162 Double quote (""") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_HASH 163 Hash ("#") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_DOLLAR 164 Dollar sign ("$") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_PERCENT 165 Percent ("%") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_AMPERSAND 166 Ampersand ("&") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_UNDERSCORE 167 Underscore ("_") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_OPEN_PAREN 168 Open parenthesis ("(") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_CLOSE_PAREN 169 Close parenthesis (")") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_ASTERISK 170 Asterisk ("*") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_PLUS 171 Plus ("+") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_PIPE 172 Pipe ("|") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_HYPHEN_MINUS 173 Hyphen-US/docs/Minus ("-") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_OPEN_CURLY_BRACKET 174 Open curly bracket ("{") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_CLOSE_CURLY_BRACKET 175 Close curly bracket ("}") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_TILDE 176 Tilde ("~") key. {{gecko_minversion_inline("15.0")}}
DOM_VK_COMMA 188 Comma (",") key.
DOM_VK_PERIOD 190 Period (".") key.
DOM_VK_SLASH 191 Slash ("/") key.
DOM_VK_BACK_QUOTE 192 Back tick ("`") key.
DOM_VK_OPEN_BRACKET 219 Open square bracket ("[") key.
DOM_VK_BACK_SLASH 220 Back slash ("\") key.
DOM_VK_CLOSE_BRACKET 221 Close square bracket ("]") key.
DOM_VK_QUOTE 222 Quote (''') key.
DOM_VK_META 224 Meta key on Linux, Command key on Mac.
DOM_VK_ALTGR 225 AltGr key on Linux. {{gecko_minversion_inline("15.0")}}
DOM_VK_WIN 91 Windows logo key on Windows. Or Super or Hyper key on Linux. {{gecko_minversion_inline("15.0")}}
DOM_VK_KANA 21 Linux support for this keycode was added in Gecko 4.0.
DOM_VK_HANGUL 21 Linux support for this keycode was added in Gecko 4.0.
DOM_VK_EISU 22 "英数" key on Japanese Mac keyboard. {{gecko_minversion_inline("15.0")}}
DOM_VK_JUNJA 23 Linux support for this keycode was added in Gecko 4.0.
DOM_VK_FINAL 24 Linux support for this keycode was added in Gecko 4.0.
DOM_VK_HANJA 25 Linux support for this keycode was added in Gecko 4.0.
DOM_VK_KANJI 25 Linux support for this keycode was added in Gecko 4.0.
DOM_VK_CONVERT 28 Linux support for this keycode was added in Gecko 4.0.
DOM_VK_NONCONVERT 29 Linux support for this keycode was added in Gecko 4.0.
DOM_VK_ACCEPT 30 Linux support for this keycode was added in Gecko 4.0.
DOM_VK_MODECHANGE 31 Linux support for this keycode was added in Gecko 4.0.
DOM_VK_SELECT 41 Linux support for this keycode was added in Gecko 4.0.
DOM_VK_PRINT 42 Linux support for this keycode was added in Gecko 4.0.
DOM_VK_EXECUTE 43 Linux support for this keycode was added in Gecko 4.0.
DOM_VK_SLEEP 95 Linux support for this keycode was added in Gecko 4.0.

Key location constants

These constants describe the location on the keyboard of key events. {{dom_level("3")}} {{gecko_minversion_inline("15.0")}}

Constant Value Description
DOM_KEY_LOCATION_STANDARD 0 The key must not be distinguished between the left and right versions of the key, and was not pressed on the numeric keypad or a key that is considered to be part of the keypad.
DOM_KEY_LOCATION_LEFT 1 The key was the left-hand version of the key; for example, this is the value of the location attribute when the left-hand Control key is pressed on a standard 101 key US keyboard. This value is only used for keys that have more that one possible location on the keyboard.
DOM_KEY_LOCATION_RIGHT 2 The key was the right-hand version of the key; for example, this is the value of the location attribute when the right-hand Control key is pressed on a standard 101 key US keyboard. This value is only used for keys that have more that one possible location on the keyboard.
DOM_KEY_LOCATION_NUMPAD 3

The key was on the numeric keypad, or has a virtual key code that corresponds to the numeric keypad.

Note: When NumLock is locked, Gecko always returns DOM_KEY_LOCATION_NUMPAD for the keys on NumPad. Otherwise, when NumLock is unlocked and the keyboard actually has a numeric keypad, Gecko always returns DOM_KEY_LOCATION_NUMPAD too. On the other hand, if the keyboard doesn't have a keypad, such as on a notebook computer, some keys become Numpad only when NumLock is locked. When such keys fires key events, the location attribute value depends on the key. That is, it must not be DOM_KEY_LOCATION_NUMPAD.
Note: NumLock key's key events indicate DOM_KEY_LOCATION_STANDARD both on Gecko and Internet Explorer.
DOM_KEY_LOCATION_MOBILE 4

The key was on a mobile device; this can be on either a physical keypad or a virtual keyboard.

Note: Gecko always returns DOM_KEY_LOCATION_MOBILE on Android, Maemo, and Boot to Gecko.
DOM_KEY_LOCATION_JOYSTICK 5

The key was a button on a game controller or a joystick on a mobile device.

Note: Gecko never fires trusted key events with DOM_KEY_LOCATION_JOYSTICK (See {{bug("756504")}} for Android).

Methods

getModifierState()

Returns the current state of the specified modifier key. {{dom_level("3")}} {{gecko_minversion_inline("15.0")}}

boolean getModifierState(
  in DOMString keyArg
);
Parameters
keyArg
A string identifying the modifier key whose value you wish to determine. This may be an implementation-defined value or one of: "Alt", "AltGraph", "CapsLock", "Control", "Fn", "Meta", "NumLock", "ScrollLock", "Shift", "SymbolLock", or "OS". Note that IE9 uses "Scroll" for "ScrollLock" and "Win" for "OS". If you use these older draft's name, Gecko's getModifierState() always returns false.
Return value

true if the specified modifier key is engaged; otherwise false.

When getModifierState() returns true on Gecko?
  Windows Linux (GTK) Mac
"Alt" Either Alt key or AltGr key pressed Alt key pressed option key pressed
"AltGraph"

Both Alt and Ctrl keys are pressed, or AltGr key is pressed

AltGr key pressed option key pressed
"CapsLock" During LED for Caps Lock turned on
"Control" Either Ctrl key or AltGr key pressed Ctrl key pressed control key pressed
"Fn" Not supported
"Meta" Not supported Meta key pressed {{gecko_minversion_inline("17.0")}} command key pressed
"NumLock" During LED for Num Lock turned on A key on numpad pressed
"ScrollLock" During LED for Scroll Lock turned on During LED for Scroll Lock turned on, but typically this isn't supported by platform Not supported
"Shift" Shift key pressed
"SymbolLock" Not supported
"OS" Windows Logo key pressed Super key or Hyper key pressed (typically, mapped to Windows Logo key) Not supported

On the other platforms, "Alt", "Control" and "Shift" may be supported.

All modifiers are always supported for untrusted events on Gecko. This doesn't depend on the platform.

initKeyboardEvent()

{{deprecated_header()}}

Initializes the attributes of a keyboard event object. This method was introduced in draft of DOM Level 3 Events, but deprecated in newer draft. Gecko doesn't implement this method but there is similar one, see initKeyEvent().

void initKeyboardEvent(
  in DOMString typeArg,
  in boolean canBubbleArg,
  in boolean cancelableArg,
  in views::AbstractView viewArg,
  in DOMString charArg,
  in DOMString keyArg,
  in unsigned long locationArg,
  in DOMString modifiersListArg,
  in boolean repeat,
  in DOMString localeArg
);
Parameters
typeArg
The type of keyboard event; this will be one of {{domevent('keydown')}}, {{domevent('keypress')}}, or {{domevent('keyup')}}.
canBubbleArg
Whether or not the event can bubble.
cancelableArg
Whether or not the event can be canceled.
viewArg
?
charArg
The value of the char attribute.
keyArg
The value of the key attribute.
locationArg
The value of the location attribute.
modifiersListArg
A whitespace-delineated list of modifier keys that should be considered to be active on the event's key. For example, specifying "Control Shift" indicates that the user was holding down the Control and Shift keys when pressing the key described by the event.
repeatArg
The value of the repeat attribute.
localeArg
The value of the locale attribute.

Processing of key events

There are keydown, keypress, and keyup events. For most keys, Gecko dispatches a sequence of key events like this:

  1. When the key is first depressed, the keydown event is sent.
  2. If the key is not a modifier key, the keypress event is sent.
  3. When the user releases the key, the keyup event is sent.

Special cases

Certain keys toggle the state of an LED indicator, such as Caps Lock, Num Lock, and Scroll Lock. On Windows and Linux, these keys dispatch only the keydown and keyup events. Note that on Linux, Firefox 12 and earlier also dispatched the keypress event for these keys.

On Mac, however, Caps Lock dispatches only the keydown event due to a platform event model limitation. Num Lock had been supported on old MacBook (2007 model and older) but Mac hasn't supported Num Lock feature even on external keyboards in these days. On the old MacBook which has Num Lock key, Num Lock doesn't cause any key events. And Gecko supports Scroll Lock key if an external keyboard which has F14 is connected. However, it generates keypress event. This inconsistent behavior is a bug; see {{bug(602812)}}.

Auto-repeat handling

When a key is pressed and held down, it begins to auto-repeat. This results in a sequence of events similar to the following being dispatched:

  1. keydown
  2. keypress
  3. keydown
  4. keypress
  5. <<repeating until the user releases the key>>
  6. keyup

This is what the DOM Level 3 specification says should happen. There are some caveats, however, as described below.

Auto-repeat on some GTK environments such as Ubuntu 9.4

In some GTK-based environments, auto-repeat dispatches a native key-up event automatically during auto-repeat, and there's no way for Gecko to know the difference between a repeated series of keypresses and an auto-repeat. On those platforms, then, an auto-repeat key will generate the following sequence of events:

  1. keydown
  2. keypress
  3. keyup
  4. keydown
  5. keypress
  6. keyup
  7. <<repeating until the user releases the key>>
  8. keyup

In these environments, unfortunately, there's no way for web content to tell the difference between auto-repeating keys and keys that are just being pressed repeatedly.

Auto-repeat handling prior to Gecko 4.0

Before Gecko 4.0 {{geckoRelease('4.0')}}, keyboard handling was less consistent across platforms.

Windows
Auto-repeat behavior is the same as in Gecko 4.0 and later.
Mac
After the initial keydown event, only keypress events are sent until the keyup event occurs; the inter-spaced keydown events are not sent.
Linux
The event behavior depends on the specific platform. It will either behave like Windows or Mac depending on what the native event model does.

Key names and Char values

Following tables show what key and char values are used for each native virtual keycode. The information for Gecko is currently planned in {{ bug(680830) }}.

key names and char values on Windows
Virtual-Key Codes IE 9 Gecko (plan)
VK_LBUTTON (0x01) "Unidentified" null "Unidentified" ""
VK_RBUTTON (0x02) "Unidentified" null "Unidentified" ""
VK_CANCEL (0x03) "" 0x03 "Cancel" 0x18
VK_MBUTTON (0x04) "Unidentified" null "Unidentified" ""
VK_XBUTTON1 (0x05) "Unidentified" null "Unidentified" ""
VK_XBUTTON2 (0x06) "Unidentified" null "Unidentified" ""
VK_BACK (0x08) "Backspace" 0x08 "Backspace" 0x08
VK_TAB (0x09) "Tab" 0x09 "Tab" 0x09
VK_CLEAR (0x0C) "Clear" null "Clear" ""
VK_RETURN (0x0D) "Enter" 0x0A for keydown,
0x0D for keypress
"Enter" 0x0A
VK_SHIFT (0x10) "Shift" null "Shift" ""
VK_CONTROL (0x11) "Control" null "Control" ""
VK_MENU (0x12) "Alt" null "Alt" ""
VK_PAUSE (0x13) "Pause" null "Pause" ""
VK_CAPITAL (0x14) "CapsLock" null "CapsLock" ""
VK_KANA,
VK_HANGUEL,
VK_HANGUL (0x15)
"KanaMode" null "KanaMode" ""
VK_JUNJA (0x17) "JunjaMode" null "JunjaMode" ""
VK_FINAL (0x18) "HanjaMode" null "HanjaMode" ""
VK_HANJA,
VK_KANJI (0x19)
"KanjiMode" null "KanjiMode" ""
VK_ESCAPE (0x1B) "Esc" 0x1B "Esc" 0x1B
VK_CONVERT (0x1C) "Convert" null "Convert" ""
VK_NONCONVERT (0x1D) "Nonconvert" null "Nonconvert" ""
VK_ACCEPT (0x1E) "Accept" null "Accept" ""
VK_MODECHANGE (0x1F) "ModeChange" null "ModeChange" ""
VK_SPACE (0x20) "Spacebar" Depends on actual inputted character "Spacebar" Depends on actual inputted character
VK_PRIOR (0x21) "PageUp" null "PageUp" ""
VK_NEXT (0x22) "PageDown" null "PageDown" ""
VK_END (0x23) "End" null "End" ""
VK_HOME (0x24) "Home" null "Home" ""
VK_LEFT (0x25) "Left" null "Left" ""
VK_UP (0x26) "Up" null "Up" ""
VK_RIGHT (0x27) "Right" null "Right" ""
VK_DOWN (0x28) "Down" null "Down" ""
VK_SELECT (0x29) "Select" null "Select" ""
VK_PRINT (0x2A) "Unidentified" null "Print" ""
VK_EXECUTE (0x2B) "Execute" null "Execute" ""
VK_SNAPSHOT (0x2C) "PrintScreen" null "PrintScreen" ""
VK_INSERT (0x2D) "Insert" null "Insert" ""
VK_DELETE (0x2E) "Del" null "Del" 0x7F
VK_HELP (0x2F) "Help" null "Help" ""
VK_LWIN (0x5B) "Win" null "OS" ""
VK_RWIN (0x5C) "Win" null "OS" ""
VK_APPS (0x5D) "Apps" null "Menu" ""
VK_SLEEP (0x5F) "Unidentified" null "Sleep" ""
VK_NUMPAD0 (0x60)VK_NUMPAD9 (0x69) "0" ~ "9" "0" ~ "9" Same as the char value Depends on actual inputted character
VK_MULTIPLY (0x6A) "Multiply" "*" "Multiply" Depends on actual inputted character
VK_ADD (0x6B) "Add" "+" "Add" Depends on actual inputted character
VK_SEPARATOR (0x6C) "Separator" null "Separator" Depends on actual inputted character
VK_SUBTRACT (0x6D) "Subtract" "-" "Subtract" Depends on actual inputted character
VK_DECIMAL (0x6E) "Decimal" "." "Decimal" Depends on actual inputted character
VK_DIVIDE (0x6F) "Divide" "/" "Divide" Depends on actual inputted character
VK_F1 (0x70)VK_F24 (0x87) "F1" ~ "F24" null "F1" ~ "F24" ""
VK_NUMLOCK (0x90) "NumLock" null "NumLock" ""
VK_SCROLL (0x91) "Scroll" null "ScrollLock" ""
VK_LSHIFT (0xA0) "Shift" null "Shift" ""
VK_RSHIFT (0xA1) "Shift" null "Shift" ""
VK_LCONTROL (0xA2) "Control" null "Control" ""
VK_RCONTROL (0xA3) "Control" null "Control" ""
VK_LMENU (0xA4) "Alt" null "Alt" ""
VK_RMENU (0xA5) "Alt" null "Alt" ""
VK_BROWSER_BACK (0xA6) "BrowserBack" null "BrowserBack" ""
VK_BROWSER_FORWARD (0xA7) "BrowserForward" null "BrowserForward" ""
VK_BROWSER_REFRESH (0xA8) "BrowserRefresh" null "BrowserRefresh" ""
VK_BROWSER_STOP (0xA9) "BrowserStop" null "BrowserStop" ""
VK_BROWSER_SEARCH (0xAA) "BrowserSearch" null "BrowserSearch" ""
VK_BROWSER_FAVORITES (0xAB) "BrowserFavorites" null "BrowserFavorites" ""
VK_BROWSER_HOME (0xAC) "BrowserHome" null "BrowserHome" ""
VK_VOLUME_MUTE (0xAD) "VolumeMute" null "VolumeMute" ""
VK_VOLUME_DOWN (0xAE) "VolumeDown" null "VolumeDown" ""
VK_VOLUME_UP (0xAF) "VolumeUp" null "VolumeUp" ""
VK_MEDIA_NEXT_TRACK (0xB0) "MediaNextTrack" null "MediaNextTrack" ""
VK_MEDIA_PREV_TRACK (0xB1) "MediaPreviousTrack" null "MediaPreviousTrack" ""
VK_MEDIA_STOP (0xB2) "MediaStop" null "MediaStop" ""
VK_MEDIA_PLAY_PAUSE (0xB3) "MediaPlayPause" null "MediaPlayPause" ""
VK_LAUNCH_MAIL (0xB4) "LaunchMail" null "LaunchMail" ""
VK_LAUNCH_MEDIA_SELECT (0xB5) "SelectMedia" null "SelectMedia" ""
VK_LAUNCH_APP1 (0xB6) "LaunchApplication1" null "LaunchApplication1" ""
VK_LAUNCH_APP2 (0xB7) "LaunchApplication2" null "LaunchApplication2" ""
VK_PROCESSKEY (0xE5) "Unidentified" (tested without IME) null "Unidentified" ""
VK_PACKET (0xE7) 0x00 (null character at 1st, tested without SendInput() API) null "Unidentified" ""
VK_ATTN (0xF6) "Attn" null "Attn" ""
VK_CRSEL (0xF7) "Crsel" null "Crsel" ""
VK_EXSEL (0xF8) "Exsel" null "Exsel" ""
VK_EREOF (0xF9) "EraseEof" null "EraseEof" ""
VK_PLAY (0xFA) "Play" null "Play" ""
VK_ZOOM (0xFB) "Zoom" null "Zoom" ""
VK_NONAME (0xFC) "Unidentified" null "Unidentified" ""
VK_PA1 (0xFD) "Unidentified" null "Unidentified" ""
VK_OEM_CLEAR (0xFE) "Clear" null "Clear" ""
key names and char values on Mac
Native virtual keycodes Gecko (plan)
kVK_ISO_Section (0x0A) "Unidentified" ""
kVK_Return (0x24) "Enter" 0x0A
kVK_Tab (0x30) "Tab" 0x09
kVK_Space (0x31) "Spacebar" Depends on actual inputted character
kVK_Delete (0x33) "Backspace" 0x08
Enter key on keypad of PowerBook (0x34) "Enter" 0x0A
kVK_Escape (0x35) "Esc" 0x1B
right-command key (0x36) "Meta" ""
kVK_Command (0x37) "Meta" ""
kVK_Shift (0x38) "Shift" ""
kVK_CapsLock (0x39) "CapsLock" ""
kVK_Option (0x3A) "Alt" ""
kVK_Control (0x3B) "Control" ""
kVK_RightShift (0x3C) "Shift" ""
kVK_RightOption (0x3D) "Alt" ""
kVK_RightControl (0x3E) "Control" ""
kVK_Function (0x3F) "Fn" ""
kVK_F17 (0x40) "F17" ""
kVK_ANSI_KeypadDecimal (0x41) "Decimal" Depends on actual inputted character
kVK_ANSI_KeypadMultiply (0x43) "Multiply" Depends on actual inputted character
kVK_ANSI_KeypadPlus (0x45) "Add" Depends on actual inputted character
kVK_ANSI_KeypadClear (0x47) "Clear" ""
kVK_VolumeUp (0x48) "VolumeUp" ""
kVK_VolumeDown (0x49) "VolumeDown" ""
kVK_Mute (0x4A) "VolumeMute" ""
kVK_ANSI_KeypadDivide (0x4B) "Divide" Depends on actual inputted character
kVK_ANSI_KeypadEnter (0x4C) "Enter" 0x0A
kVK_ANSI_KeypadMinus (0x4E) "Subtract" Depends on actual inputted character
kVK_F18 (0x4F) "F18" ""
kVK_F19 (0x50) "F19" ""
kVK_ANSI_KeypadEquals (0x51) Same as the char value Depends on actual inputted character
kVK_ANSI_Keypad0 (0x52) Same as the char value Depends on actual inputted character
kVK_ANSI_Keypad1 (0x53) Same as the char value Depends on actual inputted character
kVK_ANSI_Keypad2 (0x54) Same as the char value Depends on actual inputted character
kVK_ANSI_Keypad3 (0x55) Same as the char value Depends on actual inputted character
kVK_ANSI_Keypad4 (0x56) Same as the char value Depends on actual inputted character
kVK_ANSI_Keypad5 (0x57) Same as the char value Depends on actual inputted character
kVK_ANSI_Keypad6 (0x58) Same as the char value Depends on actual inputted character
kVK_ANSI_Keypad7 (0x59) Same as the char value Depends on actual inputted character
kVK_F20 (0x5A) "F20" ""
kVK_ANSI_Keypad8 (0x5B) Same as the char value Depends on actual inputted character
kVK_ANSI_Keypad9 (0x5C) Same as the char value Depends on actual inputted character
kVK_JIS_KeypadComma (0x5F) "Separator" Depends on actual inputted character
kVK_F5 (0x60) "F5" ""
kVK_F6 (0x61) "F6" ""
kVK_F7 (0x62) "F7" ""
kVK_F3 (0x63) "F3" ""
kVK_F8 (0x64) "F8" ""
kVK_F9 (0x65) "F9" ""
kVK_JIS_Eisu (0x66) "RomanCharacters" ""
kVK_F11 (0x67) "F11" ""
kVK_JIS_Kana (0x68) "KanjiMode" ""
kVK_F13 (0x69) "F13" ""
kVK_F16 (0x6A) "F16" ""
kVK_F14 (0x6B) "F14" ""
kVK_F10 (0x6D) "F10" ""
kVK_F12 (0x6F) "F12" ""
kVK_F15 (0x71) "F15" ""
kVK_Help (0x72) "Help" ""
kVK_Home (0x73) "Home" ""
kVK_PageUp (0x74) "PageUp" ""
kVK_ForwardDelete (0x75) "Del" 0x7F
kVK_F4 (0x76) "F4" ""
kVK_End (0x77) "End" ""
kVK_F2 (0x78) "F2" ""
kVK_PageDown (0x79) "PageDown" ""
kVK_F1 (0x7A) "F1" ""
kVK_LeftArrow (0x7B) "Left" ""
kVK_RightArrow (0x7C) "Right" ""
kVK_DownArrow (0x7D) "Down" ""
kVK_UpArrow (0x7E) "Up" ""

Specification

DOM 3 Events: KeyboardEvent

Example

<!DOCTYPE html>
<html>
<head>
<script>
var metaChar = false;
var exampleKey = 16;

function keyEvent(event) {
  var key = event.keyCode || event.which;
  var keychar = String.fromCharCode(key);
  if (key == exampleKey) {
    metaChar = true;
  }
  if (key != exampleKey) {
    if (metaChar) {
      alert("Combination of metaKey + " + keychar);
      metaChar = false;
    } else {
      alert("Key pressed " + key);
    }
  }
}

function metaKeyUp (event) {
  var key = event.keyCode || event.which;

  if (key == exampleKey) {
    metaChar = false;
  }
}
</script>
</head>

<body onkeydown="keyEvent(event)" onkeyup="metaKeyUp(event)">
</body>
</html>

Revision Source

<p><code>KeyboardEvent</code> objects describe a user interaction with the keyboard. Each event describes a key; the event type ({{domevent('keydown')}}, {{domevent('keypress')}}, or {{domevent('keyup')}}) identifies what kind of activity was performed.</p>
<div class="note">
  <strong>Note:</strong> The <code>KeyboardEvent</code> indicates just what's happening on a key. When you need to handle text input, use HTML5 <code><a href="/en-US/docs/DOM/DOM_event_reference/input" rel="custom">input</a></code> event instead. For example, if user inputs text from hand-writing system like tablet PC, key events may not be fired.</div>
<h2 id="Method_overview">Method overview</h2>
<table class="standard-table">
  <tbody>
    <tr>
      <td><code>boolean <a href="/en-US/docs/DOM/KeyboardEvent#getModifierState()" title="en-US/docs/DOM/KeyboardEvent#getModifierState()">getModifierState</a>(in DOMString keyArg);</code></td>
    </tr>
    <tr>
      <td><code>void <a href="/en-US/docs/DOM/KeyboardEvent#initKeyboardEvent()" title="en-US/docs/DOM/KeyboardEvent#initKeyboardEvent()">initKeyboardEvent</a>(in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in views::AbstractView viewArg, in DOMString charArg, in DOMString keyArg, in unsigned long locationArg, in DOMString modifiersListArg, in boolean repeat, in DOMString localeArg);</code></td>
    </tr>
  </tbody>
</table>
<h2 id="Attributes">Attributes</h2>
<table class="standard-table" style="width: auto;">
  <tbody>
    <tr>
      <td class="header">Attribute</td>
      <td class="header">Type</td>
      <td class="header">Description</td>
    </tr>
    <tr>
      <td><code>altKey</code></td>
      <td><code>boolean</code></td>
      <td><code>true</code> if the Alt (or Option, on Mac) key was active when the key event was generated. <strong>Read only.</strong></td>
    </tr>
    <tr>
      <td><code>char</code></td>
      <td><a href="/en-US/docs/DOMString" title="en-US/docs/DOMString"><code>DOMString</code></a></td>
      <td>
        <p>The character value of the key. If the key corresponds to a printable character, this value is a non-empty Unicode string containing that character. If the key doesn't have a printable representation, this is an empty string. See <a href="/en-US/docs/DOM/KeyboardEvent#Key_names_and_Char_values" title="en-US/docs/DOM/KeyboardEvent#Key_names_and_Char_values">key names and char values</a> for the detail. <strong>Read only.</strong></p>
        <div class="note">
          <strong>Note:</strong> If the key is used as a macro that inserts multiple characters, this attribute's value is the entire string, not just the first character.</div>
        <div class="geckoVersionNote" style="undefined">
          <p class="note">{{gecko_callout_unimplemented("680830")}}</p>
          <p class="note">This attribute is not implemented in Gecko at this time.</p>
        </div>
      </td>
    </tr>
    <tr>
      <td><code>charCode</code> {{deprecated_inline()}}</td>
      <td><code>unsigned long</code></td>
      <td>
        <p>The Unicode reference number of the key; this attribute is used only by the {{domevent('keypress')}} event. For keys whose <code>char</code> attribute contains multiple characters, this is the Unicode value of the first character in that attribute. <strong>Read only.</strong></p>
        <div class="warning">
          <strong>Warning:</strong> This attribute is deprecated; you should use <code>char</code> instead, if available.</div>
      </td>
    </tr>
    <tr>
      <td><code>ctrlKey</code></td>
      <td><code>boolean</code></td>
      <td><code>true</code> if the Control key was active when the key event was generated. <strong>Read only.</strong></td>
    </tr>
    <tr>
      <td><code>key</code></td>
      <td><a href="/en-US/docs/DOMString" title="en-US/docs/DOMString"><code>DOMString</code></a></td>
      <td>
        <p>The key value of the key represented by the event. If the value has a printed representation, this attribute's value is the same as the <code>char</code> attribute. Otherwise, it's one of the key value strings specified in {{anch("Key values")}}. If the key can't be identified, this is the string "Unidentified". See <a href="/en-US/docs/DOM/KeyboardEvent#Key_names_and_Char_values" title="en-US/docs/DOM/KeyboardEvent#Key_names_and_Char_values">key names and char values</a> for the detail. <strong>Read only.</strong></p>
        <div class="geckoVersionNote" style="undefined">
          <p class="note">{{gecko_callout_unimplemented("680830")}}</p>
          <p class="note">This attribute is not implemented in Gecko at this time.</p>
        </div>
      </td>
    </tr>
    <tr>
      <td><code>keyCode</code> {{deprecated_inline()}}</td>
      <td>
        <p><code>unsigned long</code></p>
      </td>
      <td>
        <p>A system and implementation dependent numerical code identifying the unmodified value of the pressed key. This is usually the decimal ASCII ({{RFC(20)}}) or Windows 1252 code corresponding to the key; see {{anch("Virtual key codes")}} for a list of Gecko's keyCode values. If the key can't be identified, this value is 0. <strong>Read only.</strong></p>
        <div class="warning">
          <strong>Warning:</strong> This attribute is deprecated; you should use <code>key</code> instead, if available.</div>
      </td>
    </tr>
    <tr>
      <td><code>locale</code></td>
      <td><a href="/en-US/docs/DOMString" title="en-US/docs/DOMString"><code>DOMString</code></a></td>
      <td>
        <p>A locale string indicating the locale the keyboard is configured for. This may be the empty string if the browser or device doesn't know the keyboard's locale. <strong>Read only.</strong></p>
        <div class="note">
          <strong>Note:</strong> This does not describe the locale of the data being entered. A user may be using one keyboard layout while typing text in a different language.</div>
      </td>
    </tr>
    <tr>
      <td>
        <p><code><a name="Attributes_location"></a></code><a name="Attributes_location"><code>location </code>{{dom_level("3")}} {{gecko_minversion_inline("15.0")}}</a></p>
      </td>
      <td><code>unsigned long</code></td>
      <td>
        <p>The location of the key on the keyboard or other input device; see {{anch("Key location constants")}} below. <strong>Read only.</strong></p>
      </td>
    </tr>
    <tr>
      <td><code>metaKey</code></td>
      <td><code>boolean</code></td>
      <td><code>true</code> if the Meta (or Command, on Mac) key was active when the key event was generated. <strong>Read only.</strong></td>
    </tr>
    <tr>
      <td><code>repeat</code></td>
      <td><code>boolean</code></td>
      <td>
        <p>true if the key is being held down such that it is automatically repeating. <strong>Read only.</strong></p>
        <div class="geckoVersionNote" style="undefined">
          <p class="note">{{gecko_callout_unimplemented("600117")}}</p>
          <p class="note">This attribute is not implemented in Gecko at this time.</p>
        </div>
      </td>
    </tr>
    <tr>
      <td><code>shiftKey</code></td>
      <td><code>boolean</code></td>
      <td><code>true</code> if the Shift key was active when the key event was generated. <strong>Read only.</strong></td>
    </tr>
    <tr>
      <td><code>which</code> {{deprecated_inline()}}</td>
      <td><code>unsigned long</code></td>
      <td>
        <p>A system and implementation dependent numeric code identifying the unmodified value of the pressed key; this is usually the same as <code>keyCode</code>. <strong>Read only.</strong></p>
        <div class="warning">
          <strong>Warning:</strong> This attribute is deprecated; you should use <code>key</code> instead, if available.</div>
      </td>
    </tr>
  </tbody>
</table>
<h2 id="Constants">Constants</h2>
<h3 id="Virtual_key_codes">Virtual key codes</h3>
<p>{{deprecated_header()}}</p>
<p>These constants represent virtual key codes as reported by the deprecated <code>keyCode</code> attribute; that is, keys that do not correspond to printable characters. The diagram below represents a standard ANSI US keyboard; Mac and most PC keyboards have the same layout for the printable characters, and a similar layout for the remaining keys.</p>
<p><img alt="" src="/@api/deki/files/5589/=KB_United_States.svg" /></p>
<p>Starting in Gecko 15 {{geckoRelease("15.0")}}, Gecko decides keycode by following rules for printable keys:</p>
<ol>
  <li>If the system is Windows and native keycode of pressed key indicates that the key is a-z or 0-9, uses a keycode for it.</li>
  <li>If the system is Mac and native keycode of pressed key indicates that the key is 0-9, uses a keycode for it.</li>
  <li>If pressed key inputs an ASCII alphabet or numeric with no modifier key, uses a keycode for it.</li>
  <li>If pressed key inputs an ASCII alphabet or numeric with Shift key, uses a keycode for it.</li>
  <li>If pressed key inputs another ASCII character with no modifier key, uses a keycode for it.</li>
  <li>If pressed key inputs another ASCII character with Shift key, users a keycode for it.</li>
  <li>Otherwise, i.e., pressed key inputs a Unicode character:
    <ol>
      <li>If the keyboard layout is ASCII capable keyboard layout (i.e., can input ASCII alphabets), uses 0.</li>
      <li>Otherwise, i.e., the keyboard layout isn't ASCII capable, using ASCII capable keyboard layout which is installed on the environment and has highest priority:
        <ol>
          <li>If pressed key on the alternative keyboard layout inputs an ASCII alphabet or numeric, uses a keycode for it.</li>
          <li>Otherwise, uses 0.</li>
        </ol>
      </li>
    </ol>
  </li>
</ol>
<div class="note">
  <strong>Note:</strong> Web developers shouldn't use keycode attribute of printable keys in keydown and keyup event handlers. As described above, keycode is not usable for checking character which will be inputted especially when Shift key or AltGr key is pressed. When web developers implement shortcut key handler, keypress event is better event for that purpose on Gecko at least. See <a href="/en-US/docs/Gecko_Keypress_Event" title="en-US/docs/Gecko_Keypress_Event">Gecko Keypress Event</a> for the detail.</div>
<table class="standard-table" style="width: auto;">
  <tbody>
    <tr>
      <td class="header">Constant</td>
      <td class="header">Value</td>
      <td class="header">Description</td>
    </tr>
    <tr>
      <td><code>DOM_VK_CANCEL</code></td>
      <td>3</td>
      <td>Cancel key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_HELP</code></td>
      <td>6</td>
      <td>Help key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_BACK_SPACE</code></td>
      <td>8</td>
      <td>Backspace key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_TAB</code></td>
      <td>9</td>
      <td>Tab key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_CLEAR</code></td>
      <td>12</td>
      <td>"5" key on Numpad when NumLock is unlocked. Or on Mac, clear key which is positioned at NumLock key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_RETURN</code></td>
      <td>13</td>
      <td>Return/enter key on the main keyboard.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_ENTER</code></td>
      <td>14</td>
      <td>Reserved, but not used.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_SHIFT</code></td>
      <td>16</td>
      <td>Shift key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_CONTROL</code></td>
      <td>17</td>
      <td>Control key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_ALT</code></td>
      <td>18</td>
      <td>Alt (Option on Mac) key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_PAUSE</code></td>
      <td>19</td>
      <td>Pause key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_CAPS_LOCK</code></td>
      <td>20</td>
      <td>Caps lock.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_ESCAPE</code></td>
      <td>27</td>
      <td>Escape key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_SPACE</code></td>
      <td>32</td>
      <td>Space bar.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_PAGE_UP</code></td>
      <td>33</td>
      <td>Page Up key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_PAGE_DOWN</code></td>
      <td>34</td>
      <td>Page Down key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_END</code></td>
      <td>35</td>
      <td>End key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_HOME</code></td>
      <td>36</td>
      <td>Home key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_LEFT</code></td>
      <td>37</td>
      <td>Left arrow.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_UP</code></td>
      <td>38</td>
      <td>Up arrow.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_RIGHT</code></td>
      <td>39</td>
      <td>Right arrow.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_DOWN</code></td>
      <td>40</td>
      <td>Down arrow.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_SELECT</code></td>
      <td>41</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_PRINT</code></td>
      <td>42</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_EXECUTE</code></td>
      <td>43</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_PRINTSCREEN</code></td>
      <td>44</td>
      <td>Print Screen key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_INSERT</code></td>
      <td>45</td>
      <td>Ins(ert) key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_DELETE</code></td>
      <td>46</td>
      <td>Del(ete) key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_0</code></td>
      <td>48</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_1</code></td>
      <td>49</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_2</code></td>
      <td>50</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_3</code></td>
      <td>51</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_4</code></td>
      <td>52</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_5</code></td>
      <td>53</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_6</code></td>
      <td>54</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_7</code></td>
      <td>55</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_8</code></td>
      <td>56</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_9</code></td>
      <td>57</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_COLON</code></td>
      <td>58</td>
      <td>Colon (":") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_SEMICOLON</code></td>
      <td>59</td>
      <td>Semicolon (";") key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_LESS_THAN</code></td>
      <td>60</td>
      <td>Less-than ("&lt;") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_EQUALS</code></td>
      <td>61</td>
      <td>Equals ("=") key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_GREATER_THAN</code></td>
      <td>62</td>
      <td>Greater-than ("&gt;") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_QUESTION_MARK</code></td>
      <td>63</td>
      <td>Question mark ("?") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_AT</code></td>
      <td>64</td>
      <td>Atmark ("@") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_A</code></td>
      <td>65</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_B</code></td>
      <td>66</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_C</code></td>
      <td>67</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_D</code></td>
      <td>68</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_E</code></td>
      <td>69</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F</code></td>
      <td>70</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_G</code></td>
      <td>71</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_H</code></td>
      <td>72</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_I</code></td>
      <td>73</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_J</code></td>
      <td>74</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_K</code></td>
      <td>75</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_L</code></td>
      <td>76</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_M</code></td>
      <td>77</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_N</code></td>
      <td>78</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_O</code></td>
      <td>79</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_P</code></td>
      <td>80</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_Q</code></td>
      <td>81</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_R</code></td>
      <td>82</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_S</code></td>
      <td>83</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_T</code></td>
      <td>84</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_U</code></td>
      <td>85</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_V</code></td>
      <td>86</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_W</code></td>
      <td>87</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_X</code></td>
      <td>88</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_Y</code></td>
      <td>89</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_Z</code></td>
      <td>90</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_CONTEXT_MENU</code></td>
      <td>93</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_NUMPAD0</code></td>
      <td>96</td>
      <td>0 on the numeric keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_NUMPAD1</code></td>
      <td>97</td>
      <td>1 on the numeric keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_NUMPAD2</code></td>
      <td>98</td>
      <td>2 on the numeric keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_NUMPAD3</code></td>
      <td>99</td>
      <td>3 on the numeric keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_NUMPAD4</code></td>
      <td>100</td>
      <td>4 on the numeric keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_NUMPAD5</code></td>
      <td>101</td>
      <td>5 on the numeric keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_NUMPAD6</code></td>
      <td>102</td>
      <td>6 on the numeric keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_NUMPAD7</code></td>
      <td>103</td>
      <td>7 on the numeric keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_NUMPAD8</code></td>
      <td>104</td>
      <td>8 on the numeric keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_NUMPAD9</code></td>
      <td>105</td>
      <td>9 on the numeric keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_MULTIPLY</code></td>
      <td>106</td>
      <td>* on the numeric keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_ADD</code></td>
      <td>107</td>
      <td>+ on the numeric keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_SEPARATOR</code></td>
      <td>108</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><code>DOM_VK_SUBTRACT</code></td>
      <td>109</td>
      <td>- on the numeric keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_DECIMAL</code></td>
      <td>110</td>
      <td>Decimal point on the numeric keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_DIVIDE</code></td>
      <td>111</td>
      <td>/ on the numeric keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F1</code></td>
      <td>112</td>
      <td>F1 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F2</code></td>
      <td>113</td>
      <td>F2 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F3</code></td>
      <td>114</td>
      <td>F3 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F4</code></td>
      <td>115</td>
      <td>F4 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F5</code></td>
      <td>116</td>
      <td>F5 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F6</code></td>
      <td>117</td>
      <td>F6 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F7</code></td>
      <td>118</td>
      <td>F7 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F8</code></td>
      <td>119</td>
      <td>F8 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F9</code></td>
      <td>120</td>
      <td>F9 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F10</code></td>
      <td>121</td>
      <td>F10 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F11</code></td>
      <td>122</td>
      <td>F11 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F12</code></td>
      <td>123</td>
      <td>F12 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F13</code></td>
      <td>124</td>
      <td>F13 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F14</code></td>
      <td>125</td>
      <td>F14 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F15</code></td>
      <td>126</td>
      <td>F15 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F16</code></td>
      <td>127</td>
      <td>F16 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F17</code></td>
      <td>128</td>
      <td>F17 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F18</code></td>
      <td>129</td>
      <td>F18 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F19</code></td>
      <td>130</td>
      <td>F19 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F20</code></td>
      <td>131</td>
      <td>F20 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F21</code></td>
      <td>132</td>
      <td>F21 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F22</code></td>
      <td>133</td>
      <td>F22 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F23</code></td>
      <td>134</td>
      <td>F23 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_F24</code></td>
      <td>135</td>
      <td>F24 key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_NUM_LOCK</code></td>
      <td>144</td>
      <td>Num Lock key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_SCROLL_LOCK</code></td>
      <td>145</td>
      <td>Scroll Lock key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_CIRCUMFLEX</code></td>
      <td>160</td>
      <td>Circumflex ("^") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_EXCLAMATION</code></td>
      <td>161</td>
      <td>Exclamation ("!") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_DOUBLE_QUOTE</code></td>
      <td>162</td>
      <td>Double quote (""") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_HASH</code></td>
      <td>163</td>
      <td>Hash ("#") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_DOLLAR</code></td>
      <td>164</td>
      <td>Dollar sign ("$") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_PERCENT</code></td>
      <td>165</td>
      <td>Percent ("%") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_AMPERSAND</code></td>
      <td>166</td>
      <td>Ampersand ("&amp;") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_UNDERSCORE</code></td>
      <td>167</td>
      <td>Underscore ("_") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_OPEN_PAREN</code></td>
      <td>168</td>
      <td>Open parenthesis ("(") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_CLOSE_PAREN</code></td>
      <td>169</td>
      <td>Close parenthesis (")") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_ASTERISK</code></td>
      <td>170</td>
      <td>Asterisk ("*") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_PLUS</code></td>
      <td>171</td>
      <td>Plus ("+") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_PIPE</code></td>
      <td>172</td>
      <td>Pipe ("|") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_HYPHEN_MINUS</code></td>
      <td>173</td>
      <td>Hyphen-US/docs/Minus ("-") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_OPEN_CURLY_BRACKET</code></td>
      <td>174</td>
      <td>Open curly bracket ("{") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_CLOSE_CURLY_BRACKET</code></td>
      <td>175</td>
      <td>Close curly bracket ("}") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_TILDE</code></td>
      <td>176</td>
      <td>Tilde ("~") key. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_COMMA</code></td>
      <td>188</td>
      <td>Comma (",") key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_PERIOD</code></td>
      <td>190</td>
      <td>Period (".") key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_SLASH</code></td>
      <td>191</td>
      <td>Slash ("/") key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_BACK_QUOTE</code></td>
      <td>192</td>
      <td>Back tick ("`") key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_OPEN_BRACKET</code></td>
      <td>219</td>
      <td>Open square bracket ("[") key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_BACK_SLASH</code></td>
      <td>220</td>
      <td>Back slash ("\") key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_CLOSE_BRACKET</code></td>
      <td>221</td>
      <td>Close square bracket ("]") key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_QUOTE</code></td>
      <td>222</td>
      <td>Quote (''') key.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_META</code></td>
      <td>224</td>
      <td>Meta key on Linux, Command key on Mac.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_ALTGR</code></td>
      <td>225</td>
      <td>AltGr key on Linux. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_WIN</code></td>
      <td>91</td>
      <td>Windows logo key on Windows. Or Super or Hyper key on Linux. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_KANA</code></td>
      <td>21</td>
      <td>Linux support for this keycode was added in Gecko 4.0.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_HANGUL</code></td>
      <td>21</td>
      <td>Linux support for this keycode was added in Gecko 4.0.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_EISU</code></td>
      <td>22</td>
      <td>"英数" key on Japanese Mac keyboard. {{gecko_minversion_inline("15.0")}}</td>
    </tr>
    <tr>
      <td><code>DOM_VK_JUNJA</code></td>
      <td>23</td>
      <td>Linux support for this keycode was added in Gecko 4.0.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_FINAL</code></td>
      <td>24</td>
      <td>Linux support for this keycode was added in Gecko 4.0.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_HANJA</code></td>
      <td>25</td>
      <td>Linux support for this keycode was added in Gecko 4.0.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_KANJI</code></td>
      <td>25</td>
      <td>Linux support for this keycode was added in Gecko 4.0.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_CONVERT</code></td>
      <td>28</td>
      <td>Linux support for this keycode was added in Gecko 4.0.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_NONCONVERT</code></td>
      <td>29</td>
      <td>Linux support for this keycode was added in Gecko 4.0.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_ACCEPT</code></td>
      <td>30</td>
      <td>Linux support for this keycode was added in Gecko 4.0.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_MODECHANGE</code></td>
      <td>31</td>
      <td>Linux support for this keycode was added in Gecko 4.0.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_SELECT</code></td>
      <td>41</td>
      <td>Linux support for this keycode was added in Gecko 4.0.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_PRINT</code></td>
      <td>42</td>
      <td>Linux support for this keycode was added in Gecko 4.0.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_EXECUTE</code></td>
      <td>43</td>
      <td>Linux support for this keycode was added in Gecko 4.0.</td>
    </tr>
    <tr>
      <td><code>DOM_VK_SLEEP</code></td>
      <td>95</td>
      <td>Linux support for this keycode was added in Gecko 4.0.</td>
    </tr>
  </tbody>
</table>
<h3 id="Key_location_constants">Key location constants</h3>
<p>These constants describe the <code>location</code> on the keyboard of key events. {{dom_level("3")}} {{gecko_minversion_inline("15.0")}}</p>
<table class="standard-table">
  <tbody>
    <tr>
      <td class="header">Constant</td>
      <td class="header">Value</td>
      <td class="header">Description</td>
    </tr>
    <tr>
      <td><code>DOM_KEY_LOCATION_STANDARD</code></td>
      <td>0</td>
      <td>The key must not be distinguished between the left and right versions of the key, and was not pressed on the numeric keypad or a key that is considered to be part of the keypad.</td>
    </tr>
    <tr>
      <td><code>DOM_KEY_LOCATION_LEFT</code></td>
      <td>1</td>
      <td>The key was the left-hand version of the key; for example, this is the value of the <code>location</code> attribute when the left-hand Control key is pressed on a standard 101 key US keyboard. This value is only used for keys that have more that one possible location on the keyboard.</td>
    </tr>
    <tr>
      <td><code>DOM_KEY_LOCATION_RIGHT</code></td>
      <td>2</td>
      <td>The key was the right-hand version of the key; for example, this is the value of the <code>location</code> attribute when the right-hand Control key is pressed on a standard 101 key US keyboard. This value is only used for keys that have more that one possible location on the keyboard.</td>
    </tr>
    <tr>
      <td><code>DOM_KEY_LOCATION_NUMPAD</code></td>
      <td>3</td>
      <td>
        <p>The key was on the numeric keypad, or has a virtual key code that corresponds to the numeric keypad.</p>
        <div class="note">
          <strong>Note:</strong> When NumLock is locked, Gecko always returns <code>DOM_KEY_LOCATION_NUMPAD</code> for the keys on NumPad. Otherwise, when NumLock is unlocked and the keyboard actually has a numeric keypad, Gecko always returns <code>DOM_KEY_LOCATION_NUMPAD</code> too. On the other hand, if the keyboard doesn't have a keypad, such as on a notebook computer, some keys become Numpad only when NumLock is locked. When such keys fires key events, the location attribute value depends on the key. That is, it must not be <code>DOM_KEY_LOCATION_NUMPAD</code>.</div>
        <div class="note">
          <strong>Note:</strong> NumLock key's key events indicate <code>DOM_KEY_LOCATION_STANDARD</code> both on Gecko and Internet Explorer.</div>
      </td>
    </tr>
    <tr>
      <td><code>DOM_KEY_LOCATION_MOBILE</code></td>
      <td>4</td>
      <td>
        <p>The key was on a mobile device; this can be on either a physical keypad or a virtual keyboard.</p>
        <div class="note">
          <strong>Note: </strong>Gecko always returns <code>DOM_KEY_LOCATION_MOBILE</code> on Android, Maemo, and <a href="/en-US/docs/Mozilla/Boot_to_Gecko" title="Boot to Gecko">Boot to Gecko</a>.</div>
      </td>
    </tr>
    <tr>
      <td><code>DOM_KEY_LOCATION_JOYSTICK</code></td>
      <td>5</td>
      <td>
        <p>The key was a button on a game controller or a joystick on a mobile device.</p>
        <div class="note">
          <strong>Note: </strong>Gecko never fires trusted key events with <code>DOM_KEY_LOCATION_JOYSTICK</code> (See {{bug("756504")}} for Android).</div>
      </td>
    </tr>
  </tbody>
</table>
<h2 id="Methods">Methods</h2>
<h3 id="getModifierState()">getModifierState()</h3>
<p>Returns the current state of the specified modifier key. {{dom_level("3")}} {{gecko_minversion_inline("15.0")}}</p>
<pre>
boolean getModifierState(
  in DOMString keyArg
);
</pre>
<h6 id="Parameters">Parameters</h6>
<dl>
  <dt>
    <code>keyArg</code></dt>
  <dd>
    A string identifying the modifier key whose value you wish to determine. This may be an implementation-defined value or one of: "Alt", "AltGraph", "CapsLock", "Control", "Fn", "Meta", "NumLock", "ScrollLock", "Shift", "SymbolLock", or "OS". Note that IE9 uses "Scroll" for "ScrollLock" and "Win" for "OS". If you use these older draft's name, Gecko's <code>getModifierState()</code> always returns <code>false</code>.</dd>
</dl>
<h6 id="Return_value">Return value</h6>
<p><code>true</code> if the specified modifier key is engaged; otherwise <code>false</code>.</p>
<div class="note">
  <table border="1" cellpadding="1" cellspacing="1" style="width:100%;">
    <caption>
      When getModifierState() returns true on Gecko?</caption>
    <thead>
      <tr>
        <th scope="row">&nbsp;</th>
        <th scope="col">Windows</th>
        <th scope="col">Linux (GTK)</th>
        <th scope="col">Mac</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">"Alt"</th>
        <td>Either Alt key or AltGr key pressed</td>
        <td>Alt key pressed</td>
        <td>option key pressed</td>
      </tr>
      <tr>
        <th scope="row">"AltGraph"</th>
        <td>
          <p>Both Alt and Ctrl keys are pressed, or AltGr key is pressed</p>
        </td>
        <td>AltGr key pressed</td>
        <td>option key pressed</td>
      </tr>
      <tr>
        <th scope="row">"CapsLock"</th>
        <td colspan="3" style="text-align:center;">During LED for Caps Lock turned on</td>
      </tr>
      <tr>
        <th scope="row">"Control"</th>
        <td>Either Ctrl key or AltGr key pressed</td>
        <td>Ctrl key pressed</td>
        <td>control key pressed</td>
      </tr>
      <tr>
        <th scope="row">"Fn"</th>
        <td colspan="3" style="background-color: rgb(211,211,211); text-align:center;"><em>Not supported</em></td>
      </tr>
      <tr>
        <th scope="row">"Meta"</th>
        <td style="background-color: rgb(211,211,211); text-align:center;"><em>Not supported</em></td>
        <td style="text-align: center;">Meta key pressed {{gecko_minversion_inline("17.0")}}</td>
        <td>command key pressed</td>
      </tr>
      <tr>
        <th scope="row">"NumLock"</th>
        <td colspan="2" style="text-align:center;">During LED for Num Lock turned on</td>
        <td>A key on numpad pressed</td>
      </tr>
      <tr>
        <th scope="row">"ScrollLock"</th>
        <td>During LED for Scroll Lock turned on</td>
        <td>During LED for Scroll Lock turned on, but typically this isn't supported by platform</td>
        <td style="background-color:#d3d3d3;"><em>Not supported</em></td>
      </tr>
      <tr>
        <th scope="row">"Shift"</th>
        <td colspan="3" rowspan="1" style="text-align:center;">Shift key pressed</td>
      </tr>
      <tr>
        <th scope="row">"SymbolLock"</th>
        <td colspan="3" style="background-color: rgb(211,211,211); text-align:center;"><em>Not supported</em></td>
      </tr>
      <tr>
        <th scope="row">"OS"</th>
        <td>Windows Logo key pressed</td>
        <td>Super key or Hyper key pressed (typically, mapped to Windows Logo key)</td>
        <td style="background-color:#d3d3d3;"><em>Not supported</em></td>
      </tr>
    </tbody>
  </table>
  <p>On the other platforms, "Alt", "Control" and "Shift" may be supported.</p>
  <p>All modifiers are always supported for untrusted events on Gecko. This doesn't depend on the platform.</p>
</div>
<h3 id="initKeyboardEvent()">initKeyboardEvent()</h3>
<p>{{deprecated_header()}}</p>
<p>Initializes the attributes of a keyboard event object. This method was introduced in draft of DOM Level 3 Events, but deprecated in newer draft. Gecko doesn't implement this method but there is similar one, see <a href="/en-US/docs/DOM/event.initKeyEvent" title="en-US/docs/DOM/event.initKeyEvent">initKeyEvent()</a>.</p>
<pre>
void initKeyboardEvent(
  in DOMString typeArg,
  in boolean canBubbleArg,
  in boolean cancelableArg,
  in views::AbstractView viewArg,
  in DOMString charArg,
  in DOMString keyArg,
  in unsigned long locationArg,
  in DOMString modifiersListArg,
  in boolean repeat,
  in DOMString localeArg
);
</pre>
<h6 id="Parameters">Parameters</h6>
<dl>
  <dt>
    <code>typeArg</code></dt>
  <dd>
    The type of keyboard event; this will be one of {{domevent('keydown')}}, {{domevent('keypress')}}, or {{domevent('keyup')}}.</dd>
  <dt>
    <code>canBubbleArg</code></dt>
  <dd>
    Whether or not the event can bubble.</dd>
  <dt>
    <code>cancelableArg</code></dt>
  <dd>
    Whether or not the event can be canceled.</dd>
  <dt>
    <code>viewArg</code></dt>
  <dd>
    ?</dd>
  <dt>
    <code>charArg</code></dt>
  <dd>
    The value of the char attribute.</dd>
  <dt>
    <code>keyArg</code></dt>
  <dd>
    The value of the key attribute.</dd>
  <dt>
    <code>locationArg</code></dt>
  <dd>
    The value of the location attribute.</dd>
  <dt>
    <code>modifiersListArg</code></dt>
  <dd>
    A whitespace-delineated list of modifier keys that should be considered to be active on the event's key. For example, specifying "Control Shift" indicates that the user was holding down the Control and Shift keys when pressing the key described by the event.</dd>
  <dt>
    <code>repeatArg</code></dt>
  <dd>
    The value of the repeat attribute.</dd>
  <dt>
    <code>localeArg</code></dt>
  <dd>
    The value of the locale attribute.</dd>
</dl>
<h2 id="Processing_of_key_events">Processing of key events</h2>
<p>There are <code>keydown</code>, <code>keypress</code>, and <code>keyup</code> events. For most keys, Gecko dispatches a sequence of key events like this:</p>
<ol>
  <li>When the key is first depressed, the <code>keydown</code> event is sent.</li>
  <li>If the key is not a modifier key, the <code>keypress</code> event is sent.</li>
  <li>When the user releases the key, the <code>keyup</code> event is sent.</li>
</ol>
<h3 id="Special_cases">Special cases</h3>
<p>Certain keys toggle the state of an LED indicator, such as Caps Lock, Num Lock, and Scroll Lock. On Windows and Linux, these keys dispatch only the <code>keydown</code> and <code>keyup</code> events. Note that on Linux, Firefox 12 and earlier also dispatched the <code>keypress</code> event for these keys.</p>
<p>On Mac, however, Caps Lock dispatches only the <code>keydown</code> event due to a platform event model limitation. Num Lock had been supported on old MacBook (2007 model and older) but Mac hasn't supported Num Lock feature even on external keyboards in these days. On the old MacBook which has Num Lock key, Num Lock doesn't cause any key events. And Gecko supports Scroll Lock key if an external keyboard which has F14 is connected. However, it generates <code>keypress</code> event. This inconsistent behavior is a bug; see {{bug(602812)}}.</p>
<h3 id="Auto-repeat_handling">Auto-repeat handling</h3>
<p>When a key is pressed and held down, it begins to auto-repeat. This results in a sequence of events similar to the following being dispatched:</p>
<ol>
  <li><code>keydown</code></li>
  <li><code>keypress</code></li>
  <li><code>keydown</code></li>
  <li><code>keypress</code></li>
  <li>&lt;&lt;repeating until the user releases the key&gt;&gt;</li>
  <li><code>keyup</code></li>
</ol>
<p>This is what the DOM Level 3 specification says should happen. There are some caveats, however, as described below.</p>
<h4 id="Auto-repeat_on_some_GTK_environments_such_as_Ubuntu_9.4">Auto-repeat on some GTK environments such as Ubuntu 9.4</h4>
<p>In some GTK-based environments, auto-repeat dispatches a native key-up event automatically during auto-repeat, and there's no way for Gecko to know the difference between a repeated series of keypresses and an auto-repeat. On those platforms, then, an auto-repeat key will generate the following sequence of events:</p>
<ol>
  <li><code>keydown</code></li>
  <li><code>keypress</code></li>
  <li><code>keyup</code></li>
  <li><code>keydown</code></li>
  <li><code>keypress</code></li>
  <li><code>keyup</code></li>
  <li>&lt;&lt;repeating until the user releases the key&gt;&gt;</li>
  <li><code>keyup</code></li>
</ol>
<p>In these environments, unfortunately, there's no way for web content to tell the difference between auto-repeating keys and keys that are just being pressed repeatedly.</p>
<h4 id="Auto-repeat_handling_prior_to_Gecko_4.0">Auto-repeat handling prior to Gecko 4.0</h4>
<p>Before Gecko 4.0 {{geckoRelease('4.0')}}, keyboard handling was less consistent across platforms.</p>
<dl>
  <dt>
    Windows</dt>
  <dd>
    Auto-repeat behavior is the same as in Gecko 4.0 and later.</dd>
  <dt>
    Mac</dt>
  <dd>
    After the initial keydown event, only keypress events are sent until the keyup event occurs; the inter-spaced keydown events are not sent.</dd>
  <dt>
    Linux</dt>
  <dd>
    The event behavior depends on the specific platform. It will either behave like Windows or Mac depending on what the native event model does.</dd>
</dl>
<h2 id="Key_names_and_Char_values">Key names and Char values</h2>
<p>Following tables show what key and char values are used for each native virtual keycode. The information for Gecko is currently planned in {{ bug(680830) }}.</p>
<table align="center" border="1" cellpadding="1" cellspacing="1" style="width:100%;">
  <caption>
    key names and char values on Windows</caption>
  <thead>
    <tr>
      <th scope="row"><a class="external" href="http://msdn.microsoft.com/en-us/library/dd375731%28v=VS.85%29.aspx" title="http://msdn.microsoft.com/en-us/library/dd375731%28v=VS.85%29.aspx">Virtual-Key Codes</a></th>
      <th colspan="2" rowspan="1" scope="col">IE 9</th>
      <th colspan="2" rowspan="1" scope="col">Gecko (plan)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row"><code>VK_LBUTTON (0x01)</code></th>
      <td><code>"Unidentified"</code></td>
      <td><code>null</code></td>
      <td><code>"Unidentified"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_RBUTTON (0x02)</code></th>
      <td><code>"Unidentified"</code></td>
      <td><code>null</code></td>
      <td><code>"Unidentified"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_CANCEL (0x03)</code></th>
      <td style="background-color: rgb(255, 255, 204);"><code>""</code></td>
      <td style="background-color: rgb(255, 255, 204);"><code>0x03</code></td>
      <td style="background-color: rgb(255, 255, 204);"><code>"Cancel"</code></td>
      <td style="background-color: rgb(255, 255, 204);"><code>0x18</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_MBUTTON (0x04)</code></th>
      <td><code>"Unidentified"</code></td>
      <td><code>null</code></td>
      <td><code>"Unidentified"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_XBUTTON1 (0x05)</code></th>
      <td><code>"Unidentified"</code></td>
      <td><code>null</code></td>
      <td><code>"Unidentified"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_XBUTTON2 (0x06)</code></th>
      <td><code>"Unidentified"</code></td>
      <td><code>null</code></td>
      <td><code>"Unidentified"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_BACK (0x08)</code></th>
      <td><code>"Backspace"</code></td>
      <td><code>0x08</code></td>
      <td><code>"Backspace"</code></td>
      <td><code>0x08</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_TAB (0x09)</code></th>
      <td><code>"Tab"</code></td>
      <td><code>0x09</code></td>
      <td><code>"Tab"</code></td>
      <td><code>0x09</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_CLEAR (0x0C)</code></th>
      <td><code>"Clear"</code></td>
      <td><code>null</code></td>
      <td><code>"Clear"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_RETURN (0x0D)</code></th>
      <td><code>"Enter"</code></td>
      <td style="background-color: rgb(255, 255, 204);"><code>0x0A</code> for <code>keydown</code>,<br />
        <code>0x0D</code> for <code>keypress</code></td>
      <td><code>"Enter"</code></td>
      <td style="background-color: rgb(255, 255, 204);">0x0A</td>
    </tr>
    <tr>
      <th scope="row"><code>VK_SHIFT (0x10)</code></th>
      <td><code>"Shift"</code></td>
      <td><code>null</code></td>
      <td><code>"Shift"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_CONTROL (0x11)</code></th>
      <td><code>"Control"</code></td>
      <td><code>null</code></td>
      <td><code>"Control"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_MENU (0x12)</code></th>
      <td><code>"Alt"</code></td>
      <td><code>null</code></td>
      <td><code>"Alt"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_PAUSE (0x13)</code></th>
      <td><code>"Pause"</code></td>
      <td><code>null</code></td>
      <td><code>"Pause"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_CAPITAL (0x14)</code></th>
      <td><code>"CapsLock"</code></td>
      <td><code>null</code></td>
      <td><code>"CapsLock"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_KANA,<br />
        VK_HANGUEL,<br />
        VK_HANGUL (0x15)</code></th>
      <td><code>"KanaMode"</code></td>
      <td><code>null</code></td>
      <td><code>"KanaMode"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_JUNJA (0x17)</code></th>
      <td><code>"JunjaMode"</code></td>
      <td><code>null</code></td>
      <td><code>"JunjaMode"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_FINAL (0x18)</code></th>
      <td><code>"HanjaMode"</code></td>
      <td><code>null</code></td>
      <td><code>"HanjaMode"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_HANJA,<br />
        VK_KANJI (0x19)</code></th>
      <td><code>"KanjiMode"</code></td>
      <td><code>null</code></td>
      <td><code>"KanjiMode"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_ESCAPE (0x1B)</code></th>
      <td><code>"Esc"</code></td>
      <td><code>0x1B</code></td>
      <td><code>"Esc"</code></td>
      <td><code>0x1B</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_CONVERT (0x1C)</code></th>
      <td><code>"Convert"</code></td>
      <td><code>null</code></td>
      <td><code>"Convert"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_NONCONVERT (0x1D)</code></th>
      <td><code>"Nonconvert"</code></td>
      <td><code>null</code></td>
      <td><code>"Nonconvert"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_ACCEPT (0x1E)</code></th>
      <td><code>"Accept"</code></td>
      <td><code>null</code></td>
      <td><code>"Accept"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_MODECHANGE (0x1F)</code></th>
      <td><code>"ModeChange"</code></td>
      <td><code>null</code></td>
      <td><code>"ModeChange"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_SPACE (0x20)</code></th>
      <td><code>"Spacebar"</code></td>
      <td>Depends on actual inputted character</td>
      <td><code>"Spacebar"</code></td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>VK_PRIOR (0x21)</code></th>
      <td><code>"PageUp"</code></td>
      <td><code>null</code></td>
      <td><code>"PageUp"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_NEXT (0x22)</code></th>
      <td><code>"PageDown"</code></td>
      <td><code>null</code></td>
      <td><code>"PageDown"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_END (0x23)</code></th>
      <td><code>"End"</code></td>
      <td><code>null</code></td>
      <td><code>"End"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_HOME (0x24)</code></th>
      <td><code>"Home"</code></td>
      <td><code>null</code></td>
      <td><code>"Home"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_LEFT (0x25)</code></th>
      <td><code>"Left"</code></td>
      <td><code>null</code></td>
      <td><code>"Left"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_UP (0x26)</code></th>
      <td><code>"Up"</code></td>
      <td><code>null</code></td>
      <td><code>"Up"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_RIGHT (0x27)</code></th>
      <td><code>"Right"</code></td>
      <td><code>null</code></td>
      <td><code>"Right"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_DOWN (0x28)</code></th>
      <td><code>"Down"</code></td>
      <td><code>null</code></td>
      <td><code>"Down"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_SELECT (0x29)</code></th>
      <td><code>"Select"</code></td>
      <td><code>null</code></td>
      <td><code>"Select"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_PRINT (0x2A)</code></th>
      <td><code>"Unidentified"</code></td>
      <td><code>null</code></td>
      <td><code>"Print"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_EXECUTE (0x2B)</code></th>
      <td><code>"Execute"</code></td>
      <td><code>null</code></td>
      <td><code>"Execute"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_SNAPSHOT (0x2C)</code></th>
      <td><code>"PrintScreen"</code></td>
      <td><code>null</code></td>
      <td><code>"PrintScreen"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_INSERT (0x2D)</code></th>
      <td><code>"Insert"</code></td>
      <td><code>null</code></td>
      <td><code>"Insert"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_DELETE (0x2E)</code></th>
      <td><code>"Del"</code></td>
      <td style="background-color: rgb(255, 255, 204);"><code>null</code></td>
      <td><code>"Del"</code></td>
      <td style="background-color: rgb(255, 255, 204);"><code>0x7F</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_HELP (0x2F)</code></th>
      <td><code>"Help"</code></td>
      <td><code>null</code></td>
      <td><code>"Help"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_LWIN (0x5B)</code></th>
      <td><code>"Win"</code></td>
      <td><code>null</code></td>
      <td><code>"OS"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_RWIN (0x5C)</code></th>
      <td><code>"Win"</code></td>
      <td><code>null</code></td>
      <td><code>"OS"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_APPS (0x5D)</code></th>
      <td style="background-color: rgb(255, 255, 204);"><code>"Apps"</code></td>
      <td><code>null</code></td>
      <td style="background-color: rgb(255, 255, 204);"><code>"Menu"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_SLEEP (0x5F)</code></th>
      <td><code>"Unidentified"</code></td>
      <td><code>null</code></td>
      <td><code>"Sleep"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_NUMPAD0 (0x60)</code> ~ <code>VK_NUMPAD9 (0x69)</code></th>
      <td><code>"0" ~ "9"</code></td>
      <td><code>"0" ~ "9"</code></td>
      <td>Same as the char value</td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>VK_MULTIPLY (0x6A)</code></th>
      <td><code>"Multiply"</code></td>
      <td><code>"*"</code></td>
      <td><code>"Multiply"</code></td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>VK_ADD (0x6B)</code></th>
      <td><code>"Add"</code></td>
      <td><code>"+"</code></td>
      <td><code>"Add"</code></td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>VK_SEPARATOR (0x6C)</code></th>
      <td><code>"Separator"</code></td>
      <td><code>null</code></td>
      <td><code>"Separator"</code></td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>VK_SUBTRACT (0x6D)</code></th>
      <td><code>"Subtract"</code></td>
      <td><code>"-"</code></td>
      <td><code>"Subtract"</code></td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>VK_DECIMAL (0x6E)</code></th>
      <td><code>"Decimal"</code></td>
      <td><code>"."</code></td>
      <td><code>"Decimal"</code></td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>VK_DIVIDE (0x6F)</code></th>
      <td><code>"Divide"</code></td>
      <td><code>"/"</code></td>
      <td><code>"Divide"</code></td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>VK_F1 (0x70)</code> ~ <code>VK_F24 (0x87)</code></th>
      <td><code>"F1" ~ "F24"</code></td>
      <td><code>null</code></td>
      <td><code>"F1" ~ "F24"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_NUMLOCK (0x90)</code></th>
      <td><code>"NumLock"</code></td>
      <td><code>null</code></td>
      <td><code>"NumLock"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_SCROLL (0x91)</code></th>
      <td><code>"Scroll"</code></td>
      <td><code>null</code></td>
      <td><code>"ScrollLock"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_LSHIFT (0xA0)</code></th>
      <td><code>"Shift"</code></td>
      <td><code>null</code></td>
      <td><code>"Shift"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_RSHIFT (0xA1)</code></th>
      <td><code>"Shift"</code></td>
      <td><code>null</code></td>
      <td><code>"Shift"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_LCONTROL (0xA2)</code></th>
      <td><code>"Control"</code></td>
      <td><code>null</code></td>
      <td><code>"Control"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_RCONTROL (0xA3)</code></th>
      <td><code>"Control"</code></td>
      <td><code>null</code></td>
      <td><code>"Control"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_LMENU (0xA4)</code></th>
      <td><code>"Alt"</code></td>
      <td><code>null</code></td>
      <td><code>"Alt"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_RMENU (0xA5)</code></th>
      <td><code>"Alt"</code></td>
      <td><code>null</code></td>
      <td><code>"Alt"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_BROWSER_BACK (0xA6)</code></th>
      <td><code>"BrowserBack"</code></td>
      <td><code>null</code></td>
      <td><code>"BrowserBack"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_BROWSER_FORWARD (0xA7)</code></th>
      <td><code>"BrowserForward"</code></td>
      <td><code>null</code></td>
      <td><code>"BrowserForward"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_BROWSER_REFRESH (0xA8)</code></th>
      <td><code>"BrowserRefresh"</code></td>
      <td><code>null</code></td>
      <td><code>"BrowserRefresh"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_BROWSER_STOP (0xA9)</code></th>
      <td><code>"BrowserStop"</code></td>
      <td><code>null</code></td>
      <td><code>"BrowserStop"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_BROWSER_SEARCH (0xAA)</code></th>
      <td><code>"BrowserSearch"</code></td>
      <td><code>null</code></td>
      <td><code>"BrowserSearch"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_BROWSER_FAVORITES (0xAB)</code></th>
      <td><code>"BrowserFavorites"</code></td>
      <td><code>null</code></td>
      <td><code>"BrowserFavorites"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_BROWSER_HOME (0xAC)</code></th>
      <td><code>"BrowserHome"</code></td>
      <td><code>null</code></td>
      <td><code>"BrowserHome"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_VOLUME_MUTE (0xAD)</code></th>
      <td><code>"VolumeMute"</code></td>
      <td><code>null</code></td>
      <td><code>"VolumeMute"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_VOLUME_DOWN (0xAE)</code></th>
      <td><code>"VolumeDown"</code></td>
      <td><code>null</code></td>
      <td><code>"VolumeDown"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_VOLUME_UP (0xAF)</code></th>
      <td><code>"VolumeUp"</code></td>
      <td><code>null</code></td>
      <td><code>"VolumeUp"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_MEDIA_NEXT_TRACK (0xB0)</code></th>
      <td><code>"MediaNextTrack"</code></td>
      <td><code>null</code></td>
      <td><code>"MediaNextTrack"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_MEDIA_PREV_TRACK (0xB1)</code></th>
      <td><code>"MediaPreviousTrack"</code></td>
      <td><code>null</code></td>
      <td><code>"MediaPreviousTrack</code><code>"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_MEDIA_STOP (0xB2)</code></th>
      <td><code>"MediaStop"</code></td>
      <td><code>null</code></td>
      <td><code>"MediaStop"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_MEDIA_PLAY_PAUSE (0xB3)</code></th>
      <td><code>"MediaPlayPause"</code></td>
      <td><code>null</code></td>
      <td><code>"MediaPlayPause"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_LAUNCH_MAIL (0xB4)</code></th>
      <td><code>"LaunchMail"</code></td>
      <td><code>null</code></td>
      <td><code>"LaunchMail"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_LAUNCH_MEDIA_SELECT (0xB5)</code></th>
      <td><code>"SelectMedia"</code></td>
      <td><code>null</code></td>
      <td><code>"SelectMedia"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_LAUNCH_APP1 (0xB6)</code></th>
      <td><code>"LaunchApplication1"</code></td>
      <td><code>null</code></td>
      <td><code>"LaunchApplication1"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_LAUNCH_APP2 (0xB7)</code></th>
      <td><code>"LaunchApplication2"</code></td>
      <td><code>null</code></td>
      <td><code>"LaunchApplication2"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_PROCESSKEY (0xE5)</code></th>
      <td><code>"Unidentified"</code> (tested without IME)</td>
      <td><code>null</code></td>
      <td><code>"Unidentified"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_PACKET (0xE7)</code></th>
      <td style="background-color: rgb(255, 255, 204);"><code>0x00 </code>(<code>null</code> character at 1st, tested without <code>SendInput()</code> API)</td>
      <td><code>null</code></td>
      <td style="background-color: rgb(255, 255, 204);"><code>"Unidentified"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_ATTN (0xF6)</code></th>
      <td><code>"Attn"</code></td>
      <td><code>null</code></td>
      <td><code>"Attn"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_CRSEL (0xF7)</code></th>
      <td><code>"Crsel"</code></td>
      <td><code>null</code></td>
      <td><code>"Crsel"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_EXSEL (0xF8)</code></th>
      <td><code>"Exsel"</code></td>
      <td><code>null</code></td>
      <td><code>"Exsel"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_EREOF (0xF9)</code></th>
      <td><code>"EraseEof"</code></td>
      <td><code>null</code></td>
      <td><code>"EraseEof"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_PLAY (0xFA)</code></th>
      <td><code>"Play"</code></td>
      <td><code>null</code></td>
      <td><code>"Play"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_ZOOM (0xFB)</code></th>
      <td><code>"Zoom"</code></td>
      <td><code>null</code></td>
      <td><code>"Zoom"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_NONAME (0xFC)</code></th>
      <td><code>"Unidentified"</code></td>
      <td><code>null</code></td>
      <td><code>"Unidentified"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_PA1 (0xFD)</code></th>
      <td><code>"Unidentified"</code></td>
      <td><code>null</code></td>
      <td><code>"Unidentified"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>VK_OEM_CLEAR (0xFE)</code></th>
      <td><code>"Clear"</code></td>
      <td><code>null</code></td>
      <td><code>"Clear"</code></td>
      <td><code>""</code></td>
    </tr>
  </tbody>
</table>
<table align="center" border="1" cellpadding="1" cellspacing="1" style="width:100%;">
  <caption>
    key names and char values on Mac</caption>
  <thead>
    <tr>
      <th scope="row">Native virtual keycodes</th>
      <th colspan="2" rowspan="1" scope="col">Gecko (plan)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row"><code>kVK_ISO_Section (0x0A)</code></th>
      <td><code>"Unidentified"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_Return (0x24)</code></th>
      <td><code>"Enter"</code></td>
      <td><code>0x0A</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_Tab (0x30)</code></th>
      <td><code>"Tab"</code></td>
      <td><code>0x09</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_Space (0x31)</code></th>
      <td><code>"Spacebar"</code></td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_Delete (0x33)</code></th>
      <td><code>"Backspace"</code></td>
      <td><code>0x08</code></td>
    </tr>
    <tr>
      <th scope="row">Enter key on keypad of PowerBook (<code>0x34</code>)</th>
      <td><code>"Enter"</code></td>
      <td><code>0x0A</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_Escape (0x35)</code></th>
      <td><code>"Esc"</code></td>
      <td><code>0x1B</code></td>
    </tr>
    <tr>
      <th scope="row">right-command key (<code>0x36</code>)</th>
      <td><code>"Meta"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_Command (0x37)</code></th>
      <td><code>"Meta"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_Shift (0x38)</code></th>
      <td><code>"Shift"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_CapsLock (0x39)</code></th>
      <td><code>"CapsLock"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_Option (0x3A)</code></th>
      <td><code>"Alt"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_Control (0x3B)</code></th>
      <td><code>"Control"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_RightShift (0x3C)</code></th>
      <td><code>"Shift"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_RightOption (0x3D)</code></th>
      <td><code>"Alt"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_RightControl (0x3E)</code></th>
      <td><code>"Control"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_Function (0x3F)</code></th>
      <td><code>"Fn"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F17 (0x40)</code></th>
      <td><code>"F17"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_KeypadDecimal (0x41)</code></th>
      <td><code>"Decimal"</code></td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_KeypadMultiply (0x43)</code></th>
      <td><code>"Multiply"</code></td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_KeypadPlus (0x45)</code></th>
      <td><code>"Add"</code></td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_KeypadClear (0x47)</code></th>
      <td><code>"Clear"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_VolumeUp (0x48)</code></th>
      <td><code>"VolumeUp"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_VolumeDown (0x49)</code></th>
      <td><code>"VolumeDown"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_Mute (0x4A)</code></th>
      <td><code>"VolumeMute"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_KeypadDivide (0x4B)</code></th>
      <td><code>"Divide"</code></td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_KeypadEnter (0x4C)</code></th>
      <td><code>"Enter"</code></td>
      <td><code>0x0A</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_KeypadMinus (0x4E)</code></th>
      <td><code>"Subtract"</code></td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F18 (0x4F)</code></th>
      <td><code>"F18"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F19 (0x50)</code></th>
      <td><code>"F19"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_KeypadEquals (0x51)</code></th>
      <td>Same as the char value</td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_Keypad0 (0x52)</code></th>
      <td>Same as the char value</td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_Keypad1 (0x53)</code></th>
      <td>Same as the char value</td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_Keypad2 (0x54)</code></th>
      <td>Same as the char value</td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_Keypad3 (0x55)</code></th>
      <td>Same as the char value</td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_Keypad4 (0x56)</code></th>
      <td>Same as the char value</td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_Keypad5 (0x57)</code></th>
      <td>Same as the char value</td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_Keypad6 (0x58)</code></th>
      <td>Same as the char value</td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_Keypad7 (0x59)</code></th>
      <td>Same as the char value</td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F20 (0x5A)</code></th>
      <td><code>"F20"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_Keypad8 (0x5B)</code></th>
      <td>Same as the char value</td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ANSI_Keypad9 (0x5C)</code></th>
      <td>Same as the char value</td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_JIS_KeypadComma (0x5F)</code></th>
      <td><code>"Separator"</code></td>
      <td>Depends on actual inputted character</td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F5 (0x60)</code></th>
      <td><code>"F5"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F6 (0x61)</code></th>
      <td><code>"F6"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F7 (0x62)</code></th>
      <td><code>"F7"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F3 (0x63)</code></th>
      <td><code>"F3"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F8 (0x64)</code></th>
      <td><code>"F8"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F9 (0x65)</code></th>
      <td><code>"F9"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_JIS_Eisu (0x66)</code></th>
      <td><code>"RomanCharacters"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F11 (0x67)</code></th>
      <td><code>"F11"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_JIS_Kana (0x68)</code></th>
      <td><code>"KanjiMode"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F13 (0x69)</code></th>
      <td><code>"F13"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F16 (0x6A)</code></th>
      <td><code>"F16"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F14 (0x6B)</code></th>
      <td><code>"F14"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F10 (0x6D)</code></th>
      <td><code>"F10"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F12 (0x6F)</code></th>
      <td><code>"F12"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F15 (0x71)</code></th>
      <td><code>"F15"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_Help (0x72)</code></th>
      <td><code>"Help"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_Home (0x73)</code></th>
      <td><code>"Home"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_PageUp (0x74)</code></th>
      <td><code>"PageUp"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_ForwardDelete (0x75)</code></th>
      <td><code>"Del"</code></td>
      <td><code>0x7F</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F4 (0x76)</code></th>
      <td><code>"F4"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_End (0x77)</code></th>
      <td><code>"End"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F2 (0x78)</code></th>
      <td><code>"F2"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_PageDown (0x79)</code></th>
      <td><code>"PageDown"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_F1 (0x7A)</code></th>
      <td><code>"F1"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_LeftArrow (0x7B)</code></th>
      <td><code>"Left"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_RightArrow (0x7C)</code></th>
      <td><code>"Right"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_DownArrow (0x7D)</code></th>
      <td><code>"Down"</code></td>
      <td><code>""</code></td>
    </tr>
    <tr>
      <th scope="row"><code>kVK_UpArrow (0x7E)</code></th>
      <td><code>"Up"</code></td>
      <td><code>""</code></td>
    </tr>
  </tbody>
</table>
<h2 id="Specification">Specification</h2>
<p><a class="external" href="http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent" title="http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent">DOM 3 Events: KeyboardEvent</a></p>
<h2 id="Example">Example</h2>
<pre class="brush: html">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;script&gt;
var metaChar = false;
var exampleKey = 16;

function keyEvent(event) {
  var key = event.keyCode || event.which;
  var keychar = String.fromCharCode(key);
  if (key == exampleKey) {
    metaChar = true;
  }
  if (key != exampleKey) {
    if (metaChar) {
      alert("Combination of metaKey + " + keychar);
      metaChar = false;
    } else {
      alert("Key pressed " + key);
    }
  }
}

function metaKeyUp (event) {
  var key = event.keyCode || event.which;

  if (key == exampleKey) {
    metaChar = false;
  }
}
&lt;/script&gt;
&lt;/head&gt;

&lt;body onkeydown="keyEvent(event)" onkeyup="metaKeyUp(event)"&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
Revert to this revision