public class KeyEvent extends InputEvent implements Parcelable
Each key press is described by a sequence of key events. A key press
starts with a key event with ACTION_DOWN
. If the key is held
sufficiently long that it repeats, then the initial down is followed
additional key events with ACTION_DOWN
and a non-zero value for
getRepeatCount()
. The last key event is a ACTION_UP
for the key up. If the key press is canceled, the key up event will have the
FLAG_CANCELED
flag set.
Key events are generally accompanied by a key code (getKeyCode()
),
scan code (getScanCode()
) and meta state (getMetaState()
).
Key code constants are defined in this class. Scan code constants are raw
device-specific codes obtained from the OS and so are not generally meaningful
to applications unless interpreted using the KeyCharacterMap
.
Meta states describe the pressed state of key modifiers
such as META_SHIFT_ON
or META_ALT_ON
.
Key codes typically correspond one-to-one with individual keys on an input device.
Many keys and key combinations serve quite different functions on different
input devices so care must be taken when interpreting them. Always use the
KeyCharacterMap
associated with the input device when mapping keys
to characters. Be aware that there may be multiple key input devices active
at the same time and each will have its own key character map.
As soft input methods can use multiple and inventive ways of inputting text,
there is no guarantee that any key press on a soft keyboard will generate a key
event: this is left to the IME's discretion, and in fact sending such events is
discouraged. You should never rely on receiving KeyEvents for any key on a soft
input method. In particular, the default software keyboard will never send any
key event to any application targetting Jelly Bean or later, and will only send
events for some presses of the delete and return keys to applications targetting
Ice Cream Sandwich or earlier. Be aware that other software input methods may
never send key events regardless of the version. Consider using editor actions
like EditorInfo.IME_ACTION_DONE
if you need
specific interaction with the software keyboard, as it gives more visibility to
the user as to how your application will react to key presses.
When interacting with an IME, the framework may deliver key events
with the special action ACTION_MULTIPLE
that either specifies
that single repeated key code or a sequence of characters to insert.
In general, the framework cannot guarantee that the key events it delivers
to a view always constitute complete key sequences since some events may be dropped
or modified by containing views before they are delivered. The view implementation
should be prepared to handle FLAG_CANCELED
and should tolerate anomalous
situations such as receiving a new ACTION_DOWN
without first having
received an ACTION_UP
for the prior key press.
Refer to InputDevice
for more information about how different kinds of
input devices and sources represent keys and buttons.
Modifier and Type | Class and Description |
---|---|
static interface |
KeyEvent.Callback |
static class |
KeyEvent.DispatcherState
Use with
dispatch(Callback, DispatcherState, Object)
for more advanced key dispatching, such as long presses. |
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static int |
ACTION_DOWN
getAction() value: the key has been pressed down. |
static int |
ACTION_MULTIPLE
getAction() value: multiple duplicate key events have
occurred in a row, or a complex string is being delivered. |
static int |
ACTION_UP
getAction() value: the key has been released. |
static Parcelable.Creator<KeyEvent> |
CREATOR |
static int |
FLAG_CANCELED
When associated with up key events, this indicates that the key press
has been canceled.
|
static 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. |
static 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".
|
static int |
FLAG_FALLBACK
Set when a key event has been synthesized to implement default behavior
for an event that the application did not handle.
|
static int |
FLAG_FROM_SYSTEM
This mask is set if an event was known to come from a trusted part
of the system.
|
static int |
FLAG_KEEP_TOUCH_MODE
This mask is set if we don't want the key event to cause us to leave
touch mode.
|
static int |
FLAG_LONG_PRESS
This flag is set for the first key repeat that occurs after the
long press timeout.
|
static int |
FLAG_SOFT_KEYBOARD
This mask is set if the key event was generated by a software keyboard.
|
static int |
FLAG_START_TRACKING
Private control to determine when an app is tracking a key sequence.
|
static int |
FLAG_TAINTED
Private flag that indicates when the system has detected that this key event
may be inconsistent with respect to the sequence of previously delivered key events,
such as when a key up event is sent but the key was not down.
|
static int |
FLAG_TRACKING
Set for
ACTION_UP when this event's key code is still being
tracked from its initial down. |
static int |
FLAG_VIRTUAL_HARD_KEY
This key event was generated by a virtual (on-screen) hard key area.
|
static int |
FLAG_WOKE_HERE
This mask is set if the device woke because of this key event.
|
static int |
KEYCODE_0
Key code constant: '0' key.
|
static int |
KEYCODE_1
Key code constant: '1' key.
|
static int |
KEYCODE_2
Key code constant: '2' key.
|
static int |
KEYCODE_3
Key code constant: '3' key.
|
static int |
KEYCODE_3D_MODE
Key code constant: 3D Mode key.
|
static int |
KEYCODE_4
Key code constant: '4' key.
|
static int |
KEYCODE_5
Key code constant: '5' key.
|
static int |
KEYCODE_6
Key code constant: '6' key.
|
static int |
KEYCODE_7
Key code constant: '7' key.
|
static int |
KEYCODE_8
Key code constant: '8' key.
|
static int |
KEYCODE_9
Key code constant: '9' key.
|
static int |
KEYCODE_A
Key code constant: 'A' key.
|
static int |
KEYCODE_ALT_LEFT
Key code constant: Left Alt modifier key.
|
static int |
KEYCODE_ALT_RIGHT
Key code constant: Right Alt modifier key.
|
static int |
KEYCODE_APOSTROPHE
Key code constant: ''' (apostrophe) key.
|
static int |
KEYCODE_APP_SWITCH
Key code constant: App switch key.
|
static int |
KEYCODE_ASSIST
Key code constant: Assist key.
|
static int |
KEYCODE_AT
Key code constant: '@' key.
|
static int |
KEYCODE_AVR_INPUT
Key code constant: A/V Receiver input key.
|
static int |
KEYCODE_AVR_POWER
Key code constant: A/V Receiver power key.
|
static int |
KEYCODE_B
Key code constant: 'B' key.
|
static int |
KEYCODE_BACK
Key code constant: Back key.
|
static int |
KEYCODE_BACKSLASH
Key code constant: '\' key.
|
static int |
KEYCODE_BOOKMARK
Key code constant: Bookmark key.
|
static int |
KEYCODE_BREAK
Key code constant: Break / Pause key.
|
static int |
KEYCODE_BUTTON_1
Key code constant: Generic Game Pad Button #1.
|
static int |
KEYCODE_BUTTON_10
Key code constant: Generic Game Pad Button #10.
|
static int |
KEYCODE_BUTTON_11
Key code constant: Generic Game Pad Button #11.
|
static int |
KEYCODE_BUTTON_12
Key code constant: Generic Game Pad Button #12.
|
static int |
KEYCODE_BUTTON_13
Key code constant: Generic Game Pad Button #13.
|
static int |
KEYCODE_BUTTON_14
Key code constant: Generic Game Pad Button #14.
|
static int |
KEYCODE_BUTTON_15
Key code constant: Generic Game Pad Button #15.
|
static int |
KEYCODE_BUTTON_16
Key code constant: Generic Game Pad Button #16.
|
static int |
KEYCODE_BUTTON_2
Key code constant: Generic Game Pad Button #2.
|
static int |
KEYCODE_BUTTON_3
Key code constant: Generic Game Pad Button #3.
|
static int |
KEYCODE_BUTTON_4
Key code constant: Generic Game Pad Button #4.
|
static int |
KEYCODE_BUTTON_5
Key code constant: Generic Game Pad Button #5.
|
static int |
KEYCODE_BUTTON_6
Key code constant: Generic Game Pad Button #6.
|
static int |
KEYCODE_BUTTON_7
Key code constant: Generic Game Pad Button #7.
|
static int |
KEYCODE_BUTTON_8
Key code constant: Generic Game Pad Button #8.
|
static int |
KEYCODE_BUTTON_9
Key code constant: Generic Game Pad Button #9.
|
static int |
KEYCODE_BUTTON_A
Key code constant: A Button key.
|
static int |
KEYCODE_BUTTON_B
Key code constant: B Button key.
|
static int |
KEYCODE_BUTTON_C
Key code constant: C Button key.
|
static int |
KEYCODE_BUTTON_L1
Key code constant: L1 Button key.
|
static int |
KEYCODE_BUTTON_L2
Key code constant: L2 Button key.
|
static int |
KEYCODE_BUTTON_MODE
Key code constant: Mode Button key.
|
static int |
KEYCODE_BUTTON_R1
Key code constant: R1 Button key.
|
static int |
KEYCODE_BUTTON_R2
Key code constant: R2 Button key.
|
static int |
KEYCODE_BUTTON_SELECT
Key code constant: Select Button key.
|
static int |
KEYCODE_BUTTON_START
Key code constant: Start Button key.
|
static int |
KEYCODE_BUTTON_THUMBL
Key code constant: Left Thumb Button key.
|
static int |
KEYCODE_BUTTON_THUMBR
Key code constant: Right Thumb Button key.
|
static int |
KEYCODE_BUTTON_X
Key code constant: X Button key.
|
static int |
KEYCODE_BUTTON_Y
Key code constant: Y Button key.
|
static int |
KEYCODE_BUTTON_Z
Key code constant: Z Button key.
|
static int |
KEYCODE_C
Key code constant: 'C' key.
|
static int |
KEYCODE_CALCULATOR
Key code constant: Calculator special function key.
|
static int |
KEYCODE_CALENDAR
Key code constant: Calendar special function key.
|
static int |
KEYCODE_CALL
Key code constant: Call key.
|
static int |
KEYCODE_CAMERA
Key code constant: Camera key.
|
static int |
KEYCODE_CAPS_LOCK
Key code constant: Caps Lock key.
|
static int |
KEYCODE_CAPTIONS
Key code constant: Toggle captions key.
|
static int |
KEYCODE_CHANNEL_DOWN
Key code constant: Channel down key.
|
static int |
KEYCODE_CHANNEL_UP
Key code constant: Channel up key.
|
static int |
KEYCODE_CLEAR
Key code constant: Clear key.
|
static int |
KEYCODE_COMMA
Key code constant: ',' key.
|
static int |
KEYCODE_CONTACTS
Key code constant: Contacts special function key.
|
static int |
KEYCODE_CTRL_LEFT
Key code constant: Left Control modifier key.
|
static int |
KEYCODE_CTRL_RIGHT
Key code constant: Right Control modifier key.
|
static int |
KEYCODE_D
Key code constant: 'D' key.
|
static int |
KEYCODE_DEL
Key code constant: Backspace key.
|
static int |
KEYCODE_DPAD_CENTER
Key code constant: Directional Pad Center key.
|
static int |
KEYCODE_DPAD_DOWN
Key code constant: Directional Pad Down key.
|
static int |
KEYCODE_DPAD_LEFT
Key code constant: Directional Pad Left key.
|
static int |
KEYCODE_DPAD_RIGHT
Key code constant: Directional Pad Right key.
|
static int |
KEYCODE_DPAD_UP
Key code constant: Directional Pad Up key.
|
static int |
KEYCODE_DVR
Key code constant: DVR key.
|
static int |
KEYCODE_E
Key code constant: 'E' key.
|
static int |
KEYCODE_EISU
Key code constant: Japanese alphanumeric key.
|
static int |
KEYCODE_ENDCALL
Key code constant: End Call key.
|
static int |
KEYCODE_ENTER
Key code constant: Enter key.
|
static int |
KEYCODE_ENVELOPE
Key code constant: Envelope special function key.
|
static int |
KEYCODE_EQUALS
Key code constant: '=' key.
|
static int |
KEYCODE_ESCAPE
Key code constant: Escape key.
|
static int |
KEYCODE_EXPLORER
Key code constant: Explorer special function key.
|
static int |
KEYCODE_F
Key code constant: 'F' key.
|
static int |
KEYCODE_F1
Key code constant: F1 key.
|
static int |
KEYCODE_F10
Key code constant: F10 key.
|
static int |
KEYCODE_F11
Key code constant: F11 key.
|
static int |
KEYCODE_F12
Key code constant: F12 key.
|
static int |
KEYCODE_F2
Key code constant: F2 key.
|
static int |
KEYCODE_F3
Key code constant: F3 key.
|
static int |
KEYCODE_F4
Key code constant: F4 key.
|
static int |
KEYCODE_F5
Key code constant: F5 key.
|
static int |
KEYCODE_F6
Key code constant: F6 key.
|
static int |
KEYCODE_F7
Key code constant: F7 key.
|
static int |
KEYCODE_F8
Key code constant: F8 key.
|
static int |
KEYCODE_F9
Key code constant: F9 key.
|
static int |
KEYCODE_FOCUS
Key code constant: Camera Focus key.
|
static int |
KEYCODE_FORWARD
Key code constant: Forward key.
|
static int |
KEYCODE_FORWARD_DEL
Key code constant: Forward Delete key.
|
static int |
KEYCODE_FUNCTION
Key code constant: Function modifier key.
|
static int |
KEYCODE_G
Key code constant: 'G' key.
|
static int |
KEYCODE_GRAVE
Key code constant: '`' (backtick) key.
|
static int |
KEYCODE_GUIDE
Key code constant: Guide key.
|
static int |
KEYCODE_H
Key code constant: 'H' key.
|
static int |
KEYCODE_HEADSETHOOK
Key code constant: Headset Hook key.
|
static int |
KEYCODE_HENKAN
Key code constant: Japanese conversion key.
|
static int |
KEYCODE_HOME
Key code constant: Home key.
|
static int |
KEYCODE_I
Key code constant: 'I' key.
|
static int |
KEYCODE_INFO
Key code constant: Info key.
|
static int |
KEYCODE_INSERT
Key code constant: Insert key.
|
static int |
KEYCODE_J
Key code constant: 'J' key.
|
static int |
KEYCODE_K
Key code constant: 'K' key.
|
static int |
KEYCODE_KANA
Key code constant: Japanese kana key.
|
static int |
KEYCODE_KATAKANA_HIRAGANA
Key code constant: Japanese katakana / hiragana key.
|
static int |
KEYCODE_L
Key code constant: 'L' key.
|
static int |
KEYCODE_LANGUAGE_SWITCH
Key code constant: Language Switch key.
|
static int |
KEYCODE_LEFT_BRACKET
Key code constant: '[' key.
|
static int |
KEYCODE_M
Key code constant: 'M' key.
|
static int |
KEYCODE_MANNER_MODE
Key code constant: Manner Mode key.
|
static int |
KEYCODE_MEDIA_CLOSE
Key code constant: Close media key.
|
static int |
KEYCODE_MEDIA_EJECT
Key code constant: Eject media key.
|
static int |
KEYCODE_MEDIA_FAST_FORWARD
Key code constant: Fast Forward media key.
|
static int |
KEYCODE_MEDIA_NEXT
Key code constant: Play Next media key.
|
static int |
KEYCODE_MEDIA_PAUSE
Key code constant: Pause media key.
|
static int |
KEYCODE_MEDIA_PLAY
Key code constant: Play media key.
|
static int |
KEYCODE_MEDIA_PLAY_PAUSE
Key code constant: Play/Pause media key.
|
static int |
KEYCODE_MEDIA_PREVIOUS
Key code constant: Play Previous media key.
|
static int |
KEYCODE_MEDIA_RECORD
Key code constant: Record media key.
|
static int |
KEYCODE_MEDIA_REWIND
Key code constant: Rewind media key.
|
static int |
KEYCODE_MEDIA_STOP
Key code constant: Stop media key.
|
static int |
KEYCODE_MENU
Key code constant: Menu key.
|
static int |
KEYCODE_META_LEFT
Key code constant: Left Meta modifier key.
|
static int |
KEYCODE_META_RIGHT
Key code constant: Right Meta modifier key.
|
static int |
KEYCODE_MINUS
Key code constant: '-'.
|
static int |
KEYCODE_MOVE_END
Key code constant: End Movement key.
|
static int |
KEYCODE_MOVE_HOME
Key code constant: Home Movement key.
|
static int |
KEYCODE_MUHENKAN
Key code constant: Japanese non-conversion key.
|
static int |
KEYCODE_MUSIC
Key code constant: Music special function key.
|
static int |
KEYCODE_MUTE
Key code constant: Mute key.
|
static int |
KEYCODE_N
Key code constant: 'N' key.
|
static int |
KEYCODE_NOTIFICATION
Key code constant: Notification key.
|
static int |
KEYCODE_NUM
Key code constant: Number modifier key.
|
static int |
KEYCODE_NUM_LOCK
Key code constant: Num Lock key.
|
static int |
KEYCODE_NUMPAD_0
Key code constant: Numeric keypad '0' key.
|
static int |
KEYCODE_NUMPAD_1
Key code constant: Numeric keypad '1' key.
|
static int |
KEYCODE_NUMPAD_2
Key code constant: Numeric keypad '2' key.
|
static int |
KEYCODE_NUMPAD_3
Key code constant: Numeric keypad '3' key.
|
static int |
KEYCODE_NUMPAD_4
Key code constant: Numeric keypad '4' key.
|
static int |
KEYCODE_NUMPAD_5
Key code constant: Numeric keypad '5' key.
|
static int |
KEYCODE_NUMPAD_6
Key code constant: Numeric keypad '6' key.
|
static int |
KEYCODE_NUMPAD_7
Key code constant: Numeric keypad '7' key.
|
static int |
KEYCODE_NUMPAD_8
Key code constant: Numeric keypad '8' key.
|
static int |
KEYCODE_NUMPAD_9
Key code constant: Numeric keypad '9' key.
|
static int |
KEYCODE_NUMPAD_ADD
Key code constant: Numeric keypad '+' key (for addition).
|
static int |
KEYCODE_NUMPAD_COMMA
Key code constant: Numeric keypad ',' key (for decimals or digit grouping).
|
static int |
KEYCODE_NUMPAD_DIVIDE
Key code constant: Numeric keypad '/' key (for division).
|
static int |
KEYCODE_NUMPAD_DOT
Key code constant: Numeric keypad '.' key (for decimals or digit grouping).
|
static int |
KEYCODE_NUMPAD_ENTER
Key code constant: Numeric keypad Enter key.
|
static int |
KEYCODE_NUMPAD_EQUALS
Key code constant: Numeric keypad '=' key.
|
static int |
KEYCODE_NUMPAD_LEFT_PAREN
Key code constant: Numeric keypad '(' key.
|
static int |
KEYCODE_NUMPAD_MULTIPLY
Key code constant: Numeric keypad '*' key (for multiplication).
|
static int |
KEYCODE_NUMPAD_RIGHT_PAREN
Key code constant: Numeric keypad ')' key.
|
static int |
KEYCODE_NUMPAD_SUBTRACT
Key code constant: Numeric keypad '-' key (for subtraction).
|
static int |
KEYCODE_O
Key code constant: 'O' key.
|
static int |
KEYCODE_P
Key code constant: 'P' key.
|
static int |
KEYCODE_PAGE_DOWN
Key code constant: Page Down key.
|
static int |
KEYCODE_PAGE_UP
Key code constant: Page Up key.
|
static int |
KEYCODE_PERIOD
Key code constant: '.' key.
|
static int |
KEYCODE_PICTSYMBOLS
Key code constant: Picture Symbols modifier key.
|
static int |
KEYCODE_PLUS
Key code constant: '+' key.
|
static int |
KEYCODE_POUND
Key code constant: '#' key.
|
static int |
KEYCODE_POWER
Key code constant: Power key.
|
static int |
KEYCODE_PROG_BLUE
Key code constant: Blue "programmable" key.
|
static int |
KEYCODE_PROG_GREEN
Key code constant: Green "programmable" key.
|
static int |
KEYCODE_PROG_RED
Key code constant: Red "programmable" key.
|
static int |
KEYCODE_PROG_YELLOW
Key code constant: Yellow "programmable" key.
|
static int |
KEYCODE_Q
Key code constant: 'Q' key.
|
static int |
KEYCODE_R
Key code constant: 'R' key.
|
static int |
KEYCODE_RIGHT_BRACKET
Key code constant: ']' key.
|
static int |
KEYCODE_RO
Key code constant: Japanese Ro key.
|
static int |
KEYCODE_S
Key code constant: 'S' key.
|
static int |
KEYCODE_SCROLL_LOCK
Key code constant: Scroll Lock key.
|
static int |
KEYCODE_SEARCH
Key code constant: Search key.
|
static int |
KEYCODE_SEMICOLON
Key code constant: ';' key.
|
static int |
KEYCODE_SETTINGS
Key code constant: Settings key.
|
static int |
KEYCODE_SHIFT_LEFT
Key code constant: Left Shift modifier key.
|
static int |
KEYCODE_SHIFT_RIGHT
Key code constant: Right Shift modifier key.
|
static int |
KEYCODE_SLASH
Key code constant: '/' key.
|
static int |
KEYCODE_SOFT_LEFT
Key code constant: Soft Left key.
|
static int |
KEYCODE_SOFT_RIGHT
Key code constant: Soft Right key.
|
static int |
KEYCODE_SPACE
Key code constant: Space key.
|
static int |
KEYCODE_STAR
Key code constant: '*' key.
|
static int |
KEYCODE_STB_INPUT
Key code constant: Set-top-box input key.
|
static int |
KEYCODE_STB_POWER
Key code constant: Set-top-box power key.
|
static int |
KEYCODE_SWITCH_CHARSET
Key code constant: Switch Charset modifier key.
|
static int |
KEYCODE_SYM
Key code constant: Symbol modifier key.
|
static int |
KEYCODE_SYSRQ
Key code constant: System Request / Print Screen key.
|
static int |
KEYCODE_T
Key code constant: 'T' key.
|
static int |
KEYCODE_TAB
Key code constant: Tab key.
|
static int |
KEYCODE_TV
Key code constant: TV key.
|
static int |
KEYCODE_TV_INPUT
Key code constant: TV input key.
|
static int |
KEYCODE_TV_POWER
Key code constant: TV power key.
|
static int |
KEYCODE_U
Key code constant: 'U' key.
|
static int |
KEYCODE_UNKNOWN
Key code constant: Unknown key code.
|
static int |
KEYCODE_V
Key code constant: 'V' key.
|
static int |
KEYCODE_VOLUME_DOWN
Key code constant: Volume Down key.
|
static int |
KEYCODE_VOLUME_MUTE
Key code constant: Volume Mute key.
|
static int |
KEYCODE_VOLUME_UP
Key code constant: Volume Up key.
|
static int |
KEYCODE_W
Key code constant: 'W' key.
|
static int |
KEYCODE_WINDOW
Key code constant: Window key.
|
static int |
KEYCODE_X
Key code constant: 'X' key.
|
static int |
KEYCODE_Y
Key code constant: 'Y' key.
|
static int |
KEYCODE_YEN
Key code constant: Japanese Yen key.
|
static int |
KEYCODE_Z
Key code constant: 'Z' key.
|
static int |
KEYCODE_ZENKAKU_HANKAKU
Key code constant: Japanese full-width / half-width key.
|
static int |
KEYCODE_ZOOM_IN
Key code constant: Zoom in key.
|
static int |
KEYCODE_ZOOM_OUT
Key code constant: Zoom out key.
|
static int |
MAX_KEYCODE
Deprecated.
There are now more than MAX_KEYCODE keycodes.
Use
getMaxKeyCode() instead. |
static int |
META_ALT_LEFT_ON
This mask is used to check whether the left ALT meta key is pressed.
|
static int |
META_ALT_LOCKED
ALT key locked.
|
static int |
META_ALT_MASK
|
static int |
META_ALT_ON
This mask is used to check whether one of the ALT meta keys is pressed.
|
static int |
META_ALT_RIGHT_ON
This mask is used to check whether the right the ALT meta key is pressed.
|
static int |
META_CAP_LOCKED
SHIFT key locked in CAPS mode.
|
static int |
META_CAPS_LOCK_ON
This mask is used to check whether the CAPS LOCK meta key is on.
|
static int |
META_CTRL_LEFT_ON
This mask is used to check whether the left CTRL meta key is pressed.
|
static int |
META_CTRL_MASK
|
static int |
META_CTRL_ON
This mask is used to check whether one of the CTRL meta keys is pressed.
|
static int |
META_CTRL_RIGHT_ON
This mask is used to check whether the right CTRL meta key is pressed.
|
static int |
META_FUNCTION_ON
This mask is used to check whether the FUNCTION meta key is pressed.
|
static int |
META_META_LEFT_ON
This mask is used to check whether the left META meta key is pressed.
|
static int |
META_META_MASK
|
static int |
META_META_ON
This mask is used to check whether one of the META meta keys is pressed.
|
static int |
META_META_RIGHT_ON
This mask is used to check whether the right META meta key is pressed.
|
static int |
META_NUM_LOCK_ON
This mask is used to check whether the NUM LOCK meta key is on.
|
static int |
META_SCROLL_LOCK_ON
This mask is used to check whether the SCROLL LOCK meta key is on.
|
static int |
META_SELECTING
Text is in selection mode.
|
static int |
META_SHIFT_LEFT_ON
This mask is used to check whether the left SHIFT meta key is pressed.
|
static int |
META_SHIFT_MASK
|
static int |
META_SHIFT_ON
This mask is used to check whether one of the SHIFT meta keys is pressed.
|
static int |
META_SHIFT_RIGHT_ON
This mask is used to check whether the right SHIFT meta key is pressed.
|
static int |
META_SYM_LOCKED
SYM key locked.
|
static int |
META_SYM_ON
This mask is used to check whether the SYM meta key is pressed.
|
mRecycled, mSeq, PARCEL_TOKEN_KEY_EVENT, PARCEL_TOKEN_MOTION_EVENT
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
KeyEvent(int action,
int code)
Create a new key event.
|
KeyEvent(KeyEvent origEvent)
Make an exact copy of an existing key event.
|
KeyEvent(KeyEvent origEvent,
long eventTime,
int newRepeat)
Deprecated.
Use
changeTimeRepeat(KeyEvent, long, int)
instead. |
KeyEvent(long downTime,
long eventTime,
int action,
int code,
int repeat)
Create a new key event.
|
KeyEvent(long downTime,
long eventTime,
int action,
int code,
int repeat,
int metaState)
Create a new key event.
|
KeyEvent(long downTime,
long eventTime,
int action,
int code,
int repeat,
int metaState,
int deviceId,
int scancode)
Create a new key event.
|
KeyEvent(long downTime,
long eventTime,
int action,
int code,
int repeat,
int metaState,
int deviceId,
int scancode,
int flags)
Create a new key event.
|
KeyEvent(long downTime,
long eventTime,
int action,
int code,
int repeat,
int metaState,
int deviceId,
int scancode,
int flags,
int source)
Create a new key event.
|
KeyEvent(long time,
String characters,
int deviceId,
int flags)
Create a new key event for a string of characters.
|
Modifier and Type | Method and Description |
---|---|
static String |
actionToString(int action)
Returns a string that represents the symbolic name of the specified action
such as "ACTION_DOWN", or an equivalent numeric constant such as "35" if unknown.
|
static KeyEvent |
changeAction(KeyEvent event,
int action)
Create a new key event that is the same as the given one, but whose
action is replaced with the given value.
|
static KeyEvent |
changeFlags(KeyEvent event,
int flags)
Create a new key event that is the same as the given one, but whose
flags are replaced with the given value.
|
static KeyEvent |
changeTimeRepeat(KeyEvent event,
long eventTime,
int newRepeat)
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.
|
static KeyEvent |
changeTimeRepeat(KeyEvent event,
long eventTime,
int newRepeat,
int newFlags)
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.
|
KeyEvent |
copy()
Copies the event.
|
static KeyEvent |
createFromParcelBody(Parcel in) |
boolean |
dispatch(KeyEvent.Callback receiver)
Deprecated.
Use
dispatch(Callback, DispatcherState, Object) instead. |
boolean |
dispatch(KeyEvent.Callback receiver,
KeyEvent.DispatcherState state,
Object target)
Deliver this key event to a
KeyEvent.Callback interface. |
int |
getAction()
Retrieve the action of this key event.
|
String |
getCharacters()
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. |
static int |
getDeadChar(int accent,
int c)
Get the character that is produced by putting accent on the character
c.
|
int |
getDeviceId()
Gets the id for the device that this event came from.
|
char |
getDisplayLabel()
Gets the primary character for this key.
|
long |
getDownTime()
Retrieve the time of the most recent key down event,
in the
SystemClock.uptimeMillis() time base. |
long |
getEventTime()
Retrieve the time this event occurred,
in the
SystemClock.uptimeMillis() time base. |
long |
getEventTimeNano()
Retrieve the time this event occurred,
in the
SystemClock.uptimeMillis() time base but with
nanosecond (instead of millisecond) precision. |
int |
getFlags()
Returns the flags for this key event.
|
int |
getKeyboardDevice()
Deprecated.
use
getDeviceId() instead. |
KeyCharacterMap |
getKeyCharacterMap()
Gets the
KeyCharacterMap associated with the keyboard device. |
int |
getKeyCode()
Retrieve the key code of the key event.
|
boolean |
getKeyData(KeyCharacterMap.KeyData results)
Deprecated.
|
char |
getMatch(char[] chars)
Gets the first character in the character array that can be generated
by the specified key code.
|
char |
getMatch(char[] chars,
int metaState)
Gets the first character in the character array that can be generated
by the specified key code.
|
static int |
getMaxKeyCode()
Returns the maximum keycode.
|
int |
getMetaState()
Returns the state of the meta keys.
|
static int |
getModifierMetaStateMask()
Gets a mask that includes all valid modifier key meta state bits.
|
int |
getModifiers()
Returns the state of the modifier keys.
|
char |
getNumber()
Gets the number or symbol associated with the key.
|
int |
getRepeatCount()
Retrieve the repeat count of the event.
|
int |
getScanCode()
Retrieve the hardware key id of this key event.
|
int |
getSource()
Gets the source of the event.
|
int |
getUnicodeChar()
Gets the Unicode character generated by the specified key and meta
key state combination.
|
int |
getUnicodeChar(int metaState)
Gets the Unicode character generated by the specified key and meta
key state combination.
|
boolean |
hasDefaultAction() |
boolean |
hasModifiers(int modifiers)
Returns true if only the specified modifiers keys are pressed.
|
boolean |
hasNoModifiers()
Returns true if no modifier keys are pressed.
|
boolean |
isAltPressed()
Returns the pressed state of the ALT meta key.
|
boolean |
isCanceled()
For
ACTION_UP events, indicates that the event has been
canceled as per FLAG_CANCELED . |
boolean |
isCapsLockOn()
Returns the locked state of the CAPS LOCK meta key.
|
boolean |
isCtrlPressed()
Returns the pressed state of the CTRL meta key.
|
boolean |
isDown()
Deprecated.
|
boolean |
isFunctionPressed()
Returns the pressed state of the FUNCTION meta key.
|
static boolean |
isGamepadButton(int keyCode)
Returns true if the specified keycode is a gamepad button.
|
boolean |
isLongPress()
For
ACTION_DOWN events, indicates that the event has been
canceled as per FLAG_LONG_PRESS . |
boolean |
isMetaPressed()
Returns the pressed state of the META meta key.
|
static boolean |
isModifierKey(int keyCode)
Returns true if this key code is a modifier key.
|
boolean |
isNumLockOn()
Returns the locked state of the NUM LOCK meta key.
|
boolean |
isPrintingKey()
Returns true if this key produces a glyph.
|
boolean |
isScrollLockOn()
Returns the locked state of the SCROLL LOCK meta key.
|
boolean |
isShiftPressed()
Returns the pressed state of the SHIFT meta key.
|
boolean |
isSymPressed()
Returns the pressed state of the SYM meta key.
|
boolean |
isSystem()
Is this a system key? System keys can not be used for menu shortcuts.
|
boolean |
isTainted()
Gets a private flag that indicates when the system has detected that this input event
may be inconsistent with respect to the sequence of previously delivered input events,
such as when a key up event is sent but the key was not down or when a pointer
move event is sent but the pointer is not down.
|
boolean |
isTracking()
For
ACTION_UP events, indicates that the event is still being
tracked from its initial down event as per
FLAG_TRACKING . |
static int |
keyCodeFromString(String symbolicName)
Gets a keycode by its symbolic name such as "KEYCODE_A" or an equivalent
numeric constant such as "1001".
|
static String |
keyCodeToString(int keyCode)
Returns a string that represents the symbolic name of the specified keycode
such as "KEYCODE_A", "KEYCODE_DPAD_UP", or an equivalent numeric constant
such as "1001" if unknown.
|
static boolean |
metaStateHasModifiers(int metaState,
int modifiers)
Returns true if only the specified modifier keys are pressed according to
the specified meta state.
|
static boolean |
metaStateHasNoModifiers(int metaState)
Returns true if no modifiers keys are pressed according to the specified meta state.
|
static String |
metaStateToString(int metaState)
Returns a string that represents the symbolic name of the specified combined meta
key modifier state flags such as "0", "META_SHIFT_ON",
"META_ALT_ON|META_SHIFT_ON" or an equivalent numeric constant such as "0x10000000"
if unknown.
|
static int |
normalizeMetaState(int metaState)
Normalizes the specified meta state.
|
static KeyEvent |
obtain(KeyEvent other)
Obtains a (potentially recycled) copy of another key event.
|
static KeyEvent |
obtain(long downTime,
long eventTime,
int action,
int code,
int repeat,
int metaState,
int deviceId,
int scancode,
int flags,
int source,
String characters)
Obtains a (potentially recycled) key event.
|
void |
recycle()
Recycles a key event.
|
void |
recycleIfNeededAfterDispatch()
Conditionally recycled the event if it is appropriate to do so after
dispatching the event to an application.
|
void |
setSource(int source)
Modifies the source of the event.
|
void |
setTainted(boolean tainted)
Sets a private flag that indicates when the system has detected that this input event
may be inconsistent with respect to the sequence of previously delivered input events,
such as when a key up event is sent but the key was not down or when a pointer
move event is sent but the pointer is not down.
|
void |
startTracking()
Call this during
KeyEvent.Callback.onKeyDown(int, android.view.KeyEvent) to have the system track
the key through its final up (possibly including a long press). |
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
void |
writeToParcel(Parcel out,
int flags)
Flatten this object in to a Parcel.
|
describeContents, getDevice, getSequenceNumber, prepareForReuse
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
describeContents
public static final int KEYCODE_UNKNOWN
public static final int KEYCODE_SOFT_LEFT
public static final int KEYCODE_SOFT_RIGHT
public static final int KEYCODE_HOME
public static final int KEYCODE_BACK
public static final int KEYCODE_CALL
public static final int KEYCODE_ENDCALL
public static final int KEYCODE_0
public static final int KEYCODE_1
public static final int KEYCODE_2
public static final int KEYCODE_3
public static final int KEYCODE_4
public static final int KEYCODE_5
public static final int KEYCODE_6
public static final int KEYCODE_7
public static final int KEYCODE_8
public static final int KEYCODE_9
public static final int KEYCODE_STAR
public static final int KEYCODE_POUND
public static final int KEYCODE_DPAD_UP
public static final int KEYCODE_DPAD_DOWN
public static final int KEYCODE_DPAD_LEFT
public static final int KEYCODE_DPAD_RIGHT
public static final int KEYCODE_DPAD_CENTER
public static final int KEYCODE_VOLUME_UP
public static final int KEYCODE_VOLUME_DOWN
public static final int KEYCODE_POWER
public static final int KEYCODE_CAMERA
public static final int KEYCODE_CLEAR
public static final int KEYCODE_A
public static final int KEYCODE_B
public static final int KEYCODE_C
public static final int KEYCODE_D
public static final int KEYCODE_E
public static final int KEYCODE_F
public static final int KEYCODE_G
public static final int KEYCODE_H
public static final int KEYCODE_I
public static final int KEYCODE_J
public static final int KEYCODE_K
public static final int KEYCODE_L
public static final int KEYCODE_M
public static final int KEYCODE_N
public static final int KEYCODE_O
public static final int KEYCODE_P
public static final int KEYCODE_Q
public static final int KEYCODE_R
public static final int KEYCODE_S
public static final int KEYCODE_T
public static final int KEYCODE_U
public static final int KEYCODE_V
public static final int KEYCODE_W
public static final int KEYCODE_X
public static final int KEYCODE_Y
public static final int KEYCODE_Z
public static final int KEYCODE_COMMA
public static final int KEYCODE_PERIOD
public static final int KEYCODE_ALT_LEFT
public static final int KEYCODE_ALT_RIGHT
public static final int KEYCODE_SHIFT_LEFT
public static final int KEYCODE_SHIFT_RIGHT
public static final int KEYCODE_TAB
public static final int KEYCODE_SPACE
public static final int KEYCODE_SYM
public static final int KEYCODE_EXPLORER
public static final int KEYCODE_ENVELOPE
public static final int KEYCODE_ENTER
public static final int KEYCODE_DEL
KEYCODE_FORWARD_DEL
.public static final int KEYCODE_GRAVE
public static final int KEYCODE_MINUS
public static final int KEYCODE_EQUALS
public static final int KEYCODE_LEFT_BRACKET
public static final int KEYCODE_RIGHT_BRACKET
public static final int KEYCODE_BACKSLASH
public static final int KEYCODE_SEMICOLON
public static final int KEYCODE_APOSTROPHE
public static final int KEYCODE_SLASH
public static final int KEYCODE_AT
public static final int KEYCODE_NUM
KEYCODE_ALT_LEFT
and is
interpreted as an ALT key by MetaKeyKeyListener
.public static final int KEYCODE_HEADSETHOOK
public static final int KEYCODE_FOCUS
public static final int KEYCODE_PLUS
public static final int KEYCODE_MENU
public static final int KEYCODE_NOTIFICATION
public static final int KEYCODE_SEARCH
public static final int KEYCODE_MEDIA_PLAY_PAUSE
public static final int KEYCODE_MEDIA_STOP
public static final int KEYCODE_MEDIA_NEXT
public static final int KEYCODE_MEDIA_PREVIOUS
public static final int KEYCODE_MEDIA_REWIND
public static final int KEYCODE_MEDIA_FAST_FORWARD
public static final int KEYCODE_MUTE
KEYCODE_VOLUME_MUTE
.public static final int KEYCODE_PAGE_UP
public static final int KEYCODE_PAGE_DOWN
public static final int KEYCODE_PICTSYMBOLS
public static final int KEYCODE_SWITCH_CHARSET
public static final int KEYCODE_BUTTON_A
public static final int KEYCODE_BUTTON_B
public static final int KEYCODE_BUTTON_C
public static final int KEYCODE_BUTTON_X
public static final int KEYCODE_BUTTON_Y
public static final int KEYCODE_BUTTON_Z
public static final int KEYCODE_BUTTON_L1
public static final int KEYCODE_BUTTON_R1
public static final int KEYCODE_BUTTON_L2
public static final int KEYCODE_BUTTON_R2
public static final int KEYCODE_BUTTON_THUMBL
public static final int KEYCODE_BUTTON_THUMBR
public static final int KEYCODE_BUTTON_START
public static final int KEYCODE_BUTTON_SELECT
public static final int KEYCODE_BUTTON_MODE
public static final int KEYCODE_ESCAPE
public static final int KEYCODE_FORWARD_DEL
KEYCODE_DEL
.public static final int KEYCODE_CTRL_LEFT
public static final int KEYCODE_CTRL_RIGHT
public static final int KEYCODE_CAPS_LOCK
public static final int KEYCODE_SCROLL_LOCK
public static final int KEYCODE_META_LEFT
public static final int KEYCODE_META_RIGHT
public static final int KEYCODE_FUNCTION
public static final int KEYCODE_SYSRQ
public static final int KEYCODE_BREAK
public static final int KEYCODE_MOVE_HOME
public static final int KEYCODE_MOVE_END
public static final int KEYCODE_INSERT
public static final int KEYCODE_FORWARD
KEYCODE_BACK
.public static final int KEYCODE_MEDIA_PLAY
public static final int KEYCODE_MEDIA_PAUSE
public static final int KEYCODE_MEDIA_CLOSE
public static final int KEYCODE_MEDIA_EJECT
public static final int KEYCODE_MEDIA_RECORD
public static final int KEYCODE_F1
public static final int KEYCODE_F2
public static final int KEYCODE_F3
public static final int KEYCODE_F4
public static final int KEYCODE_F5
public static final int KEYCODE_F6
public static final int KEYCODE_F7
public static final int KEYCODE_F8
public static final int KEYCODE_F9
public static final int KEYCODE_F10
public static final int KEYCODE_F11
public static final int KEYCODE_F12
public static final int KEYCODE_NUM_LOCK
KEYCODE_NUM
.
This key alters the behavior of other keys on the numeric keypad.public static final int KEYCODE_NUMPAD_0
public static final int KEYCODE_NUMPAD_1
public static final int KEYCODE_NUMPAD_2
public static final int KEYCODE_NUMPAD_3
public static final int KEYCODE_NUMPAD_4
public static final int KEYCODE_NUMPAD_5
public static final int KEYCODE_NUMPAD_6
public static final int KEYCODE_NUMPAD_7
public static final int KEYCODE_NUMPAD_8
public static final int KEYCODE_NUMPAD_9
public static final int KEYCODE_NUMPAD_DIVIDE
public static final int KEYCODE_NUMPAD_MULTIPLY
public static final int KEYCODE_NUMPAD_SUBTRACT
public static final int KEYCODE_NUMPAD_ADD
public static final int KEYCODE_NUMPAD_DOT
public static final int KEYCODE_NUMPAD_COMMA
public static final int KEYCODE_NUMPAD_ENTER
public static final int KEYCODE_NUMPAD_EQUALS
public static final int KEYCODE_NUMPAD_LEFT_PAREN
public static final int KEYCODE_NUMPAD_RIGHT_PAREN
public static final int KEYCODE_VOLUME_MUTE
KEYCODE_MUTE
.
This key should normally be implemented as a toggle such that the first press
mutes the speaker and the second press restores the original volume.public static final int KEYCODE_INFO
public static final int KEYCODE_CHANNEL_UP
public static final int KEYCODE_CHANNEL_DOWN
public static final int KEYCODE_ZOOM_IN
public static final int KEYCODE_ZOOM_OUT
public static final int KEYCODE_TV
public static final int KEYCODE_WINDOW
public static final int KEYCODE_GUIDE
public static final int KEYCODE_DVR
public static final int KEYCODE_BOOKMARK
public static final int KEYCODE_CAPTIONS
public static final int KEYCODE_SETTINGS
public static final int KEYCODE_TV_POWER
public static final int KEYCODE_TV_INPUT
public static final int KEYCODE_STB_POWER
public static final int KEYCODE_STB_INPUT
public static final int KEYCODE_AVR_POWER
public static final int KEYCODE_AVR_INPUT
public static final int KEYCODE_PROG_RED
public static final int KEYCODE_PROG_GREEN
public static final int KEYCODE_PROG_YELLOW
public static final int KEYCODE_PROG_BLUE
public static final int KEYCODE_APP_SWITCH
public static final int KEYCODE_BUTTON_1
public static final int KEYCODE_BUTTON_2
public static final int KEYCODE_BUTTON_3
public static final int KEYCODE_BUTTON_4
public static final int KEYCODE_BUTTON_5
public static final int KEYCODE_BUTTON_6
public static final int KEYCODE_BUTTON_7
public static final int KEYCODE_BUTTON_8
public static final int KEYCODE_BUTTON_9
public static final int KEYCODE_BUTTON_10
public static final int KEYCODE_BUTTON_11
public static final int KEYCODE_BUTTON_12
public static final int KEYCODE_BUTTON_13
public static final int KEYCODE_BUTTON_14
public static final int KEYCODE_BUTTON_15
public static final int KEYCODE_BUTTON_16
public static final int KEYCODE_LANGUAGE_SWITCH
public static final int KEYCODE_MANNER_MODE
public static final int KEYCODE_3D_MODE
public static final int KEYCODE_CONTACTS
public static final int KEYCODE_CALENDAR
public static final int KEYCODE_MUSIC
public static final int KEYCODE_CALCULATOR
public static final int KEYCODE_ZENKAKU_HANKAKU
public static final int KEYCODE_EISU
public static final int KEYCODE_MUHENKAN
public static final int KEYCODE_HENKAN
public static final int KEYCODE_KATAKANA_HIRAGANA
public static final int KEYCODE_YEN
public static final int KEYCODE_RO
public static final int KEYCODE_KANA
public static final int KEYCODE_ASSIST
@Deprecated public static final int MAX_KEYCODE
getMaxKeyCode()
instead.public static final int ACTION_DOWN
getAction()
value: the key has been pressed down.public static final int ACTION_UP
getAction()
value: the key has been released.public static final int ACTION_MULTIPLE
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 is KEYCODE_UNKNOWN
, then
this is a sequence of characters as returned by getCharacters()
.public static final int META_CAP_LOCKED
MetaKeyKeyListener
for a published constant in its API.public static final int META_ALT_LOCKED
MetaKeyKeyListener
for a published constant in its API.public static final int META_SYM_LOCKED
MetaKeyKeyListener
for a published constant in its API.public static final int META_SELECTING
MetaKeyKeyListener
for a private unpublished constant
in its API that is currently being retained for legacy reasons.public static final int META_ALT_ON
This mask is used to check whether one of the ALT meta keys is pressed.
public static final int META_ALT_LEFT_ON
This mask is used to check whether the left ALT meta key is pressed.
public static final int META_ALT_RIGHT_ON
This mask is used to check whether the right the ALT meta key is pressed.
public static final int META_SHIFT_ON
This mask is used to check whether one of the SHIFT meta keys is pressed.
public static final int META_SHIFT_LEFT_ON
This mask is used to check whether the left SHIFT meta key is pressed.
public static final int META_SHIFT_RIGHT_ON
This mask is used to check whether the right SHIFT meta key is pressed.
public static final int META_SYM_ON
This mask is used to check whether the SYM meta key is pressed.
isSymPressed()
,
getMetaState()
,
Constant Field Valuespublic static final int META_FUNCTION_ON
This mask is used to check whether the FUNCTION meta key is pressed.
public static final int META_CTRL_ON
This mask is used to check whether one of the CTRL meta keys is pressed.
public static final int META_CTRL_LEFT_ON
This mask is used to check whether the left CTRL meta key is pressed.
public static final int META_CTRL_RIGHT_ON
This mask is used to check whether the right CTRL meta key is pressed.
public static final int META_META_ON
This mask is used to check whether one of the META meta keys is pressed.
public static final int META_META_LEFT_ON
This mask is used to check whether the left META meta key is pressed.
public static final int META_META_RIGHT_ON
This mask is used to check whether the right META meta key is pressed.
public static final int META_CAPS_LOCK_ON
This mask is used to check whether the CAPS LOCK meta key is on.
public static final int META_NUM_LOCK_ON
This mask is used to check whether the NUM LOCK meta key is on.
public static final int META_SCROLL_LOCK_ON
This mask is used to check whether the SCROLL LOCK meta key is on.
public static final int META_SHIFT_MASK
public static final int META_ALT_MASK
public static final int META_CTRL_MASK
public static final int META_META_MASK
public static final int FLAG_WOKE_HERE
public static final int FLAG_SOFT_KEYBOARD
public static final int FLAG_KEEP_TOUCH_MODE
public static final int FLAG_FROM_SYSTEM
public static final int FLAG_EDITOR_ACTION
public static final int FLAG_CANCELED
public static final int FLAG_VIRTUAL_HARD_KEY
public static final int FLAG_LONG_PRESS
public static final int FLAG_CANCELED_LONG_PRESS
FLAG_CANCELED
set because a long
press action was executed while it was down.public static final int FLAG_TRACKING
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.public static final int FLAG_FALLBACK
public static final int FLAG_START_TRACKING
public static final int FLAG_TAINTED
isTainted()
,
setTainted(boolean)
,
Constant Field Valuespublic static final Parcelable.Creator<KeyEvent> CREATOR
public KeyEvent(int action, int code)
action
- Action code: either ACTION_DOWN
,
ACTION_UP
, or ACTION_MULTIPLE
.code
- The key code.public KeyEvent(long downTime, long eventTime, int action, int code, int repeat)
downTime
- The time (in SystemClock.uptimeMillis()
)
at which this key code originally went down.eventTime
- The time (in SystemClock.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.public KeyEvent(long downTime, long eventTime, int action, int code, int repeat, int metaState)
downTime
- The time (in SystemClock.uptimeMillis()
)
at which this key code originally went down.eventTime
- The time (in SystemClock.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.public KeyEvent(long downTime, long eventTime, int action, int code, int repeat, int metaState, int deviceId, int scancode)
downTime
- The time (in SystemClock.uptimeMillis()
)
at which this key code originally went down.eventTime
- The time (in SystemClock.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.deviceId
- The device ID that generated the key event.scancode
- Raw device scan code of the event.public KeyEvent(long downTime, long eventTime, int action, int code, int repeat, int metaState, int deviceId, int scancode, int flags)
downTime
- The time (in SystemClock.uptimeMillis()
)
at which this key code originally went down.eventTime
- The time (in SystemClock.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.deviceId
- The device ID that generated the key event.scancode
- Raw device scan code of the event.flags
- The flags for this key eventpublic KeyEvent(long downTime, long eventTime, int action, int code, int repeat, int metaState, int deviceId, int scancode, int flags, int source)
downTime
- The time (in SystemClock.uptimeMillis()
)
at which this key code originally went down.eventTime
- The time (in SystemClock.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.deviceId
- The device ID that generated the key event.scancode
- Raw device scan code of the event.flags
- The flags for this key eventsource
- The input source such as InputDevice.SOURCE_KEYBOARD
.public KeyEvent(long time, String characters, int deviceId, int flags)
KEYCODE_UNKNOWN
, ACTION_MULTIPLE
, 0, and
InputDevice.SOURCE_KEYBOARD
for you.time
- The time (in SystemClock.uptimeMillis()
)
at which this event occured.characters
- The string of characters.deviceId
- The device ID that generated the key event.flags
- The flags for this key eventpublic KeyEvent(KeyEvent origEvent)
@Deprecated public KeyEvent(KeyEvent origEvent, long eventTime, int newRepeat)
changeTimeRepeat(KeyEvent, long, int)
instead.origEvent
- The existing event to be copied.eventTime
- The new event time
(in SystemClock.uptimeMillis()
) of the event.newRepeat
- The new repeat count of the event.public static int getMaxKeyCode()
public static int getDeadChar(int accent, int c)
public static KeyEvent obtain(long downTime, long eventTime, int action, int code, int repeat, int metaState, int deviceId, int scancode, int flags, int source, String characters)
public static KeyEvent obtain(KeyEvent other)
public KeyEvent copy()
InputEvent
copy
in class InputEvent
public final void recycle()
recycle
in class InputEvent
public final void recycleIfNeededAfterDispatch()
InputEvent
MotionEvent
then it is recycled.
If the event is a KeyEvent
then it is NOT recycled, because applications
expect key events to be immutable so once the event has been dispatched to
the application we can no longer recycle it.recycleIfNeededAfterDispatch
in class InputEvent
public static KeyEvent changeTimeRepeat(KeyEvent event, long eventTime, int newRepeat)
event
- The existing event to be copied. This is not modified.eventTime
- The new event time
(in SystemClock.uptimeMillis()
) of the event.newRepeat
- The new repeat count of the event.public static KeyEvent changeTimeRepeat(KeyEvent event, long eventTime, int newRepeat, int newFlags)
event
- The existing event to be copied. This is not modified.eventTime
- The new event time
(in SystemClock.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.public static KeyEvent changeAction(KeyEvent event, int action)
event
- The existing event to be copied. This is not modified.action
- The new action code of the event.public static KeyEvent changeFlags(KeyEvent event, int flags)
event
- The existing event to be copied. This is not modified.flags
- The new flags constant.public final boolean isTainted()
InputEvent
isTainted
in class InputEvent
public final void setTainted(boolean tainted)
InputEvent
setTainted
in class InputEvent
tainted
- True if this event is tainted.@Deprecated public final boolean isDown()
getAction()
.public final boolean isSystem()
public final boolean hasDefaultAction()
public static final boolean isGamepadButton(int keyCode)
KEYCODE_BUTTON_A
.public final int getDeviceId()
getDeviceId
in class InputEvent
InputDevice.getDevice(int)
public final int getSource()
getSource
in class InputEvent
InputDevice.SOURCE_UNKNOWN
if unknown.InputDevice#getSourceInfo
public final void setSource(int source)
setSource
in class InputEvent
source
- The new source.public final int getMetaState()
Returns the state of the meta keys.
isAltPressed()
,
isShiftPressed()
,
isSymPressed()
,
isCtrlPressed()
,
isMetaPressed()
,
isFunctionPressed()
,
isCapsLockOn()
,
isNumLockOn()
,
isScrollLockOn()
,
META_ALT_ON
,
META_ALT_LEFT_ON
,
META_ALT_RIGHT_ON
,
META_SHIFT_ON
,
META_SHIFT_LEFT_ON
,
META_SHIFT_RIGHT_ON
,
META_SYM_ON
,
META_FUNCTION_ON
,
META_CTRL_ON
,
META_CTRL_LEFT_ON
,
META_CTRL_RIGHT_ON
,
META_META_ON
,
META_META_LEFT_ON
,
META_META_RIGHT_ON
,
META_CAPS_LOCK_ON
,
META_NUM_LOCK_ON
,
META_SCROLL_LOCK_ON
,
getModifiers()
public final int getModifiers()
For the purposes of this function, KEYCODE_CAPS_LOCK
,
KEYCODE_SCROLL_LOCK
, and KEYCODE_NUM_LOCK
are
not considered modifier keys. Consequently, this function specifically masks out
META_CAPS_LOCK_ON
, META_SCROLL_LOCK_ON
and META_NUM_LOCK_ON
.
The value returned consists of the meta state (from getMetaState()
)
normalized using normalizeMetaState(int)
and then masked with
getModifierMetaStateMask()
so that only valid modifier bits are retained.
getMetaState()
public final int getFlags()
FLAG_WOKE_HERE
public static int getModifierMetaStateMask()
For the purposes of this function, KEYCODE_CAPS_LOCK
,
KEYCODE_SCROLL_LOCK
, and KEYCODE_NUM_LOCK
are
not considered modifier keys. Consequently, the mask specifically excludes
META_CAPS_LOCK_ON
, META_SCROLL_LOCK_ON
and META_NUM_LOCK_ON
.
META_SHIFT_ON
, META_SHIFT_LEFT_ON
, META_SHIFT_RIGHT_ON
,
META_ALT_ON
, META_ALT_LEFT_ON
, META_ALT_RIGHT_ON
,
META_CTRL_ON
, META_CTRL_LEFT_ON
, META_CTRL_RIGHT_ON
,
META_META_ON
, META_META_LEFT_ON
, META_META_RIGHT_ON
,
META_SYM_ON
, META_FUNCTION_ON
.public static boolean isModifierKey(int keyCode)
For the purposes of this function, KEYCODE_CAPS_LOCK
,
KEYCODE_SCROLL_LOCK
, and KEYCODE_NUM_LOCK
are
not considered modifier keys. Consequently, this function return false
for those keys.
KEYCODE_SHIFT_LEFT
KEYCODE_SHIFT_RIGHT
,
KEYCODE_ALT_LEFT
, KEYCODE_ALT_RIGHT
,
KEYCODE_CTRL_LEFT
, KEYCODE_CTRL_RIGHT
,
KEYCODE_META_LEFT
, or KEYCODE_META_RIGHT
,
KEYCODE_SYM
, KEYCODE_NUM
, KEYCODE_FUNCTION
.public static int normalizeMetaState(int metaState)
The meta state is normalized such that if either the left or right modifier meta state bits are set then the result will also include the universal bit for that modifier.
If the specified meta state contains META_ALT_LEFT_ON
then
the result will also contain META_ALT_ON
in addition to META_ALT_LEFT_ON
and the other bits that were specified in the input. The same is process is
performed for shift, control and meta.
If the specified meta state contains synthetic meta states defined by
MetaKeyKeyListener
, then those states are translated here and the original
synthetic meta states are removed from the result.
MetaKeyKeyListener.META_CAP_LOCKED
is translated to META_CAPS_LOCK_ON
.
MetaKeyKeyListener.META_ALT_LOCKED
is translated to META_ALT_ON
.
MetaKeyKeyListener.META_SYM_LOCKED
is translated to META_SYM_ON
.
Undefined meta state bits are removed.
metaState
- The meta state.public static boolean metaStateHasNoModifiers(int metaState)
For the purposes of this function, KEYCODE_CAPS_LOCK
,
KEYCODE_SCROLL_LOCK
, and KEYCODE_NUM_LOCK
are
not considered modifier keys. Consequently, this function ignores
META_CAPS_LOCK_ON
, META_SCROLL_LOCK_ON
and META_NUM_LOCK_ON
.
The meta state is normalized prior to comparison using normalizeMetaState(int)
.
metaState
- The meta state to consider.hasNoModifiers()
public static boolean metaStateHasModifiers(int metaState, int modifiers)
For the purposes of this function, KEYCODE_CAPS_LOCK
,
KEYCODE_SCROLL_LOCK
, and KEYCODE_NUM_LOCK
are
not considered modifier keys. Consequently, this function ignores
META_CAPS_LOCK_ON
, META_SCROLL_LOCK_ON
and META_NUM_LOCK_ON
.
If the specified modifier mask includes directional modifiers, such as
META_SHIFT_LEFT_ON
, then this method ensures that the
modifier is pressed on that side.
If the specified modifier mask includes non-directional modifiers, such as
META_SHIFT_ON
, then this method ensures that the modifier
is pressed on either side.
If the specified modifier mask includes both directional and non-directional modifiers
for the same type of key, such as META_SHIFT_ON
and META_SHIFT_LEFT_ON
,
then this method throws an illegal argument exception.
metaState
- The meta state to consider.modifiers
- The meta state of the modifier keys to check. May be a combination
of modifier meta states as defined by getModifierMetaStateMask()
. May be 0 to
ensure that no modifier keys are pressed.IllegalArgumentException
- if the modifiers parameter contains invalid modifiershasModifiers(int)
public final boolean hasNoModifiers()
For the purposes of this function, KEYCODE_CAPS_LOCK
,
KEYCODE_SCROLL_LOCK
, and KEYCODE_NUM_LOCK
are
not considered modifier keys. Consequently, this function ignores
META_CAPS_LOCK_ON
, META_SCROLL_LOCK_ON
and META_NUM_LOCK_ON
.
The meta state is normalized prior to comparison using normalizeMetaState(int)
.
metaStateHasNoModifiers(int)
public final boolean hasModifiers(int modifiers)
For the purposes of this function, KEYCODE_CAPS_LOCK
,
KEYCODE_SCROLL_LOCK
, and KEYCODE_NUM_LOCK
are
not considered modifier keys. Consequently, this function ignores
META_CAPS_LOCK_ON
, META_SCROLL_LOCK_ON
and META_NUM_LOCK_ON
.
If the specified modifier mask includes directional modifiers, such as
META_SHIFT_LEFT_ON
, then this method ensures that the
modifier is pressed on that side.
If the specified modifier mask includes non-directional modifiers, such as
META_SHIFT_ON
, then this method ensures that the modifier
is pressed on either side.
If the specified modifier mask includes both directional and non-directional modifiers
for the same type of key, such as META_SHIFT_ON
and META_SHIFT_LEFT_ON
,
then this method throws an illegal argument exception.
modifiers
- The meta state of the modifier keys to check. May be a combination
of modifier meta states as defined by getModifierMetaStateMask()
. May be 0 to
ensure that no modifier keys are pressed.IllegalArgumentException
- if the modifiers parameter contains invalid modifiersmetaStateHasModifiers(int, int)
public final boolean isAltPressed()
Returns the pressed state of the ALT meta key.
KEYCODE_ALT_LEFT
,
KEYCODE_ALT_RIGHT
,
META_ALT_ON
public final boolean isShiftPressed()
Returns the pressed state of the SHIFT meta key.
KEYCODE_SHIFT_LEFT
,
KEYCODE_SHIFT_RIGHT
,
META_SHIFT_ON
public final boolean isSymPressed()
Returns the pressed state of the SYM meta key.
KEYCODE_SYM
,
META_SYM_ON
public final boolean isCtrlPressed()
Returns the pressed state of the CTRL meta key.
KEYCODE_CTRL_LEFT
,
KEYCODE_CTRL_RIGHT
,
META_CTRL_ON
public final boolean isMetaPressed()
Returns the pressed state of the META meta key.
KEYCODE_META_LEFT
,
KEYCODE_META_RIGHT
,
META_META_ON
public final boolean isFunctionPressed()
Returns the pressed state of the FUNCTION meta key.
KEYCODE_FUNCTION
,
META_FUNCTION_ON
public final boolean isCapsLockOn()
Returns the locked state of the CAPS LOCK meta key.
KEYCODE_CAPS_LOCK
,
META_CAPS_LOCK_ON
public final boolean isNumLockOn()
Returns the locked state of the NUM LOCK meta key.
KEYCODE_NUM_LOCK
,
META_NUM_LOCK_ON
public final boolean isScrollLockOn()
Returns the locked state of the SCROLL LOCK meta key.
KEYCODE_SCROLL_LOCK
,
META_SCROLL_LOCK_ON
public final int getAction()
public final boolean isCanceled()
ACTION_UP
events, indicates that the event has been
canceled as per FLAG_CANCELED
.public final void startTracking()
KeyEvent.Callback.onKeyDown(int, android.view.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.public final boolean isTracking()
ACTION_UP
events, indicates that the event is still being
tracked from its initial down event as per
FLAG_TRACKING
.public final boolean isLongPress()
ACTION_DOWN
events, indicates that the event has been
canceled as per FLAG_LONG_PRESS
.public final int getKeyCode()
public final String getCharacters()
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.public final int getScanCode()
public final int getRepeatCount()
public final long getDownTime()
SystemClock.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.SystemClock.uptimeMillis()
time basepublic final long getEventTime()
SystemClock.uptimeMillis()
time base.getEventTime
in class InputEvent
SystemClock.uptimeMillis()
time base.public final long getEventTimeNano()
SystemClock.uptimeMillis()
time base but with
nanosecond (instead of millisecond) precision.
The value is in nanosecond precision but it may not have nanosecond accuracy.
getEventTimeNano
in class InputEvent
SystemClock.uptimeMillis()
time base but with
nanosecond (instead of millisecond) precision.@Deprecated public final int getKeyboardDevice()
getDeviceId()
instead.getDeviceId()
.public final KeyCharacterMap getKeyCharacterMap()
KeyCharacterMap
associated with the keyboard device.{@link
- KeyCharacterMap.UnavailableException} if the key character map
could not be loaded because it was malformed or the default key character map
is missing from the system.KeyCharacterMap.load(int)
public char getDisplayLabel()
public int getUnicodeChar()
Returns the Unicode character that the specified key would produce
when the specified meta bits (see MetaKeyKeyListener
)
were active.
Returns 0 if the key is not one that is used to type Unicode characters.
If the return value has bit KeyCharacterMap.COMBINING_ACCENT
set, the
key is a "dead key" that should be combined with another to
actually produce a character -- see KeyCharacterMap.getDeadChar(int, int)
--
after masking with KeyCharacterMap.COMBINING_ACCENT_MASK
.
public int getUnicodeChar(int metaState)
Returns the Unicode character that the specified key would produce
when the specified meta bits (see MetaKeyKeyListener
)
were active.
Returns 0 if the key is not one that is used to type Unicode characters.
If the return value has bit KeyCharacterMap.COMBINING_ACCENT
set, the
key is a "dead key" that should be combined with another to
actually produce a character -- see KeyCharacterMap.getDeadChar(int, int)
--
after masking with KeyCharacterMap.COMBINING_ACCENT_MASK
.
metaState
- The meta key modifier state.@Deprecated public boolean getKeyData(KeyCharacterMap.KeyData results)
results
- A KeyCharacterMap.KeyData
instance that will be
filled with the results.public char getMatch(char[] chars)
This is a convenience function that returns the same value as
getMatch(chars, 0)
.
chars
- The array of matching characters to consider.public char getMatch(char[] chars, int metaState)
chars
- The array of matching characters to consider.metaState
- The preferred meta key modifier state.public char getNumber()
The character value is returned, not the numeric value. If the key is not a number, but is a symbol, the symbol is retuned.
This method is intended to to support dial pads and other numeric or symbolic entry on keyboards where certain keys serve dual function as alphabetic and symbolic keys. This method returns the number or symbol associated with the key independent of whether the user has pressed the required modifier.
For example, on one particular keyboard the keys on the top QWERTY row generate
numbers when ALT is pressed such that ALT-Q maps to '1'. So for that keyboard
when getNumber()
is called with KEYCODE_Q
it returns '1'
so that the user can type numbers without pressing ALT when it makes sense.
public boolean isPrintingKey()
@Deprecated public final boolean dispatch(KeyEvent.Callback receiver)
dispatch(Callback, DispatcherState, Object)
instead.public final boolean dispatch(KeyEvent.Callback receiver, KeyEvent.DispatcherState state, Object target)
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.public String toString()
Object
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.
public static String actionToString(int action)
action
- The action.public static String keyCodeToString(int keyCode)
keyCode
- The key code.KeyCharacterMap.getDisplayLabel(int)
public static int keyCodeFromString(String symbolicName)
symbolicName
- The symbolic name of the keycode.KEYCODE_UNKNOWN
if not found.#keycodeToString
public static String metaStateToString(int metaState)
metaState
- The meta state.public void writeToParcel(Parcel out, int flags)
Parcelable
writeToParcel
in interface Parcelable
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.PARCELABLE_WRITE_RETURN_VALUE
.