KeyboardEvent()
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", optionalDOMString, defaulting to"", that sets the value ofKeyboardEvent.key. -
"code", optionalDOMString, defaulting to"", that sets the value ofKeyboardEvent.code. -
"location", optionalunsigned long, defaulting to0, that sets the value ofKeyboardEvent.location. -
"ctrlKey", optional boolean value, defaulting tofalse, that sets the value ofKeyboardEvent.ctrlKey. -
"shiftKey", optional boolean value, defaulting tofalse, that sets the value ofKeyboardEvent.shiftKey. -
"altKey", optional boolean value, defaulting tofalse, that sets the value ofKeyboardEvent.altKey. -
"metaKey", optional boolean value, defaulting tofalse, that sets the value ofKeyboardEvent.metaKey.< /li> -
"repeat", optional boolean value, defaulting tofalse, that sets the value ofKeyboardEvent.repeat. -
"isComposing", optional boolean value, defaulting tofalse, that sets the value ofKeyboardEvent.isComposing. -
"charCode", optionalunsigned long, defaulting to0, that sets the value of the deprecatedKeyboardEvent.charCode. -
"keyCode", optionalunsigned long, defaulting to0, that sets the value of the deprecatedKeyboardEvent.keyCode. -
"which", optionalunsigned long, defaulting to0, that sets the value of the deprecatedKeyboardEvent.which.
Note: The
KeyboardEventInitdictionary also accepts fields from theUIEventInitandEventInitdictionaries. -
Specifications
| Specification |
|---|
| UI Events # dom-keyboardevent-keyboardevent |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
KeyboardEvent |
26 |
12 |
31 |
No |
15 |
7 |
≤37 |
26 |
31 |
14 |
7 |
1.5 |
See also
-
KeyboardEvent, the interface of the objects it constructs.
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent