KeyboardEvent: KeyboardEvent() constructor
The KeyboardEvent()
constructor creates a new
KeyboardEvent
object.
Syntax
new KeyboardEvent(type)
new KeyboardEvent(type, options)
Parameters
type
-
A string with the name of the event. It is case-sensitive and browsers set it to
keydown
,keyup
, orkeypress
. options
Optional-
An object that, in addition of the properties defined in
UIEvent()
, can have the following properties:key
Optional-
A string, defaulting to
""
, that sets the value ofKeyboardEvent.key
. code
Optional-
A string, defaulting to
""
, that sets the value ofKeyboardEvent.code
. location
Optional-
A string, defaulting to
0
, that sets the value ofKeyboardEvent.location
. repeat
Optional-
A boolean value, defaulting to
false
, that sets the value ofKeyboardEvent.repeat
. isComposing
Optional-
A boolean value, defaulting to
false
, that sets the value ofKeyboardEvent.isComposing
. charCode
Optional Deprecated-
A number, defaulting to
0
, that sets the value of the deprecatedKeyboardEvent.charCode
. keyCode
Optional Deprecated-
A number, defaulting to
0
, that sets the value of the deprecatedKeyboardEvent.keyCode
. which
Optional Deprecated-
A number, defaulting to
0
, that sets the value of the deprecatedUIEvent.which
. ctrlKey
Optional-
A boolean value, defaulting to
false
, that sets the value ofKeyboardEvent.ctrlKey
. shiftKey
Optional-
A boolean value, defaulting to
false
, that sets the value ofKeyboardEvent.shiftKey
. altKey
Optional-
A boolean value, defaulting to
false
, that sets the value ofKeyboardEvent.altKey
. metaKey
Optional-
A boolean value, defaulting to
false
, that sets the value ofKeyboardEvent.metaKey
.
Return value
A new KeyboardEvent
object.
Specifications
Specification |
---|
UI Events # dom-keyboardevent-keyboardevent |
Browser compatibility
BCD tables only load in the browser
See also
KeyboardEvent
, the interface of the objects it constructs.