Interface KeyboardEvent
- All Known Implementing Classes:
DOMKeyboardEvent
KeyboardEvent interface provides specific contextual
information associated with keyboard devices. Each keyboard event
references a key using an identifier. Keyboard events are commonly
directed at the element that has the focus.
The KeyboardEvent interface provides convenient attributes
for some common modifiers keys: KeyboardEvent.ctrlKey,
KeyboardEvent.shiftKey, KeyboardEvent.altKey,
KeyboardEvent.metaKey. These attributes are equivalent to
use the method
KeyboardEvent.getModifierState(keyIdentifierArg) with
"Control", "Shift", "Alt", or "Meta" respectively.
To create an instance of the KeyboardEvent interface, use
the DocumentEvent.createEvent("KeyboardEvent") method call.
See also the Document Object Model (DOM) Level 3 Events Specification .
- Since:
- DOM Level 3
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe key activated is in the left key location (there is more than one possible location for this key).static final intThe key activation originated on the numeric keypad or with a virtual key corresponding to the numeric keypad.static final intThe key activation is in the right key location (there is more than one possible location for this key).static final intThe key activation is not distinguished as the left or right version of the key, and did not originate from the numeric keypad (or did not originate with a virtual key corresponding to the numeric keypad).Fields inherited from interface Event
AT_TARGET, BUBBLING_PHASE, CAPTURING_PHASE -
Method Summary
Modifier and TypeMethodDescriptionbooleantrueif the alternative (Alt) key modifier is activated.booleantrueif the control (Ctrl) key modifier is activated.keyIdentifierholds the identifier of the key.intThekeyLocationattribute contains an indication of the location of they key on the device, as described in .booleantrueif the meta (Meta) key modifier is activated.booleangetModifierState(String keyIdentifierArg) This methods queries the state of a modifier using a key identifier.booleantrueif the shift (Shift) key modifier is activated.voidinitKeyboardEvent(String typeArg, boolean canBubbleArg, boolean cancelableArg, AbstractView viewArg, String keyIdentifierArg, int keyLocationArg, String modifiersList) TheinitKeyboardEventmethod is used to initialize the value of aKeyboardEventobject and has the same behavior asUIEvent.initUIEvent().voidinitKeyboardEventNS(String namespaceURI, String typeArg, boolean canBubbleArg, boolean cancelableArg, AbstractView viewArg, String keyIdentifierArg, int keyLocationArg, String modifiersList) TheinitKeyboardEventNSmethod is used to initialize the value of aKeyboardEventobject and has the same behavior asUIEvent.initUIEventNS().Methods inherited from interface Event
getBubbles, getCancelable, getCurrentTarget, getEventPhase, getTarget, getTimeStamp, getType, initEvent, preventDefault, stopPropagationMethods inherited from interface UIEvent
getDetail, getView, initUIEvent
-
Field Details
-
DOM_KEY_LOCATION_STANDARD
static final int DOM_KEY_LOCATION_STANDARDThe key activation is not distinguished as the left or right version of the key, and did not originate from the numeric keypad (or did not originate with a virtual key corresponding to the numeric keypad). Example: the 'Q' key on a PC 101 Key US keyboard.- See Also:
-
DOM_KEY_LOCATION_LEFT
static final int DOM_KEY_LOCATION_LEFTThe key activated is in the left key location (there is more than one possible location for this key). Example: the left Shift key on a PC 101 Key US keyboard.- See Also:
-
DOM_KEY_LOCATION_RIGHT
static final int DOM_KEY_LOCATION_RIGHTThe key activation is in the right key location (there is more than one possible location for this key). Example: the right Shift key on a PC 101 Key US keyboard.- See Also:
-
DOM_KEY_LOCATION_NUMPAD
static final int DOM_KEY_LOCATION_NUMPADThe key activation originated on the numeric keypad or with a virtual key corresponding to the numeric keypad. Example: the '1' key on a PC 101 Key US keyboard located on the numeric pad.- See Also:
-
-
Method Details
-
getKeyIdentifier
String getKeyIdentifier()keyIdentifierholds the identifier of the key. The key identifiers are defined in Appendix A.2 "". Implementations that are unable to identify a key must use the key identifier"Unidentified". -
getKeyLocation
int getKeyLocation()ThekeyLocationattribute contains an indication of the location of they key on the device, as described in . -
getCtrlKey
boolean getCtrlKey()trueif the control (Ctrl) key modifier is activated. -
getShiftKey
boolean getShiftKey()trueif the shift (Shift) key modifier is activated. -
getAltKey
boolean getAltKey()trueif the alternative (Alt) key modifier is activated.Note: The Option key modifier on Macintosh systems must be represented using this key modifier.
-
getMetaKey
boolean getMetaKey()trueif the meta (Meta) key modifier is activated.Note: The Command key modifier on Macintosh systems must be represented using this key modifier.
-
getModifierState
This methods queries the state of a modifier using a key identifier. See also .- Parameters:
keyIdentifierArg- A modifier key identifier. Common modifier keys are"Alt","AltGraph","CapsLock","Control","Meta","NumLock","Scroll", or"Shift".Note: If an application wishes to distinguish between right and left modifiers, this information could be deduced using keyboard events and
KeyboardEvent.keyLocation.- Returns:
trueif it is modifier key and the modifier is activated,falseotherwise.
-
initKeyboardEvent
void initKeyboardEvent(String typeArg, boolean canBubbleArg, boolean cancelableArg, AbstractView viewArg, String keyIdentifierArg, int keyLocationArg, String modifiersList) TheinitKeyboardEventmethod is used to initialize the value of aKeyboardEventobject and has the same behavior asUIEvent.initUIEvent(). The value ofUIEvent.detailremains undefined.- Parameters:
typeArg- Refer to theUIEvent.initUIEvent()method for a description of this parameter.canBubbleArg- Refer to theUIEvent.initUIEvent()method for a description of this parameter.cancelableArg- Refer to theUIEvent.initUIEvent()method for a description of this parameter.viewArg- Refer to theUIEvent.initUIEvent()method for a description of this parameter.keyIdentifierArg- SpecifiesKeyboardEvent.keyIdentifier.keyLocationArg- SpecifiesKeyboardEvent.keyLocation.modifiersList- A white space separated list of modifier key identifiers to be activated on this object.
-
initKeyboardEventNS
void initKeyboardEventNS(String namespaceURI, String typeArg, boolean canBubbleArg, boolean cancelableArg, AbstractView viewArg, String keyIdentifierArg, int keyLocationArg, String modifiersList) TheinitKeyboardEventNSmethod is used to initialize the value of aKeyboardEventobject and has the same behavior asUIEvent.initUIEventNS(). The value ofUIEvent.detailremains undefined.- Parameters:
namespaceURI- Refer to theUIEvent.initUIEventNS()method for a description of this parameter.typeArg- Refer to theUIEvent.initUIEventNS()method for a description of this parameter.canBubbleArg- Refer to theUIEvent.initUIEventNS()method for a description of this parameter.cancelableArg- Refer to theUIEvent.initUIEventNS()method for a description of this parameter.viewArg- Refer to theUIEvent.initUIEventNS()method for a description of this parameter.keyIdentifierArg- Refer to theKeyboardEvent.initKeyboardEvent()method for a description of this parameter.keyLocationArg- Refer to theKeyboardEvent.initKeyboardEvent()method for a description of this parameter.modifiersList- A white space separated list of modifier key identifiers to be activated on this object. As an example,"Control Alt"will activated the control and alt modifiers.
-