The KeyboardEvent() constructor creates a new KeyboardEvent.

Syntax

 event = new KeyboardEvent(typeArg, KeyboardEventInit);

Values

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

The KeyboardEventInit dictionary also accepts fields from the UIEventInit and EventInit dictionaries.

Specifications

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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support YesEdge ? Firefox Full support 31IE No support NoOpera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 31Opera Android Full support YesSafari iOS ? Samsung Internet Android ?
Added code and key to KeyboardEventInitChrome Full support 49Edge ? Firefox ? IE ? Opera ? Safari ? WebView Android Full support 49Chrome Android Full support 49Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android ?

Legend

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

See also

Document Tags and Contributors

Contributors to this page: sideshowbarker, fscholz, jpmedley, jwhitlock, torbasow, nyrosmith, teoli
Last updated by: sideshowbarker,