public interface KeyboardEvent extends UIEvent
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
.
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.
Modifier and Type | Field and Description |
---|---|
static int |
DOM_KEY_LOCATION_LEFT
The key activated is in the left key location (there is more than one
possible location for this key).
|
static int |
DOM_KEY_LOCATION_NUMPAD
The key activation originated on the numeric keypad or with a virtual
key corresponding to the numeric keypad.
|
static int |
DOM_KEY_LOCATION_RIGHT
The key activation is in the right key location (there is more than
one possible location for this key).
|
static int |
DOM_KEY_LOCATION_STANDARD
The 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).
|
AT_TARGET, BUBBLING_PHASE, CAPTURING_PHASE
Modifier and Type | Method and Description |
---|---|
boolean |
getAltKey()
true if the alternative (Alt) key modifier is activated. |
boolean |
getCtrlKey()
true if the control (Ctrl) key modifier is activated. |
java.lang.String |
getKeyIdentifier()
keyIdentifier holds the identifier of the key. |
int |
getKeyLocation()
The
keyLocation attribute contains an indication of the
location of they key on the device, as described in
Keyboard event types. |
boolean |
getMetaKey()
true if the meta (Meta) key modifier is activated. |
boolean |
getShiftKey()
true if the shift (Shift) key modifier is activated. |
void |
initKeyboardEvent(java.lang.String typeArg,
boolean canBubbleArg,
boolean cancelableArg,
AbstractView viewArg,
java.lang.String keyIdentifierArg,
int keyLocationArg,
java.lang.String modifiersList)
The
initKeyboardEvent method is used to initialize the
value of a KeyboardEvent object and has the same
behavior as UIEvent.initUIEvent() . |
void |
initKeyboardEventNS(java.lang.String namespaceURIArg,
java.lang.String typeArg,
boolean canBubbleArg,
boolean cancelableArg,
AbstractView viewArg,
java.lang.String keyIdentifierArg,
int keyLocationArg,
java.lang.String modifiersList)
The
initKeyboardEventNS method is used to initialize the
value of a KeyboardEvent object and has the same
behavior as UIEvent.initUIEventNS() . |
getDetail, getView, initUIEvent, initUIEventNS
getBubbles, getCancelable, getCurrentTarget, getDefaultPrevented, getEventPhase, getNamespaceURI, getTarget, getTimeStamp, getType, initEvent, initEventNS, preventDefault, stopPropagation
static final int DOM_KEY_LOCATION_STANDARD
static final int DOM_KEY_LOCATION_LEFT
static final int DOM_KEY_LOCATION_RIGHT
static final int DOM_KEY_LOCATION_NUMPAD
java.lang.String getKeyIdentifier()
keyIdentifier
holds the identifier of the key. The key
identifiers are defined in Appendix A.2
"Key identifiers set". Implementations that are
unable to identify a key must use the key identifier
"Unidentified"
.int getKeyLocation()
keyLocation
attribute contains an indication of the
location of they key on the device, as described in
Keyboard event types.boolean getCtrlKey()
true
if the control (Ctrl) key modifier is activated.boolean getShiftKey()
true
if the shift (Shift) key modifier is activated.boolean getAltKey()
true
if the alternative (Alt) key modifier is activated.
Note: The Option key modifier on Macintosh systems must be represented using this key modifier.
boolean getMetaKey()
true
if the meta (Meta) key modifier is activated.
Note: The Command key modifier on Macintosh systems must be represented using this key modifier.
void initKeyboardEvent(java.lang.String typeArg, boolean canBubbleArg, boolean cancelableArg, AbstractView viewArg, java.lang.String keyIdentifierArg, int keyLocationArg, java.lang.String modifiersList)
initKeyboardEvent
method is used to initialize the
value of a KeyboardEvent
object and has the same
behavior as UIEvent.initUIEvent()
. The value of
UIEvent.detail
remains undefined.typeArg
- Refer to the UIEvent.initUIEvent()
method
for a description of this parameter.canBubbleArg
- Refer to the UIEvent.initUIEvent()
method for a description of this parameter.cancelableArg
- Refer to the UIEvent.initUIEvent()
method for a description of this parameter.viewArg
- Refer to the UIEvent.initUIEvent()
method
for a description of this parameter.keyIdentifierArg
- Specifies
KeyboardEvent.keyIdentifier
.keyLocationArg
- Specifies KeyboardEvent.keyLocation
.modifiersList
- A
white space
separated list of modifier key identifiers to be activated on
this object.void initKeyboardEventNS(java.lang.String namespaceURIArg, java.lang.String typeArg, boolean canBubbleArg, boolean cancelableArg, AbstractView viewArg, java.lang.String keyIdentifierArg, int keyLocationArg, java.lang.String modifiersList)
initKeyboardEventNS
method is used to initialize the
value of a KeyboardEvent
object and has the same
behavior as UIEvent.initUIEventNS()
. The value of
UIEvent.detail
remains undefined.namespaceURIArg
- Refer to the UIEvent.initUIEventNS()
method for a description of this parameter.typeArg
- Refer to the UIEvent.initUIEventNS()
method for a description of this parameter.canBubbleArg
- Refer to the UIEvent.initUIEventNS()
method for a description of this parameter.cancelableArg
- Refer to the UIEvent.initUIEventNS()
method for a description of this parameter.viewArg
- Refer to the UIEvent.initUIEventNS()
method for a description of this parameter.keyIdentifierArg
- Refer to the
KeyboardEvent.initKeyboardEvent()
method for a
description of this parameter.keyLocationArg
- Refer to the
KeyboardEvent.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.Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Use is subject to License Terms. Your use of this web site or any of its contents or software indicates your agreement to be bound by these License Terms.