The KeyboardEvent() constructor creates a new KeyboardEvent.
Syntax
event = new KeyboardEvent(typeArg, KeyboardEventInit);
Values
- typeArg
- Is a
DOMStringrepresenting the name of the event. - KeyboardEventInitOptional
- Is a
KeyboardEventInitdictionary, having the following fields:"key", optional and defaulting to"", of typeDOMString, that sets the value ofKeyboardEvent.key."code", optional and defaulting to"", of typeDOMString, that sets the value ofKeyboardEvent.code."location", optional and defaulting to0, of typeunsigned long, that sets the value ofKeyboardEvent.location."ctrlKey", optional and defaulting tofalse, of typeBoolean, that sets the value ofKeyboardEvent.ctrlKey."shiftKey", optional and defaulting tofalse, of typeBoolean, that sets the value ofKeyboardEvent.shiftKey."altKey", optional and defaulting tofalse, of typeBoolean, that sets the value ofKeyboardEvent.altKey."metaKey", optional and defaulting tofalse, of typeBoolean, that sets the value ofKeyboardEvent.metaKey."repeat", optional and defaulting tofalse, of typeBoolean, that sets the value ofKeyboardEvent.repeat."isComposing", optional and defaulting tofalse, of typeBoolean, that sets the value ofKeyboardEvent.isComposing."charCode", optional and defaulting to0, of typeunsigned long, that sets the value of the deprecatedKeyboardEvent.charCode."keyCode", optional and defaulting to0, of typeunsigned long, that sets the value of the deprecatedKeyboardEvent.keyCode."which", optional and defaulting to0, of typeunsigned long, that sets the value of the deprecatedKeyboardEvent.which.
The
KeyboardEventInitdictionary also accepts fields from theUIEventInitandEventInitdictionaries.
Specifications
| Specification | Status | Comment |
|---|---|---|
| Document Object Model (DOM) Level 3 Events Specification The definition of 'KeyboardEvent()' in that specification. |
Working Draft | Initial definition. |
Browser compatibility
| 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 |
See also
KeyboardEvent, the interface of the objects it constructs.