Skip to content
SiteEmail

KeyboardEvent

Module: JavaScript DOM API

#include <KeyboardEvent.idl>

Inherits from UIEvent, Event

Name
KeyboardEventKeyboardEvent(DOMInternedString type, optional KeyboardEventInit eventInitDict)
voidinitKeyboardEvent(optional DOMInternedString typeArg, optional boolean bubblesArg, optional boolean cancelableArg, optional Window? viewArg, optional DOMString keyIdentifier, optional unsigned long locationArg, optional boolean ctrlKey, optional boolean altKey, optional boolean shiftKey, optional boolean metaKey, optional boolean altGraphKey)
booleangetModifierState(DOMString keyIdentifier)
Queries the state of a modifier using a key value.
Name
const unsigned longDOM_KEY_LOCATION_STANDARD
const unsigned longDOM_KEY_LOCATION_LEFT
const unsigned longDOM_KEY_LOCATION_RIGHT
const unsigned longDOM_KEY_LOCATION_NUMPAD
readonly attribute unsigned longcharCode
keyCode is deprecated in HTML but a lot of existing code prefers it and it also is the standard thing to use in GT
readonly attribute unsigned longkeyCode
readonly attribute unsigned longwhich
readonly attribute DOMStringkey
readonly attribute DOMStringcode
readonly attribute unsigned longlocation
Returns a Number representing the location of the key on the keyboard or other input device.
readonly attribute booleanrepeat
Returns a boolean representing if the event is repeating (the user is holding the key down).
readonly attribute booleanctrlKey
readonly attribute booleanshiftKey
readonly attribute booleanaltKey
readonly attribute booleanmetaKey

Public Functions inherited from UIEvent

Name
UIEventUIEvent(DOMInternedString type, optional UIEventInit initEvent)
voidinitUIEvent(optional DOMInternedString type, optional boolean canBubble, optional boolean cancelable, optional Window? view, optional long detail)

Public Attributes inherited from UIEvent

Name
readonly attribute longdetail

Public Functions inherited from Event

Name
EventEvent(DOMInternedString type, optional EventInit initEvent)
voidstopPropagation()
voidpreventDefault()
voidinitEvent(optional DOMInternedString eventTypeArg, optional boolean canBubbleArg, optional boolean cancelableArg)
voidstopImmediatePropagation()

Public Attributes inherited from Event

Name
const unsigned shortNONE
const unsigned shortCAPTURING_PHASE
const unsigned shortAT_TARGET
const unsigned shortBUBBLING_PHASE
readonly attribute DOMStringtype
readonly attribute EventTargettarget
readonly attribute EventTargetcurrentTarget
readonly attribute unsigned shorteventPhase
readonly attribute booleanbubbles
readonly attribute booleancancelable
readonly attribute booleandefaultPrevented
readonly attribute booleancomposed
KeyboardEvent KeyboardEvent(
DOMInternedString type,
optional KeyboardEventInit eventInitDict
)
void initKeyboardEvent(
optional DOMInternedString typeArg,
optional boolean bubblesArg,
optional boolean cancelableArg,
optional Window? viewArg,
optional DOMString keyIdentifier,
optional unsigned long locationArg,
optional boolean ctrlKey,
optional boolean altKey,
optional boolean shiftKey,
optional boolean metaKey,
optional boolean altGraphKey
)
boolean getModifierState(
DOMString keyIdentifier
)

Queries the state of a modifier using a key value.

Parameters:

  • keyIdentifier A modifier key value.

Return: true if it is a modifier key and the modifier is activated, false otherwise.

const unsigned long DOM_KEY_LOCATION_STANDARD = 0x00;
const unsigned long DOM_KEY_LOCATION_LEFT = 0x01;
const unsigned long DOM_KEY_LOCATION_RIGHT = 0x02;
const unsigned long DOM_KEY_LOCATION_NUMPAD = 0x03;
readonly attribute unsigned long charCode;

keyCode is deprecated in HTML but a lot of existing code prefers it and it also is the standard thing to use in GT

readonly attribute unsigned long keyCode;
readonly attribute unsigned long which;
readonly attribute DOMString key;
readonly attribute DOMString code;
readonly attribute unsigned long location;

Returns a Number representing the location of the key on the keyboard or other input device.

readonly attribute boolean repeat;

Returns a boolean representing if the event is repeating (the user is holding the key down).

readonly attribute boolean ctrlKey;
readonly attribute boolean shiftKey;
readonly attribute boolean altKey;
readonly attribute boolean metaKey;