The KeyboardEvent()
constructor creates a new KeyboardEvent
.
KeyboardEvent()
Syntax
new KeyboardEvent(typeArg, KeyboardEventInit);
Values
- typeArg
-
Is a
DOMString
representing the name of the event. - KeyboardEventInit Optional
-
Is a
KeyboardEventInit
dictionary, 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
. -
"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
KeyboardEventInit
dictionary also accepts fields from theUIEventInit
andEventInit
dictionaries. -
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
|
4.4
|
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