The KeyboardEvent()
constructor creates a new KeyboardEvent
.
event = new KeyboardEvent(typeArg, KeyboardEventInit);
DOMString
representing the name of the event.KeyboardEventInit
dictionary, having the following fields: "key"
, optional and defaulting to ""
, of type DOMString
, that sets the value of KeyboardEvent.key
."code"
, optional and defaulting to ""
, of type DOMString
, that sets the value of KeyboardEvent.code
."location"
, optional and defaulting to 0
, of type unsigned long
, that sets the value of KeyboardEvent.location
."ctrlKey"
, optional and defaulting to false
, of type Boolean
, that sets the value of KeyboardEvent.ctrlKey
."shiftKey"
, optional and defaulting to false
, of type Boolean
, that sets the value of KeyboardEvent.shiftKey
."altKey"
, optional and defaulting to false
, of type Boolean
, that sets the value of KeyboardEvent.altKey
."metaKey"
, optional and defaulting to false
, of type Boolean
, that sets the value of KeyboardEvent.metaKey
."repeat"
, optional and defaulting to false
, of type Boolean
, that sets the value of KeyboardEvent.repeat
."isComposing"
, optional and defaulting to false
, of type Boolean
, that sets the value of KeyboardEvent.isComposing
."charCode"
, optional and defaulting to 0
, of type unsigned long
, that sets the value of the deprecated KeyboardEvent.charCode
."keyCode"
, optional and defaulting to 0
, of type unsigned long
, that sets the value of the deprecated KeyboardEvent.keyCode
."which"
, optional and defaulting to 0
, of type unsigned long
, that sets the value of the deprecated KeyboardEvent.which
.The KeyboardEventInit
dictionary also accepts fields from the UIEventInit
and EventInit
dictionaries.
Specification | Status | Comment |
---|---|---|
UI Events The definition of 'KeyboardEvent()' in that specification. | Working Draft | Current definition. |
Document Object Model (DOM) Level 3 Events Specification The definition of 'KeyboardEvent()' in that specification. | Obsolete | Initial definition. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | Yes | ? | 31 | No | Yes | ? |
Added code and key to KeyboardEventInit
|
49 | ? | ? | ? | ? | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | ? | 31 | Yes | ? | ? |
Added code and key to KeyboardEventInit
|
49 | 49 | ? | ? | ? | ? | ? |
KeyboardEvent
, the interface of the objects it constructs.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent