The KeyboardEvent() constructor creates a new KeyboardEvent.


 event = new KeyboardEvent(typeArg, KeyboardEventInit);


Is a DOMString representing the name of the event.
Is a KeyboardEventInit dictionary, having the following fields:

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.

Browser compatibility

ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
KeyboardEvent() constructorChrome Full support YesEdge Full support ≤79Firefox Full support 31IE No support NoOpera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 31Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
Added code and key to KeyboardEventInitChrome Full support 49Edge Full support ≤79Firefox ? IE No support NoOpera ? Safari ? WebView Android Full support 49Chrome Android Full support 49Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android Full support 5.0


Full support
Full support
No support
No support
Compatibility unknown
Compatibility unknown

See also