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. |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | 31 (31) | No support | (Yes) | ? |
Add code and key to init | 49.0 |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | ? | (Yes) | 31.0 (31) | No support | (Yes) | ? | (Yes) |
Add code and key to init | No support | 49.0 | 49.0 |
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