KeyboardEvent objects describe a user interaction with the keyboard; each event describes a single interaction between the user and a key (or combination of a key with modifier keys) on the keyboard.

Documentation KeyboardEvent by Mozilla Contributors, licensed under CC-BY-SA 2.5.

See also:

Static variables

@:value(1)staticinlineread onlyDOM_KEY_LOCATION_LEFT:Int = 1

@:value(3)staticinlineread onlyDOM_KEY_LOCATION_NUMPAD:Int = 3

@:value(2)staticinlineread onlyDOM_KEY_LOCATION_RIGHT:Int = 2

@:value(0)staticinlineread onlyDOM_KEY_LOCATION_STANDARD:Int = 0

@:value(48)staticinlineread onlyDOM_VK_0:Int = 48

@:value(49)staticinlineread onlyDOM_VK_1:Int = 49

@:value(50)staticinlineread onlyDOM_VK_2:Int = 50

@:value(51)staticinlineread onlyDOM_VK_3:Int = 51

@:value(52)staticinlineread onlyDOM_VK_4:Int = 52

@:value(53)staticinlineread onlyDOM_VK_5:Int = 53

@:value(54)staticinlineread onlyDOM_VK_6:Int = 54

@:value(55)staticinlineread onlyDOM_VK_7:Int = 55

@:value(56)staticinlineread onlyDOM_VK_8:Int = 56

@:value(57)staticinlineread onlyDOM_VK_9:Int = 57

@:value(65)staticinlineread onlyDOM_VK_A:Int = 65

@:value(30)staticinlineread onlyDOM_VK_ACCEPT:Int = 30

@:value(107)staticinlineread onlyDOM_VK_ADD:Int = 107

@:value(18)staticinlineread onlyDOM_VK_ALT:Int = 18

@:value(225)staticinlineread onlyDOM_VK_ALTGR:Int = 225

@:value(166)staticinlineread onlyDOM_VK_AMPERSAND:Int = 166

@:value(170)staticinlineread onlyDOM_VK_ASTERISK:Int = 170

@:value(64)staticinlineread onlyDOM_VK_AT:Int = 64

@:value(246)staticinlineread onlyDOM_VK_ATTN:Int = 246

@:value(66)staticinlineread onlyDOM_VK_B:Int = 66

@:value(192)staticinlineread onlyDOM_VK_BACK_QUOTE:Int = 192

@:value(220)staticinlineread onlyDOM_VK_BACK_SLASH:Int = 220

@:value(8)staticinlineread onlyDOM_VK_BACK_SPACE:Int = 8

@:value(67)staticinlineread onlyDOM_VK_C:Int = 67

@:value(3)staticinlineread onlyDOM_VK_CANCEL:Int = 3

@:value(20)staticinlineread onlyDOM_VK_CAPS_LOCK:Int = 20

@:value(160)staticinlineread onlyDOM_VK_CIRCUMFLEX:Int = 160

@:value(12)staticinlineread onlyDOM_VK_CLEAR:Int = 12

@:value(221)staticinlineread onlyDOM_VK_CLOSE_BRACKET:Int = 221

@:value(175)staticinlineread onlyDOM_VK_CLOSE_CURLY_BRACKET:Int = 175

@:value(169)staticinlineread onlyDOM_VK_CLOSE_PAREN:Int = 169

@:value(58)staticinlineread onlyDOM_VK_COLON:Int = 58

@:value(188)staticinlineread onlyDOM_VK_COMMA:Int = 188

@:value(93)staticinlineread onlyDOM_VK_CONTEXT_MENU:Int = 93

@:value(17)staticinlineread onlyDOM_VK_CONTROL:Int = 17

@:value(28)staticinlineread onlyDOM_VK_CONVERT:Int = 28

@:value(247)staticinlineread onlyDOM_VK_CRSEL:Int = 247

@:value(68)staticinlineread onlyDOM_VK_D:Int = 68

@:value(110)staticinlineread onlyDOM_VK_DECIMAL:Int = 110

@:value(46)staticinlineread onlyDOM_VK_DELETE:Int = 46

@:value(111)staticinlineread onlyDOM_VK_DIVIDE:Int = 111

@:value(164)staticinlineread onlyDOM_VK_DOLLAR:Int = 164

@:value(162)staticinlineread onlyDOM_VK_DOUBLE_QUOTE:Int = 162

@:value(40)staticinlineread onlyDOM_VK_DOWN:Int = 40

@:value(69)staticinlineread onlyDOM_VK_E:Int = 69

@:value(22)staticinlineread onlyDOM_VK_EISU:Int = 22

@:value(35)staticinlineread onlyDOM_VK_END:Int = 35

@:value(61)staticinlineread onlyDOM_VK_EQUALS:Int = 61

@:value(249)staticinlineread onlyDOM_VK_EREOF:Int = 249

@:value(27)staticinlineread onlyDOM_VK_ESCAPE:Int = 27

@:value(161)staticinlineread onlyDOM_VK_EXCLAMATION:Int = 161

@:value(43)staticinlineread onlyDOM_VK_EXECUTE:Int = 43

@:value(248)staticinlineread onlyDOM_VK_EXSEL:Int = 248

@:value(70)staticinlineread onlyDOM_VK_F:Int = 70

@:value(112)staticinlineread onlyDOM_VK_F1:Int = 112

@:value(121)staticinlineread onlyDOM_VK_F10:Int = 121

@:value(122)staticinlineread onlyDOM_VK_F11:Int = 122

@:value(123)staticinlineread onlyDOM_VK_F12:Int = 123

@:value(124)staticinlineread onlyDOM_VK_F13:Int = 124

@:value(125)staticinlineread onlyDOM_VK_F14:Int = 125

@:value(126)staticinlineread onlyDOM_VK_F15:Int = 126

@:value(127)staticinlineread onlyDOM_VK_F16:Int = 127

@:value(128)staticinlineread onlyDOM_VK_F17:Int = 128

@:value(129)staticinlineread onlyDOM_VK_F18:Int = 129

@:value(130)staticinlineread onlyDOM_VK_F19:Int = 130

@:value(113)staticinlineread onlyDOM_VK_F2:Int = 113

@:value(131)staticinlineread onlyDOM_VK_F20:Int = 131

@:value(132)staticinlineread onlyDOM_VK_F21:Int = 132

@:value(133)staticinlineread onlyDOM_VK_F22:Int = 133

@:value(134)staticinlineread onlyDOM_VK_F23:Int = 134

@:value(135)staticinlineread onlyDOM_VK_F24:Int = 135

@:value(114)staticinlineread onlyDOM_VK_F3:Int = 114

@:value(115)staticinlineread onlyDOM_VK_F4:Int = 115

@:value(116)staticinlineread onlyDOM_VK_F5:Int = 116

@:value(117)staticinlineread onlyDOM_VK_F6:Int = 117

@:value(118)staticinlineread onlyDOM_VK_F7:Int = 118

@:value(119)staticinlineread onlyDOM_VK_F8:Int = 119

@:value(120)staticinlineread onlyDOM_VK_F9:Int = 120

@:value(24)staticinlineread onlyDOM_VK_FINAL:Int = 24

@:value(71)staticinlineread onlyDOM_VK_G:Int = 71

@:value(62)staticinlineread onlyDOM_VK_GREATER_THAN:Int = 62

@:value(72)staticinlineread onlyDOM_VK_H:Int = 72

@:value(21)staticinlineread onlyDOM_VK_HANGUL:Int = 21

@:value(25)staticinlineread onlyDOM_VK_HANJA:Int = 25

@:value(163)staticinlineread onlyDOM_VK_HASH:Int = 163

@:value(6)staticinlineread onlyDOM_VK_HELP:Int = 6

@:value(36)staticinlineread onlyDOM_VK_HOME:Int = 36

@:value(173)staticinlineread onlyDOM_VK_HYPHEN_MINUS:Int = 173

@:value(73)staticinlineread onlyDOM_VK_I:Int = 73

@:value(45)staticinlineread onlyDOM_VK_INSERT:Int = 45

@:value(74)staticinlineread onlyDOM_VK_J:Int = 74

@:value(23)staticinlineread onlyDOM_VK_JUNJA:Int = 23

@:value(75)staticinlineread onlyDOM_VK_K:Int = 75

@:value(21)staticinlineread onlyDOM_VK_KANA:Int = 21

@:value(25)staticinlineread onlyDOM_VK_KANJI:Int = 25

@:value(76)staticinlineread onlyDOM_VK_L:Int = 76

@:value(37)staticinlineread onlyDOM_VK_LEFT:Int = 37

@:value(60)staticinlineread onlyDOM_VK_LESS_THAN:Int = 60

@:value(77)staticinlineread onlyDOM_VK_M:Int = 77

@:value(224)staticinlineread onlyDOM_VK_META:Int = 224

@:value(31)staticinlineread onlyDOM_VK_MODECHANGE:Int = 31

@:value(106)staticinlineread onlyDOM_VK_MULTIPLY:Int = 106

@:value(78)staticinlineread onlyDOM_VK_N:Int = 78

@:value(29)staticinlineread onlyDOM_VK_NONCONVERT:Int = 29

@:value(96)staticinlineread onlyDOM_VK_NUMPAD0:Int = 96

@:value(97)staticinlineread onlyDOM_VK_NUMPAD1:Int = 97

@:value(98)staticinlineread onlyDOM_VK_NUMPAD2:Int = 98

@:value(99)staticinlineread onlyDOM_VK_NUMPAD3:Int = 99

@:value(100)staticinlineread onlyDOM_VK_NUMPAD4:Int = 100

@:value(101)staticinlineread onlyDOM_VK_NUMPAD5:Int = 101

@:value(102)staticinlineread onlyDOM_VK_NUMPAD6:Int = 102

@:value(103)staticinlineread onlyDOM_VK_NUMPAD7:Int = 103

@:value(104)staticinlineread onlyDOM_VK_NUMPAD8:Int = 104

@:value(105)staticinlineread onlyDOM_VK_NUMPAD9:Int = 105

@:value(144)staticinlineread onlyDOM_VK_NUM_LOCK:Int = 144

@:value(79)staticinlineread onlyDOM_VK_O:Int = 79

@:value(219)staticinlineread onlyDOM_VK_OPEN_BRACKET:Int = 219

@:value(174)staticinlineread onlyDOM_VK_OPEN_CURLY_BRACKET:Int = 174

@:value(168)staticinlineread onlyDOM_VK_OPEN_PAREN:Int = 168

@:value(80)staticinlineread onlyDOM_VK_P:Int = 80

@:value(253)staticinlineread onlyDOM_VK_PA1:Int = 253

@:value(34)staticinlineread onlyDOM_VK_PAGE_DOWN:Int = 34

@:value(33)staticinlineread onlyDOM_VK_PAGE_UP:Int = 33

@:value(19)staticinlineread onlyDOM_VK_PAUSE:Int = 19

@:value(165)staticinlineread onlyDOM_VK_PERCENT:Int = 165

@:value(190)staticinlineread onlyDOM_VK_PERIOD:Int = 190

@:value(172)staticinlineread onlyDOM_VK_PIPE:Int = 172

@:value(250)staticinlineread onlyDOM_VK_PLAY:Int = 250

@:value(171)staticinlineread onlyDOM_VK_PLUS:Int = 171

@:value(42)staticinlineread onlyDOM_VK_PRINT:Int = 42

@:value(44)staticinlineread onlyDOM_VK_PRINTSCREEN:Int = 44

@:value(229)staticinlineread onlyDOM_VK_PROCESSKEY:Int = 229

@:value(81)staticinlineread onlyDOM_VK_Q:Int = 81

@:value(63)staticinlineread onlyDOM_VK_QUESTION_MARK:Int = 63

@:value(222)staticinlineread onlyDOM_VK_QUOTE:Int = 222

@:value(82)staticinlineread onlyDOM_VK_R:Int = 82

@:value(13)staticinlineread onlyDOM_VK_RETURN:Int = 13

@:value(39)staticinlineread onlyDOM_VK_RIGHT:Int = 39

@:value(83)staticinlineread onlyDOM_VK_S:Int = 83

@:value(145)staticinlineread onlyDOM_VK_SCROLL_LOCK:Int = 145

@:value(41)staticinlineread onlyDOM_VK_SELECT:Int = 41

@:value(59)staticinlineread onlyDOM_VK_SEMICOLON:Int = 59

@:value(108)staticinlineread onlyDOM_VK_SEPARATOR:Int = 108

@:value(16)staticinlineread onlyDOM_VK_SHIFT:Int = 16

@:value(191)staticinlineread onlyDOM_VK_SLASH:Int = 191

@:value(95)staticinlineread onlyDOM_VK_SLEEP:Int = 95

@:value(32)staticinlineread onlyDOM_VK_SPACE:Int = 32

@:value(109)staticinlineread onlyDOM_VK_SUBTRACT:Int = 109

@:value(84)staticinlineread onlyDOM_VK_T:Int = 84

@:value(9)staticinlineread onlyDOM_VK_TAB:Int = 9

@:value(176)staticinlineread onlyDOM_VK_TILDE:Int = 176

@:value(85)staticinlineread onlyDOM_VK_U:Int = 85

@:value(167)staticinlineread onlyDOM_VK_UNDERSCORE:Int = 167

@:value(38)staticinlineread onlyDOM_VK_UP:Int = 38

@:value(86)staticinlineread onlyDOM_VK_V:Int = 86

@:value(182)staticinlineread onlyDOM_VK_VOLUME_DOWN:Int = 182

@:value(181)staticinlineread onlyDOM_VK_VOLUME_MUTE:Int = 181

@:value(183)staticinlineread onlyDOM_VK_VOLUME_UP:Int = 183

@:value(87)staticinlineread onlyDOM_VK_W:Int = 87

@:value(91)staticinlineread onlyDOM_VK_WIN:Int = 91

@:value(228)staticinlineread onlyDOM_VK_WIN_ICO_00:Int = 228

@:value(230)staticinlineread onlyDOM_VK_WIN_ICO_CLEAR:Int = 230

@:value(227)staticinlineread onlyDOM_VK_WIN_ICO_HELP:Int = 227

@:value(240)staticinlineread onlyDOM_VK_WIN_OEM_ATTN:Int = 240

@:value(243)staticinlineread onlyDOM_VK_WIN_OEM_AUTO:Int = 243

@:value(245)staticinlineread onlyDOM_VK_WIN_OEM_BACKTAB:Int = 245

@:value(254)staticinlineread onlyDOM_VK_WIN_OEM_CLEAR:Int = 254

@:value(242)staticinlineread onlyDOM_VK_WIN_OEM_COPY:Int = 242

@:value(239)staticinlineread onlyDOM_VK_WIN_OEM_CUSEL:Int = 239

@:value(244)staticinlineread onlyDOM_VK_WIN_OEM_ENLW:Int = 244

@:value(241)staticinlineread onlyDOM_VK_WIN_OEM_FINISH:Int = 241

@:value(146)staticinlineread onlyDOM_VK_WIN_OEM_FJ_JISHO:Int = 146

@:value(149)staticinlineread onlyDOM_VK_WIN_OEM_FJ_LOYA:Int = 149

@:value(147)staticinlineread onlyDOM_VK_WIN_OEM_FJ_MASSHOU:Int = 147

@:value(150)staticinlineread onlyDOM_VK_WIN_OEM_FJ_ROYA:Int = 150

@:value(148)staticinlineread onlyDOM_VK_WIN_OEM_FJ_TOUROKU:Int = 148

@:value(234)staticinlineread onlyDOM_VK_WIN_OEM_JUMP:Int = 234

@:value(235)staticinlineread onlyDOM_VK_WIN_OEM_PA1:Int = 235

@:value(236)staticinlineread onlyDOM_VK_WIN_OEM_PA2:Int = 236

@:value(237)staticinlineread onlyDOM_VK_WIN_OEM_PA3:Int = 237

@:value(233)staticinlineread onlyDOM_VK_WIN_OEM_RESET:Int = 233

@:value(238)staticinlineread onlyDOM_VK_WIN_OEM_WSCTRL:Int = 238

@:value(88)staticinlineread onlyDOM_VK_X:Int = 88

@:value(89)staticinlineread onlyDOM_VK_Y:Int = 89

@:value(90)staticinlineread onlyDOM_VK_Z:Int = 90

@:value(251)staticinlineread onlyDOM_VK_ZOOM:Int = 251

Constructor

new(typeArg:String, ?keyboardEventInitDict:Null<KeyboardEventInit>)

Throws:

null

DOMError

Variables

read onlyaltKey:Bool

Returns a Boolean that is true if the Alt ( Option or ⌥ on OS X) key was active when the key event was generated.

read onlycharCode:Int

Returns a Number representing the Unicode reference number of the key; this attribute is used only by the keypress event. For keys whose char attribute contains multiple characters, this is the Unicode value of the first character in that attribute. In Firefox 26 this returns codes for printable characters. Warning: This attribute is deprecated; you should use KeyboardEvent.key instead, if available.

read onlycode:String

Returns a DOMString with the code value of the key represented by the event.

read onlyctrlKey:Bool

Returns a Boolean that is true if the Ctrl key was active when the key event was generated.

read onlyisComposing:Bool

Returns a Boolean that is true if the event is fired between after compositionstart and before compositionend.

read onlykey:String

Returns a DOMString representing the key value of the key represented by the event.

read onlykeyCode:Int

Returns a Number representing a system and implementation dependent numerical code identifying the unmodified value of the pressed key. Warning: This attribute is deprecated; you should use KeyboardEvent.key instead, if available.

read onlylocation:Int

Returns a Number representing the location of the key on the keyboard or other input device.

read onlymetaKey:Bool

Returns a Boolean that is true if the Meta key (on Mac keyboards, the ⌘ Command key; on Windows keyboards, the Windows key (⊞)) was active when the key event was generated.

read onlyrepeat:Bool

Returns a Boolean that is true if the key is being held down such that it is automatically repeating.

read onlyshiftKey:Bool

Returns a Boolean that is true if the Shift key was active when the key event was generated.

Methods

getModifierState(key:String):Bool

Returns a Boolean indicating if a modifier key such as Alt, Shift, Ctrl, or Meta, was pressed when the event was created.

@:value({ charCode : 0, keyCode : 0, metaKey : false, shiftKey : false, altKey : false, ctrlKey : false, cancelable : false, canBubble : false })initKeyEvent(type:String, canBubble:Bool = false, cancelable:Bool = false, ?view:Window, ctrlKey:Bool = false, altKey:Bool = false, shiftKey:Bool = false, metaKey:Bool = false, keyCode:Int = 0, charCode:Int = 0):Void

Initializes a KeyboardEvent object. This was implemented only by Firefox, and is no longer supported even there; instead, you should use the KeyboardEvent.KeyboardEvent constructor.

@:value({ metaKey : false, shiftKey : false, altKey : false, ctrlKey : false, locationArg : 0, keyArg : "", cancelableArg : false, bubblesArg : false })initKeyboardEvent(typeArg:String, bubblesArg:Bool = false, cancelableArg:Bool = false, ?viewArg:Window, keyArg:String = "", locationArg:Int = 0, ctrlKey:Bool = false, altKey:Bool = false, shiftKey:Bool = false, metaKey:Bool = false):Void

Initializes a KeyboardEvent object. This is now deprecated. You should instead use the KeyboardEvent.KeyboardEvent constructor.

Throws:

null

DOMError

Inherited Variables

Defined by UIEvent

read onlydetail:Int

Returns a long with details about the event, depending on the event type.

read onlylayerX:Int

Returns the horizontal coordinate of the event relative to the current layer.

read onlylayerY:Int

Returns the vertical coordinate of the event relative to the current layer.

read onlypageX:Int

Returns the horizontal coordinate of the event relative to the whole document.

read onlypageY:Int

Returns the vertical coordinate of the event relative to the whole document.

read onlyrangeOffset:Int

read onlyrangeParent:Node

read onlyview:Window

Returns a WindowProxy that contains the view that generated the event.

read onlywhich:Int

Returns the numeric keyCode of the key pressed, or the character code (charCode) for an alphanumeric key pressed.

Defined by Event

read onlybubbles:Bool

A Boolean indicating whether the event bubbles up through the DOM or not.

cancelBubble:Bool

A historical alias to Event.stopPropagation(). Setting its value to true before returning from an event handler prevents propagation of the event.

read onlycancelable:Bool

A Boolean indicating whether the event is cancelable.

read onlycomposed:Bool

A Boolean value indicating whether or not the event can bubble across the boundary between the shadow DOM and the regular DOM.

read onlycurrentTarget:EventTarget

A reference to the currently registered target for the event. This is the object to which the event is currently slated to be sent; it's possible this has been changed along the way through retargeting.

read onlydefaultPrevented:Bool

Indicates whether or not event.preventDefault() has been called on the event.

read onlyeventPhase:Int

Indicates which phase of the event flow is being processed.

read onlyexplicitOriginalTarget:EventTarget

The explicit original target of the event (Mozilla-specific).

read onlyisTrusted:Bool

Indicates whether or not the event was initiated by the browser (after a user click for instance) or by a script (using an event creation method, like event.initEvent).

read onlyoriginalTarget:EventTarget

The original target of the event, before any retargetings (Mozilla-specific).

returnValue:Bool

A historical property introduced by Internet Explorer and eventually adopted into the DOM specification in order to ensure existing sites continue to work. Ideally, you should try to use Event.preventDefault() and Event.defaultPrevented instead, but you can use returnValue if you choose to do so.

read onlytarget:EventTarget

A reference to the target to which the event was originally dispatched.

read onlytimeStamp:Float

The time at which the event was created (in milliseconds). By specification, this value is time since epoch, but in reality browsers' definitions vary; in addition, work is underway to change this to be a DOMHighResTimeStamp instead.

read onlytype:String

The name of the event (case-insensitive).

Inherited Methods

Defined by UIEvent

@:value({ aDetail : 0, aCancelable : false, aCanBubble : false })initUIEvent(aType:String, aCanBubble:Bool = false, aCancelable:Bool = false, ?aView:Window, aDetail:Int = 0):Void

Initializes a UIEvent object. If the event has already being dispatched, this method does nothing.

Defined by Event

composedPath():Array<EventTarget>

Returns the event’s path (objects on which listeners will be invoked). This does not include nodes in shadow trees if the shadow root was created with its ShadowRoot.mode closed.

@:value({ cancelable : false, bubbles : false })initEvent(type:String, bubbles:Bool = false, cancelable:Bool = false):Void

Initializes the value of an Event created. If the event has already being dispatched, this method does nothing.

preventDefault():Void

Cancels the event (if it is cancelable).

stopImmediatePropagation():Void

For this particular event, no other listener will be called. Neither those attached on the same element, nor those attached on elements which will be traversed later (in capture phase, for instance)

stopPropagation():Void

Stops the propagation of events further along in the DOM.