java.lang.Object | |
↳ | android.view.KeyEvent |
Contains constants for key events.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
KeyEvent.Callback | |||||||||||
KeyEvent.DispatcherState | Use with dispatch(Callback, DispatcherState, Object)
for more advanced key dispatching, such as long presses. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | ACTION_DOWN | getAction() value: the key has been pressed down. |
|||||||||
int | ACTION_MULTIPLE | getAction() value: multiple duplicate key events have
occurred in a row, or a complex string is being delivered. |
|||||||||
int | ACTION_UP | getAction() value: the key has been released. |
|||||||||
Creator<KeyEvent> | CREATOR | ||||||||||
int | FLAG_CANCELED | When associated with up key events, this indicates that the key press has been canceled. | |||||||||
int | FLAG_CANCELED_LONG_PRESS | Set when a key event has FLAG_CANCELED set because a long
press action was executed while it was down. |
|||||||||
int | FLAG_EDITOR_ACTION | This mask is used for compatibility, to identify enter keys that are coming from an IME whose enter key has been auto-labelled "next" or "done". | |||||||||
int | FLAG_FROM_SYSTEM | This mask is set if an event was known to come from a trusted part of the system. | |||||||||
int | FLAG_KEEP_TOUCH_MODE | This mask is set if we don't want the key event to cause us to leave touch mode. | |||||||||
int | FLAG_LONG_PRESS | This flag is set for the first key repeat that occurs after the long press timeout. | |||||||||
int | FLAG_SOFT_KEYBOARD | This mask is set if the key event was generated by a software keyboard. | |||||||||
int | FLAG_TRACKING | Set for ACTION_UP when this event's key code is still being
tracked from its initial down. |
|||||||||
int | FLAG_VIRTUAL_HARD_KEY | This key event was generated by a virtual (on-screen) hard key area. | |||||||||
int | FLAG_WOKE_HERE | This mask is set if the device woke because of this key event. | |||||||||
int | KEYCODE_0 | ||||||||||
int | KEYCODE_1 | ||||||||||
int | KEYCODE_2 | ||||||||||
int | KEYCODE_3 | ||||||||||
int | KEYCODE_4 | ||||||||||
int | KEYCODE_5 | ||||||||||
int | KEYCODE_6 | ||||||||||
int | KEYCODE_7 | ||||||||||
int | KEYCODE_8 | ||||||||||
int | KEYCODE_9 | ||||||||||
int | KEYCODE_A | ||||||||||
int | KEYCODE_ALT_LEFT | ||||||||||
int | KEYCODE_ALT_RIGHT | ||||||||||
int | KEYCODE_APOSTROPHE | ||||||||||
int | KEYCODE_AT | ||||||||||
int | KEYCODE_B | ||||||||||
int | KEYCODE_BACK | ||||||||||
int | KEYCODE_BACKSLASH | ||||||||||
int | KEYCODE_C | ||||||||||
int | KEYCODE_CALL | ||||||||||
int | KEYCODE_CAMERA | ||||||||||
int | KEYCODE_CLEAR | ||||||||||
int | KEYCODE_COMMA | ||||||||||
int | KEYCODE_D | ||||||||||
int | KEYCODE_DEL | ||||||||||
int | KEYCODE_DPAD_CENTER | ||||||||||
int | KEYCODE_DPAD_DOWN | ||||||||||
int | KEYCODE_DPAD_LEFT | ||||||||||
int | KEYCODE_DPAD_RIGHT | ||||||||||
int | KEYCODE_DPAD_UP | ||||||||||
int | KEYCODE_E | ||||||||||
int | KEYCODE_ENDCALL | ||||||||||
int | KEYCODE_ENTER | ||||||||||
int | KEYCODE_ENVELOPE | ||||||||||
int | KEYCODE_EQUALS | ||||||||||
int | KEYCODE_EXPLORER | ||||||||||
int | KEYCODE_F | ||||||||||
int | KEYCODE_FOCUS | ||||||||||
int | KEYCODE_G | ||||||||||
int | KEYCODE_GRAVE | ||||||||||
int | KEYCODE_H | ||||||||||
int | KEYCODE_HEADSETHOOK | ||||||||||
int | KEYCODE_HOME | ||||||||||
int | KEYCODE_I | ||||||||||
int | KEYCODE_J | ||||||||||
int | KEYCODE_K | ||||||||||
int | KEYCODE_L | ||||||||||
int | KEYCODE_LEFT_BRACKET | ||||||||||
int | KEYCODE_M | ||||||||||
int | KEYCODE_MEDIA_FAST_FORWARD | ||||||||||
int | KEYCODE_MEDIA_NEXT | ||||||||||
int | KEYCODE_MEDIA_PLAY_PAUSE | ||||||||||
int | KEYCODE_MEDIA_PREVIOUS | ||||||||||
int | KEYCODE_MEDIA_REWIND | ||||||||||
int | KEYCODE_MEDIA_STOP | ||||||||||
int | KEYCODE_MENU | ||||||||||
int | KEYCODE_MINUS | ||||||||||
int | KEYCODE_MUTE | ||||||||||
int | KEYCODE_N | ||||||||||
int | KEYCODE_NOTIFICATION | ||||||||||
int | KEYCODE_NUM | ||||||||||
int | KEYCODE_O | ||||||||||
int | KEYCODE_P | ||||||||||
int | KEYCODE_PERIOD | ||||||||||
int | KEYCODE_PLUS | ||||||||||
int | KEYCODE_POUND | ||||||||||
int | KEYCODE_POWER | ||||||||||
int | KEYCODE_Q | ||||||||||
int | KEYCODE_R | ||||||||||
int | KEYCODE_RIGHT_BRACKET | ||||||||||
int | KEYCODE_S | ||||||||||
int | KEYCODE_SEARCH | ||||||||||
int | KEYCODE_SEMICOLON | ||||||||||
int | KEYCODE_SHIFT_LEFT | ||||||||||
int | KEYCODE_SHIFT_RIGHT | ||||||||||
int | KEYCODE_SLASH | ||||||||||
int | KEYCODE_SOFT_LEFT | ||||||||||
int | KEYCODE_SOFT_RIGHT | ||||||||||
int | KEYCODE_SPACE | ||||||||||
int | KEYCODE_STAR | ||||||||||
int | KEYCODE_SYM | ||||||||||
int | KEYCODE_T | ||||||||||
int | KEYCODE_TAB | ||||||||||
int | KEYCODE_U | ||||||||||
int | KEYCODE_UNKNOWN | ||||||||||
int | KEYCODE_V | ||||||||||
int | KEYCODE_VOLUME_DOWN | ||||||||||
int | KEYCODE_VOLUME_UP | ||||||||||
int | KEYCODE_W | ||||||||||
int | KEYCODE_X | ||||||||||
int | KEYCODE_Y | ||||||||||
int | KEYCODE_Z | ||||||||||
int | MAX_KEYCODE |
This constant is deprecated.
There are now more than MAX_KEYCODE keycodes.
Use getMaxKeyCode() instead.
|
|||||||||
int | META_ALT_LEFT_ON | This mask is used to check whether the left ALT meta key is pressed. |
|||||||||
int | META_ALT_ON | This mask is used to check whether one of the ALT meta keys is pressed. |
|||||||||
int | META_ALT_RIGHT_ON | This mask is used to check whether the right the ALT meta key is pressed. |
|||||||||
int | META_SHIFT_LEFT_ON | This mask is used to check whether the left SHIFT meta key is pressed. |
|||||||||
int | META_SHIFT_ON | This mask is used to check whether one of the SHIFT meta keys is pressed. |
|||||||||
int | META_SHIFT_RIGHT_ON | This mask is used to check whether the right SHIFT meta key is pressed. |
|||||||||
int | META_SYM_ON | This mask is used to check whether the SYM meta key is pressed. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new key event.
| |||||||||||
Create a new key event.
| |||||||||||
Create a new key event.
| |||||||||||
Create a new key event.
| |||||||||||
Create a new key event.
| |||||||||||
Create a new key event for a string of characters.
| |||||||||||
Make an exact copy of an existing key event.
| |||||||||||
This constructor is deprecated.
Use
changeTimeRepeat(KeyEvent, long, int)
instead. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new key event that is the same as the given one, but whose
action is replaced with the given value.
| |||||||||||
Create a new key event that is the same as the given one, but whose
flags are replaced with the given value.
| |||||||||||
Create a new key event that is the same as the given one, but whose
event time and repeat count are replaced with the given value.
| |||||||||||
Create a new key event that is the same as the given one, but whose
event time and repeat count are replaced with the given value.
| |||||||||||
Describe the kinds of special objects contained in this Parcelable's
marshalled representation.
| |||||||||||
This method is deprecated.
Use
dispatch(Callback, DispatcherState, Object) instead.
| |||||||||||
Deliver this key event to a
KeyEvent.Callback interface. | |||||||||||
Retrieve the action of this key event.
| |||||||||||
For the special case of a
ACTION_MULTIPLE event with key
code of KEYCODE_UNKNOWN , this is a raw string of characters
associated with the event. | |||||||||||
Get the character that is produced by putting accent on the character
c.
| |||||||||||
Return the id for the keyboard that this event came from.
| |||||||||||
Get the primary character for this key.
| |||||||||||
Retrieve the time of the most recent key down event,
in the
uptimeMillis() time base. | |||||||||||
Retrieve the time this event occurred,
in the
uptimeMillis() time base. | |||||||||||
Returns the flags for this key event.
| |||||||||||
Retrieve the key code of the key event.
| |||||||||||
Get the characters conversion data for the key event..
| |||||||||||
If one of the chars in the array can be generated by the keyCode of this
key event, return the char; otherwise return '\0'.
| |||||||||||
The same as
getMatch(chars, 0) . | |||||||||||
Returns the maximum keycode.
| |||||||||||
Returns the state of the meta keys. | |||||||||||
Gets the number or symbol associated with the key.
| |||||||||||
Retrieve the repeat count of the event.
| |||||||||||
Retrieve the hardware key id of this key event. These values are not
reliable and vary from device to device.
| |||||||||||
Returns the Unicode character that the key would produce. | |||||||||||
Returns the Unicode character that the key would produce. | |||||||||||
Returns the pressed state of the ALT meta key. | |||||||||||
For
ACTION_UP events, indicates that the event has been
canceled as per FLAG_CANCELED . | |||||||||||
For
ACTION_DOWN events, indicates that the event has been
canceled as per FLAG_LONG_PRESS . | |||||||||||
Returns true if this key code is a modifier key.
| |||||||||||
Does the key code of this key produce a glyph?
| |||||||||||
Returns the pressed state of the SHIFT meta key. | |||||||||||
Returns the pressed state of the SYM meta key. | |||||||||||
Is this a system key? System keys can not be used for menu shortcuts.
| |||||||||||
For
ACTION_UP events, indicates that the event is still being
tracked from its initial down event as per
FLAG_TRACKING . | |||||||||||
Call this during
onKeyDown(int, KeyEvent) to have the system track
the key through its final up (possibly including a long press). | |||||||||||
Returns a string containing a concise, human-readable description of this
object.
| |||||||||||
Flatten this object in to a Parcel.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
getAction()
value: the key has been pressed down.
getAction()
value: multiple duplicate key events have
occurred in a row, or a complex string is being delivered. If the
key code is not {#link KEYCODE_UNKNOWN
then the
{#link getRepeatCount()
method returns the number of times
the given key code should be executed.
Otherwise, if the key code KEYCODE_UNKNOWN
, then
this is a sequence of characters as returned by getCharacters()
.
getAction()
value: the key has been released.
When associated with up key events, this indicates that the key press has been canceled. Typically this is used with virtual touch screen keys, where the user can slide from the virtual key area on to the display: in that case, the application will receive a canceled up event and should not perform the action normally associated with the key. Note that for this to work, the application can not perform an action for a key until it receives an up or the long press timeout has expired.
Set when a key event has FLAG_CANCELED
set because a long
press action was executed while it was down.
This mask is used for compatibility, to identify enter keys that are coming from an IME whose enter key has been auto-labelled "next" or "done". This allows TextView to dispatch these as normal enter keys for old applications, but still do the appropriate action when receiving them.
This mask is set if an event was known to come from a trusted part of the system. That is, the event is known to come from the user, and could not have been spoofed by a third party component.
This mask is set if we don't want the key event to cause us to leave touch mode.
This flag is set for the first key repeat that occurs after the long press timeout.
This mask is set if the key event was generated by a software keyboard.
Set for ACTION_UP
when this event's key code is still being
tracked from its initial down. That is, somebody requested that tracking
started on the key down and a long press has not caused
the tracking to be canceled.
This key event was generated by a virtual (on-screen) hard key area. Typically this is an area of the touchscreen, outside of the regular display, dedicated to "hardware" buttons.
This mask is set if the device woke because of this key event.
This constant is deprecated.
There are now more than MAX_KEYCODE keycodes.
Use getMaxKeyCode()
instead.
This mask is used to check whether the left ALT meta key is pressed.
This mask is used to check whether one of the ALT meta keys is pressed.
This mask is used to check whether the right the ALT meta key is pressed.
This mask is used to check whether the left SHIFT meta key is pressed.
This mask is used to check whether one of the SHIFT meta keys is pressed.
This mask is used to check whether the right SHIFT meta key is pressed.
This mask is used to check whether the SYM meta key is pressed.
Create a new key event.
action | Action code: either ACTION_DOWN ,
ACTION_UP , or ACTION_MULTIPLE . |
---|---|
code | The key code. |
Create a new key event.
downTime | The time (in uptimeMillis() )
at which this key code originally went down. |
---|---|
eventTime | The time (in uptimeMillis() )
at which this event happened. |
action | Action code: either ACTION_DOWN ,
ACTION_UP , or ACTION_MULTIPLE . |
code | The key code. |
repeat | A repeat count for down events (> 0 if this is after the initial down) or event count for multiple events. |
Create a new key event.
downTime | The time (in uptimeMillis() )
at which this key code originally went down. |
---|---|
eventTime | The time (in uptimeMillis() )
at which this event happened. |
action | Action code: either ACTION_DOWN ,
ACTION_UP , or ACTION_MULTIPLE . |
code | The key code. |
repeat | A repeat count for down events (> 0 if this is after the initial down) or event count for multiple events. |
metaState | Flags indicating which meta keys are currently pressed. |
Create a new key event.
downTime | The time (in uptimeMillis() )
at which this key code originally went down. |
---|---|
eventTime | The time (in uptimeMillis() )
at which this event happened. |
action | Action code: either ACTION_DOWN ,
ACTION_UP , or ACTION_MULTIPLE . |
code | The key code. |
repeat | A repeat count for down events (> 0 if this is after the initial down) or event count for multiple events. |
metaState | Flags indicating which meta keys are currently pressed. |
device | The device ID that generated the key event. |
scancode | Raw device scan code of the event. |
Create a new key event.
downTime | The time (in uptimeMillis() )
at which this key code originally went down. |
---|---|
eventTime | The time (in uptimeMillis() )
at which this event happened. |
action | Action code: either ACTION_DOWN ,
ACTION_UP , or ACTION_MULTIPLE . |
code | The key code. |
repeat | A repeat count for down events (> 0 if this is after the initial down) or event count for multiple events. |
metaState | Flags indicating which meta keys are currently pressed. |
device | The device ID that generated the key event. |
scancode | Raw device scan code of the event. |
flags | The flags for this key event |
Create a new key event for a string of characters. The key code,
action, and repeat could will automatically be set to
KEYCODE_UNKNOWN
, ACTION_MULTIPLE
, and 0 for you.
time | The time (in uptimeMillis() )
at which this event occured. |
---|---|
characters | The string of characters. |
device | The device ID that generated the key event. |
flags | The flags for this key event |
Make an exact copy of an existing key event.
This constructor is deprecated.
Use changeTimeRepeat(KeyEvent, long, int)
instead.
Copy an existing key event, modifying its time and repeat count.
origEvent | The existing event to be copied. |
---|---|
eventTime | The new event time
(in uptimeMillis() ) of the event. |
newRepeat | The new repeat count of the event. |
Create a new key event that is the same as the given one, but whose action is replaced with the given value.
event | The existing event to be copied. This is not modified. |
---|---|
action | The new action code of the event. |
Create a new key event that is the same as the given one, but whose flags are replaced with the given value.
event | The existing event to be copied. This is not modified. |
---|---|
flags | The new flags constant. |
Create a new key event that is the same as the given one, but whose event time and repeat count are replaced with the given value.
event | The existing event to be copied. This is not modified. |
---|---|
eventTime | The new event time
(in uptimeMillis() ) of the event. |
newRepeat | The new repeat count of the event. |
Create a new key event that is the same as the given one, but whose event time and repeat count are replaced with the given value.
event | The existing event to be copied. This is not modified. |
---|---|
eventTime | The new event time
(in uptimeMillis() ) of the event. |
newRepeat | The new repeat count of the event. |
newFlags | New flags for the event, replacing the entire value in the original event. |
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
Deliver this key event to a KeyEvent.Callback
interface. If this is
an ACTION_MULTIPLE event and it is not handled, then an attempt will
be made to deliver a single normal event.
receiver | The Callback that will be given the event. |
---|---|
state | State information retained across events. |
target | The target of the dispatch, for use in tracking. |
Retrieve the action of this key event. May be either
ACTION_DOWN
, ACTION_UP
, or ACTION_MULTIPLE
.
For the special case of a ACTION_MULTIPLE
event with key
code of KEYCODE_UNKNOWN
, this is a raw string of characters
associated with the event. In all other cases it is null.
Get the character that is produced by putting accent on the character c. For example, getDeadChar('`', 'e') returns è.
Return the id for the keyboard that this event came from. A device id of 0 indicates the event didn't come from a physical device and maps to the default keymap. The other numbers are arbitrary and you shouldn't depend on the values.
Get the primary character for this key. In other words, the label that is physically printed on it.
Retrieve the time of the most recent key down event,
in the uptimeMillis()
time base. If this
is a down event, this will be the same as getEventTime()
.
Note that when chording keys, this value is the down time of the
most recently pressed key, which may not be the same physical
key of this event.
uptimeMillis()
time base
Retrieve the time this event occurred,
in the uptimeMillis()
time base.
uptimeMillis()
time base.
Retrieve the key code of the key event. This is the physical key that was pressed, not the Unicode character.
Get the characters conversion data for the key event..
results | a KeyCharacterMap.KeyData that will be filled with the results. |
---|
If one of the chars in the array can be generated by the keyCode of this key event, return the char; otherwise return '\0'.
chars | the characters to try to find |
---|---|
modifiers | the modifier bits to prefer. If any of these bits are set, if there are multiple choices, that could work, the one for this modifier will be set. |
Returns the state of the meta keys.
Gets the number or symbol associated with the key. The character value is returned, not the numeric value. If the key is not a number, but is a symbol, the symbol is retuned.
Retrieve the repeat count of the event. For both key up and key down events, this is the number of times the key has repeated with the first down starting at 0 and counting up from there. For multiple key events, this is the number of down/up pairs that have occurred.
Retrieve the hardware key id of this key event. These values are not reliable and vary from device to device.
Mostly this is here for debugging purposes.
Returns the Unicode character that the key would produce.
Returns 0 if the key is not one that is used to type Unicode characters.
If the return value has bit
COMBINING_ACCENT
set, the key is a "dead key" that should be combined with another to
actually produce a character -- see getDeadChar(int, int)
-- after masking
with COMBINING_ACCENT_MASK
.
Returns the Unicode character that the key would produce.
Returns 0 if the key is not one that is used to type Unicode characters.
If the return value has bit
COMBINING_ACCENT
set, the key is a "dead key" that should be combined with another to
actually produce a character -- see getDeadChar(int, int)
--
after masking with
COMBINING_ACCENT_MASK
.
Returns the pressed state of the ALT meta key.
For ACTION_UP
events, indicates that the event has been
canceled as per FLAG_CANCELED
.
For ACTION_DOWN
events, indicates that the event has been
canceled as per FLAG_LONG_PRESS
.
Returns true if this key code is a modifier key.
KEYCODE_SHIFT_LEFT
KEYCODE_SHIFT_RIGHT
,
KEYCODE_ALT_LEFT
, KEYCODE_ALT_RIGHT
or KEYCODE_SYM
.
Returns the pressed state of the SHIFT meta key.
Returns the pressed state of the SYM meta key.
Is this a system key? System keys can not be used for menu shortcuts. TODO: this information should come from a table somewhere. TODO: should the dpad keys be here? arguably, because they also shouldn't be menu shortcuts
For ACTION_UP
events, indicates that the event is still being
tracked from its initial down event as per
FLAG_TRACKING
.
Call this during onKeyDown(int, KeyEvent)
to have the system track
the key through its final up (possibly including a long press). Note
that only one key can be tracked at a time -- if another key down
event is received while a previous one is being tracked, tracking is
stopped on the previous event.
Returns a string containing a concise, human-readable description of this
object. Subclasses are encouraged to override this method and provide an
implementation that takes into account the object's type and data. The
default implementation simply concatenates the class name, the '@' sign
and a hexadecimal representation of the object's hashCode()
,
that is, it is equivalent to the following expression:
getClass().getName() + '@' + Integer.toHexString(hashCode())
Flatten this object in to a Parcel.
out | The Parcel in which the object should be written. |
---|---|
flags | Additional flags about how the object should be written.
May be 0 or PARCELABLE_WRITE_RETURN_VALUE .
|