java.lang.Object | ||
↳ | android.view.InputEvent | |
↳ | android.view.KeyEvent |
Object used to report key and button events.
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 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.
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. |
|||||||||
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_FALLBACK | Set when a key event has been synthesized to implement default behavior for an event that the application did not handle. | |||||||||
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 | Key code constant: '0' key. | |||||||||
int | KEYCODE_1 | Key code constant: '1' key. | |||||||||
int | KEYCODE_2 | Key code constant: '2' key. | |||||||||
int | KEYCODE_3 | Key code constant: '3' key. | |||||||||
int | KEYCODE_3D_MODE | Key code constant: 3D Mode key. | |||||||||
int | KEYCODE_4 | Key code constant: '4' key. | |||||||||
int | KEYCODE_5 | Key code constant: '5' key. | |||||||||
int | KEYCODE_6 | Key code constant: '6' key. | |||||||||
int | KEYCODE_7 | Key code constant: '7' key. | |||||||||
int | KEYCODE_8 | Key code constant: '8' key. | |||||||||
int | KEYCODE_9 | Key code constant: '9' key. | |||||||||
int | KEYCODE_A | Key code constant: 'A' key. | |||||||||
int | KEYCODE_ALT_LEFT | Key code constant: Left Alt modifier key. | |||||||||
int | KEYCODE_ALT_RIGHT | Key code constant: Right Alt modifier key. | |||||||||
int | KEYCODE_APOSTROPHE | Key code constant: ''' (apostrophe) key. | |||||||||
int | KEYCODE_APP_SWITCH | Key code constant: App switch key. | |||||||||
int | KEYCODE_ASSIST | Key code constant: Assist key. | |||||||||
int | KEYCODE_AT | Key code constant: '@' key. | |||||||||
int | KEYCODE_AVR_INPUT | Key code constant: A/V Receiver input key. | |||||||||
int | KEYCODE_AVR_POWER | Key code constant: A/V Receiver power key. | |||||||||
int | KEYCODE_B | Key code constant: 'B' key. | |||||||||
int | KEYCODE_BACK | Key code constant: Back key. | |||||||||
int | KEYCODE_BACKSLASH | Key code constant: '\' key. | |||||||||
int | KEYCODE_BOOKMARK | Key code constant: Bookmark key. | |||||||||
int | KEYCODE_BREAK | Key code constant: Break / Pause key. | |||||||||
int | KEYCODE_BRIGHTNESS_DOWN | Key code constant: Brightness Down key. | |||||||||
int | KEYCODE_BRIGHTNESS_UP | Key code constant: Brightness Up key. | |||||||||
int | KEYCODE_BUTTON_1 | Key code constant: Generic Game Pad Button #1. | |||||||||
int | KEYCODE_BUTTON_10 | Key code constant: Generic Game Pad Button #10. | |||||||||
int | KEYCODE_BUTTON_11 | Key code constant: Generic Game Pad Button #11. | |||||||||
int | KEYCODE_BUTTON_12 | Key code constant: Generic Game Pad Button #12. | |||||||||
int | KEYCODE_BUTTON_13 | Key code constant: Generic Game Pad Button #13. | |||||||||
int | KEYCODE_BUTTON_14 | Key code constant: Generic Game Pad Button #14. | |||||||||
int | KEYCODE_BUTTON_15 | Key code constant: Generic Game Pad Button #15. | |||||||||
int | KEYCODE_BUTTON_16 | Key code constant: Generic Game Pad Button #16. | |||||||||
int | KEYCODE_BUTTON_2 | Key code constant: Generic Game Pad Button #2. | |||||||||
int | KEYCODE_BUTTON_3 | Key code constant: Generic Game Pad Button #3. | |||||||||
int | KEYCODE_BUTTON_4 | Key code constant: Generic Game Pad Button #4. | |||||||||
int | KEYCODE_BUTTON_5 | Key code constant: Generic Game Pad Button #5. | |||||||||
int | KEYCODE_BUTTON_6 | Key code constant: Generic Game Pad Button #6. | |||||||||
int | KEYCODE_BUTTON_7 | Key code constant: Generic Game Pad Button #7. | |||||||||
int | KEYCODE_BUTTON_8 | Key code constant: Generic Game Pad Button #8. | |||||||||
int | KEYCODE_BUTTON_9 | Key code constant: Generic Game Pad Button #9. | |||||||||
int | KEYCODE_BUTTON_A | Key code constant: A Button key. | |||||||||
int | KEYCODE_BUTTON_B | Key code constant: B Button key. | |||||||||
int | KEYCODE_BUTTON_C | Key code constant: C Button key. | |||||||||
int | KEYCODE_BUTTON_L1 | Key code constant: L1 Button key. | |||||||||
int | KEYCODE_BUTTON_L2 | Key code constant: L2 Button key. | |||||||||
int | KEYCODE_BUTTON_MODE | Key code constant: Mode Button key. | |||||||||
int | KEYCODE_BUTTON_R1 | Key code constant: R1 Button key. | |||||||||
int | KEYCODE_BUTTON_R2 | Key code constant: R2 Button key. | |||||||||
int | KEYCODE_BUTTON_SELECT | Key code constant: Select Button key. | |||||||||
int | KEYCODE_BUTTON_START | Key code constant: Start Button key. | |||||||||
int | KEYCODE_BUTTON_THUMBL | Key code constant: Left Thumb Button key. | |||||||||
int | KEYCODE_BUTTON_THUMBR | Key code constant: Right Thumb Button key. | |||||||||
int | KEYCODE_BUTTON_X | Key code constant: X Button key. | |||||||||
int | KEYCODE_BUTTON_Y | Key code constant: Y Button key. | |||||||||
int | KEYCODE_BUTTON_Z | Key code constant: Z Button key. | |||||||||
int | KEYCODE_C | Key code constant: 'C' key. | |||||||||
int | KEYCODE_CALCULATOR | Key code constant: Calculator special function key. | |||||||||
int | KEYCODE_CALENDAR | Key code constant: Calendar special function key. | |||||||||
int | KEYCODE_CALL | Key code constant: Call key. | |||||||||
int | KEYCODE_CAMERA | Key code constant: Camera key. | |||||||||
int | KEYCODE_CAPS_LOCK | Key code constant: Caps Lock key. | |||||||||
int | KEYCODE_CAPTIONS | Key code constant: Toggle captions key. | |||||||||
int | KEYCODE_CHANNEL_DOWN | Key code constant: Channel down key. | |||||||||
int | KEYCODE_CHANNEL_UP | Key code constant: Channel up key. | |||||||||
int | KEYCODE_CLEAR | Key code constant: Clear key. | |||||||||
int | KEYCODE_COMMA | Key code constant: ',' key. | |||||||||
int | KEYCODE_CONTACTS | Key code constant: Contacts special function key. | |||||||||
int | KEYCODE_CTRL_LEFT | Key code constant: Left Control modifier key. | |||||||||
int | KEYCODE_CTRL_RIGHT | Key code constant: Right Control modifier key. | |||||||||
int | KEYCODE_D | Key code constant: 'D' key. | |||||||||
int | KEYCODE_DEL | Key code constant: Backspace key. | |||||||||
int | KEYCODE_DPAD_CENTER | Key code constant: Directional Pad Center key. | |||||||||
int | KEYCODE_DPAD_DOWN | Key code constant: Directional Pad Down key. | |||||||||
int | KEYCODE_DPAD_LEFT | Key code constant: Directional Pad Left key. | |||||||||
int | KEYCODE_DPAD_RIGHT | Key code constant: Directional Pad Right key. | |||||||||
int | KEYCODE_DPAD_UP | Key code constant: Directional Pad Up key. | |||||||||
int | KEYCODE_DVR | Key code constant: DVR key. | |||||||||
int | KEYCODE_E | Key code constant: 'E' key. | |||||||||
int | KEYCODE_EISU | Key code constant: Japanese alphanumeric key. | |||||||||
int | KEYCODE_ENDCALL | Key code constant: End Call key. | |||||||||
int | KEYCODE_ENTER | Key code constant: Enter key. | |||||||||
int | KEYCODE_ENVELOPE | Key code constant: Envelope special function key. | |||||||||
int | KEYCODE_EQUALS | Key code constant: '=' key. | |||||||||
int | KEYCODE_ESCAPE | Key code constant: Escape key. | |||||||||
int | KEYCODE_EXPLORER | Key code constant: Explorer special function key. | |||||||||
int | KEYCODE_F | Key code constant: 'F' key. | |||||||||
int | KEYCODE_F1 | Key code constant: F1 key. | |||||||||
int | KEYCODE_F10 | Key code constant: F10 key. | |||||||||
int | KEYCODE_F11 | Key code constant: F11 key. | |||||||||
int | KEYCODE_F12 | Key code constant: F12 key. | |||||||||
int | KEYCODE_F2 | Key code constant: F2 key. | |||||||||
int | KEYCODE_F3 | Key code constant: F3 key. | |||||||||
int | KEYCODE_F4 | Key code constant: F4 key. | |||||||||
int | KEYCODE_F5 | Key code constant: F5 key. | |||||||||
int | KEYCODE_F6 | Key code constant: F6 key. | |||||||||
int | KEYCODE_F7 | Key code constant: F7 key. | |||||||||
int | KEYCODE_F8 | Key code constant: F8 key. | |||||||||
int | KEYCODE_F9 | Key code constant: F9 key. | |||||||||
int | KEYCODE_FOCUS | Key code constant: Camera Focus key. | |||||||||
int | KEYCODE_FORWARD | Key code constant: Forward key. | |||||||||
int | KEYCODE_FORWARD_DEL | Key code constant: Forward Delete key. | |||||||||
int | KEYCODE_FUNCTION | Key code constant: Function modifier key. | |||||||||
int | KEYCODE_G | Key code constant: 'G' key. | |||||||||
int | KEYCODE_GRAVE | Key code constant: '`' (backtick) key. | |||||||||
int | KEYCODE_GUIDE | Key code constant: Guide key. | |||||||||
int | KEYCODE_H | Key code constant: 'H' key. | |||||||||
int | KEYCODE_HEADSETHOOK | Key code constant: Headset Hook key. | |||||||||
int | KEYCODE_HENKAN | Key code constant: Japanese conversion key. | |||||||||
int | KEYCODE_HOME | Key code constant: Home key. | |||||||||
int | KEYCODE_I | Key code constant: 'I' key. | |||||||||
int | KEYCODE_INFO | Key code constant: Info key. | |||||||||
int | KEYCODE_INSERT | Key code constant: Insert key. | |||||||||
int | KEYCODE_J | Key code constant: 'J' key. | |||||||||
int | KEYCODE_K | Key code constant: 'K' key. | |||||||||
int | KEYCODE_KANA | Key code constant: Japanese kana key. | |||||||||
int | KEYCODE_KATAKANA_HIRAGANA | Key code constant: Japanese katakana / hiragana key. | |||||||||
int | KEYCODE_L | Key code constant: 'L' key. | |||||||||
int | KEYCODE_LANGUAGE_SWITCH | Key code constant: Language Switch key. | |||||||||
int | KEYCODE_LEFT_BRACKET | Key code constant: '[' key. | |||||||||
int | KEYCODE_M | Key code constant: 'M' key. | |||||||||
int | KEYCODE_MANNER_MODE | Key code constant: Manner Mode key. | |||||||||
int | KEYCODE_MEDIA_AUDIO_TRACK | Key code constant: Audio Track key Switches the audio tracks. | |||||||||
int | KEYCODE_MEDIA_CLOSE | Key code constant: Close media key. | |||||||||
int | KEYCODE_MEDIA_EJECT | Key code constant: Eject media key. | |||||||||
int | KEYCODE_MEDIA_FAST_FORWARD | Key code constant: Fast Forward media key. | |||||||||
int | KEYCODE_MEDIA_NEXT | Key code constant: Play Next media key. | |||||||||
int | KEYCODE_MEDIA_PAUSE | Key code constant: Pause media key. | |||||||||
int | KEYCODE_MEDIA_PLAY | Key code constant: Play media key. | |||||||||
int | KEYCODE_MEDIA_PLAY_PAUSE | Key code constant: Play/Pause media key. | |||||||||
int | KEYCODE_MEDIA_PREVIOUS | Key code constant: Play Previous media key. | |||||||||
int | KEYCODE_MEDIA_RECORD | Key code constant: Record media key. | |||||||||
int | KEYCODE_MEDIA_REWIND | Key code constant: Rewind media key. | |||||||||
int | KEYCODE_MEDIA_STOP | Key code constant: Stop media key. | |||||||||
int | KEYCODE_MENU | Key code constant: Menu key. | |||||||||
int | KEYCODE_META_LEFT | Key code constant: Left Meta modifier key. | |||||||||
int | KEYCODE_META_RIGHT | Key code constant: Right Meta modifier key. | |||||||||
int | KEYCODE_MINUS | Key code constant: '-'. | |||||||||
int | KEYCODE_MOVE_END | Key code constant: End Movement key. | |||||||||
int | KEYCODE_MOVE_HOME | Key code constant: Home Movement key. | |||||||||
int | KEYCODE_MUHENKAN | Key code constant: Japanese non-conversion key. | |||||||||
int | KEYCODE_MUSIC | Key code constant: Music special function key. | |||||||||
int | KEYCODE_MUTE | Key code constant: Mute key. | |||||||||
int | KEYCODE_N | Key code constant: 'N' key. | |||||||||
int | KEYCODE_NOTIFICATION | Key code constant: Notification key. | |||||||||
int | KEYCODE_NUM | Key code constant: Number modifier key. | |||||||||
int | KEYCODE_NUMPAD_0 | Key code constant: Numeric keypad '0' key. | |||||||||
int | KEYCODE_NUMPAD_1 | Key code constant: Numeric keypad '1' key. | |||||||||
int | KEYCODE_NUMPAD_2 | Key code constant: Numeric keypad '2' key. | |||||||||
int | KEYCODE_NUMPAD_3 | Key code constant: Numeric keypad '3' key. | |||||||||
int | KEYCODE_NUMPAD_4 | Key code constant: Numeric keypad '4' key. | |||||||||
int | KEYCODE_NUMPAD_5 | Key code constant: Numeric keypad '5' key. | |||||||||
int | KEYCODE_NUMPAD_6 | Key code constant: Numeric keypad '6' key. | |||||||||
int | KEYCODE_NUMPAD_7 | Key code constant: Numeric keypad '7' key. | |||||||||
int | KEYCODE_NUMPAD_8 | Key code constant: Numeric keypad '8' key. | |||||||||
int | KEYCODE_NUMPAD_9 | Key code constant: Numeric keypad '9' key. | |||||||||
int | KEYCODE_NUMPAD_ADD | Key code constant: Numeric keypad '+' key (for addition). | |||||||||
int | KEYCODE_NUMPAD_COMMA | Key code constant: Numeric keypad ',' key (for decimals or digit grouping). | |||||||||
int | KEYCODE_NUMPAD_DIVIDE | Key code constant: Numeric keypad '/' key (for division). | |||||||||
int | KEYCODE_NUMPAD_DOT | Key code constant: Numeric keypad '.' key (for decimals or digit grouping). | |||||||||
int | KEYCODE_NUMPAD_ENTER | Key code constant: Numeric keypad Enter key. | |||||||||
int | KEYCODE_NUMPAD_EQUALS | Key code constant: Numeric keypad '=' key. | |||||||||
int | KEYCODE_NUMPAD_LEFT_PAREN | Key code constant: Numeric keypad '(' key. | |||||||||
int | KEYCODE_NUMPAD_MULTIPLY | Key code constant: Numeric keypad '*' key (for multiplication). | |||||||||
int | KEYCODE_NUMPAD_RIGHT_PAREN | Key code constant: Numeric keypad ')' key. | |||||||||
int | KEYCODE_NUMPAD_SUBTRACT | Key code constant: Numeric keypad '-' key (for subtraction). | |||||||||
int | KEYCODE_NUM_LOCK | Key code constant: Num Lock key. | |||||||||
int | KEYCODE_O | Key code constant: 'O' key. | |||||||||
int | KEYCODE_P | Key code constant: 'P' key. | |||||||||
int | KEYCODE_PAGE_DOWN | Key code constant: Page Down key. | |||||||||
int | KEYCODE_PAGE_UP | Key code constant: Page Up key. | |||||||||
int | KEYCODE_PERIOD | Key code constant: '.' key. | |||||||||
int | KEYCODE_PICTSYMBOLS | Key code constant: Picture Symbols modifier key. | |||||||||
int | KEYCODE_PLUS | Key code constant: '+' key. | |||||||||
int | KEYCODE_POUND | Key code constant: '#' key. | |||||||||
int | KEYCODE_POWER | Key code constant: Power key. | |||||||||
int | KEYCODE_PROG_BLUE | Key code constant: Blue "programmable" key. | |||||||||
int | KEYCODE_PROG_GREEN | Key code constant: Green "programmable" key. | |||||||||
int | KEYCODE_PROG_RED | Key code constant: Red "programmable" key. | |||||||||
int | KEYCODE_PROG_YELLOW | Key code constant: Yellow "programmable" key. | |||||||||
int | KEYCODE_Q | Key code constant: 'Q' key. | |||||||||
int | KEYCODE_R | Key code constant: 'R' key. | |||||||||
int | KEYCODE_RIGHT_BRACKET | Key code constant: ']' key. | |||||||||
int | KEYCODE_RO | Key code constant: Japanese Ro key. | |||||||||
int | KEYCODE_S | Key code constant: 'S' key. | |||||||||
int | KEYCODE_SCROLL_LOCK | Key code constant: Scroll Lock key. | |||||||||
int | KEYCODE_SEARCH | Key code constant: Search key. | |||||||||
int | KEYCODE_SEMICOLON | Key code constant: ';' key. | |||||||||
int | KEYCODE_SETTINGS | Key code constant: Settings key. | |||||||||
int | KEYCODE_SHIFT_LEFT | Key code constant: Left Shift modifier key. | |||||||||
int | KEYCODE_SHIFT_RIGHT | Key code constant: Right Shift modifier key. | |||||||||
int | KEYCODE_SLASH | Key code constant: '/' key. | |||||||||
int | KEYCODE_SOFT_LEFT | Key code constant: Soft Left key. | |||||||||
int | KEYCODE_SOFT_RIGHT | Key code constant: Soft Right key. | |||||||||
int | KEYCODE_SPACE | Key code constant: Space key. | |||||||||
int | KEYCODE_STAR | Key code constant: '*' key. | |||||||||
int | KEYCODE_STB_INPUT | Key code constant: Set-top-box input key. | |||||||||
int | KEYCODE_STB_POWER | Key code constant: Set-top-box power key. | |||||||||
int | KEYCODE_SWITCH_CHARSET | Key code constant: Switch Charset modifier key. | |||||||||
int | KEYCODE_SYM | Key code constant: Symbol modifier key. | |||||||||
int | KEYCODE_SYSRQ | Key code constant: System Request / Print Screen key. | |||||||||
int | KEYCODE_T | Key code constant: 'T' key. | |||||||||
int | KEYCODE_TAB | Key code constant: Tab key. | |||||||||
int | KEYCODE_TV | Key code constant: TV key. | |||||||||
int | KEYCODE_TV_INPUT | Key code constant: TV input key. | |||||||||
int | KEYCODE_TV_POWER | Key code constant: TV power key. | |||||||||
int | KEYCODE_U | Key code constant: 'U' key. | |||||||||
int | KEYCODE_UNKNOWN | Key code constant: Unknown key code. | |||||||||
int | KEYCODE_V | Key code constant: 'V' key. | |||||||||
int | KEYCODE_VOLUME_DOWN | Key code constant: Volume Down key. | |||||||||
int | KEYCODE_VOLUME_MUTE | Key code constant: Volume Mute key. | |||||||||
int | KEYCODE_VOLUME_UP | Key code constant: Volume Up key. | |||||||||
int | KEYCODE_W | Key code constant: 'W' key. | |||||||||
int | KEYCODE_WINDOW | Key code constant: Window key. | |||||||||
int | KEYCODE_X | Key code constant: 'X' key. | |||||||||
int | KEYCODE_Y | Key code constant: 'Y' key. | |||||||||
int | KEYCODE_YEN | Key code constant: Japanese Yen key. | |||||||||
int | KEYCODE_Z | Key code constant: 'Z' key. | |||||||||
int | KEYCODE_ZENKAKU_HANKAKU | Key code constant: Japanese full-width / half-width key. | |||||||||
int | KEYCODE_ZOOM_IN | Key code constant: Zoom in key. | |||||||||
int | KEYCODE_ZOOM_OUT | Key code constant: Zoom out key. | |||||||||
int | MAX_KEYCODE |
This constant was deprecated
in API level 3.
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_MASK | This mask is a combination of META_ALT_ON , META_ALT_LEFT_ON
and META_ALT_RIGHT_ON . |
|||||||||
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_CAPS_LOCK_ON | This mask is used to check whether the CAPS LOCK meta key is on. |
|||||||||
int | META_CTRL_LEFT_ON | This mask is used to check whether the left CTRL meta key is pressed. |
|||||||||
int | META_CTRL_MASK | This mask is a combination of META_CTRL_ON , META_CTRL_LEFT_ON
and META_CTRL_RIGHT_ON . |
|||||||||
int | META_CTRL_ON | This mask is used to check whether one of the CTRL meta keys is pressed. |
|||||||||
int | META_CTRL_RIGHT_ON | This mask is used to check whether the right CTRL meta key is pressed. |
|||||||||
int | META_FUNCTION_ON | This mask is used to check whether the FUNCTION meta key is pressed. |
|||||||||
int | META_META_LEFT_ON | This mask is used to check whether the left META meta key is pressed. |
|||||||||
int | META_META_MASK | This mask is a combination of META_META_ON , META_META_LEFT_ON
and META_META_RIGHT_ON . |
|||||||||
int | META_META_ON | This mask is used to check whether one of the META meta keys is pressed. |
|||||||||
int | META_META_RIGHT_ON | This mask is used to check whether the right META meta key is pressed. |
|||||||||
int | META_NUM_LOCK_ON | This mask is used to check whether the NUM LOCK meta key is on. |
|||||||||
int | META_SCROLL_LOCK_ON | This mask is used to check whether the SCROLL LOCK meta key is on. |
|||||||||
int | META_SHIFT_LEFT_ON | This mask is used to check whether the left SHIFT meta key is pressed. |
|||||||||
int | META_SHIFT_MASK | This mask is a combination of META_SHIFT_ON , META_SHIFT_LEFT_ON
and META_SHIFT_RIGHT_ON . |
|||||||||
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
android.os.Parcelable
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
CREATOR |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.InputEvent
|
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.
| |||||||||||
Create a new key event for a string of characters.
| |||||||||||
Make an exact copy of an existing key event.
| |||||||||||
This constructor was deprecated
in API level 5.
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.
| |||||||||||
Deliver this key event to a
KeyEvent.Callback interface. | |||||||||||
This method was deprecated
in API level 5.
Use
dispatch(Callback, DispatcherState, Object) instead.
| |||||||||||
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.
| |||||||||||
Gets the id for the device that this event came from.
| |||||||||||
Gets 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.
| |||||||||||
Gets the
KeyCharacterMap associated with the keyboard device. | |||||||||||
Retrieve the key code of the key event.
| |||||||||||
This method was deprecated
in API level 11.
instead use
getDisplayLabel() ,
getNumber() or getUnicodeChar(int) .
| |||||||||||
Gets the first character in the character array that can be generated
by the specified key code.
| |||||||||||
Gets the first character in the character array that can be generated
by the specified key code.
| |||||||||||
Returns the maximum keycode.
| |||||||||||
Returns the state of the meta keys. | |||||||||||
Gets a mask that includes all valid modifier key meta state bits.
| |||||||||||
Returns the state of the modifier 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.
| |||||||||||
Gets the source of the event.
| |||||||||||
Gets the Unicode character generated by the specified key and meta
key state combination.
| |||||||||||
Gets the Unicode character generated by the specified key and meta
key state combination.
| |||||||||||
Returns true if only the specified modifiers keys are pressed.
| |||||||||||
Returns true if no modifier keys are pressed.
| |||||||||||
Returns the pressed state of the ALT meta key. | |||||||||||
For
ACTION_UP events, indicates that the event has been
canceled as per FLAG_CANCELED . | |||||||||||
Returns the locked state of the CAPS LOCK meta key. | |||||||||||
Returns the pressed state of the CTRL meta key. | |||||||||||
Returns the pressed state of the FUNCTION meta key. | |||||||||||
Returns true if the specified keycode is a gamepad button.
| |||||||||||
For
ACTION_DOWN events, indicates that the event has been
canceled as per FLAG_LONG_PRESS . | |||||||||||
Returns the pressed state of the META meta key. | |||||||||||
Returns true if this key code is a modifier key.
| |||||||||||
Returns the locked state of the NUM LOCK meta key. | |||||||||||
Returns true if this key produces a glyph.
| |||||||||||
Returns the locked state of the SCROLL LOCK meta key. | |||||||||||
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 . | |||||||||||
Gets a keycode by its symbolic name such as "KEYCODE_A" or an equivalent
numeric constant such as "1001".
| |||||||||||
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.
| |||||||||||
Returns true if only the specified modifier keys are pressed according to
the specified meta state.
| |||||||||||
Returns true if no modifiers keys are pressed according to the specified meta state.
| |||||||||||
Normalizes the specified meta state.
| |||||||||||
Modifies the source of the event.
| |||||||||||
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.InputEvent
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
android.os.Parcelable
|
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 is 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.
Set when a key event has been synthesized to implement default behavior for an event that the application did not handle. Fallback key events are generated by unhandled trackball motions (to emulate a directional keypad) and by certain unhandled key presses that are declared in the key map (such as special function numeric keypad keys when numlock is off).
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.
Key code constant: '0' key.
Key code constant: '1' key.
Key code constant: '2' key.
Key code constant: '3' key.
Key code constant: 3D Mode key. Toggles the display between 2D and 3D mode.
Key code constant: '4' key.
Key code constant: '5' key.
Key code constant: '6' key.
Key code constant: '7' key.
Key code constant: '8' key.
Key code constant: '9' key.
Key code constant: 'A' key.
Key code constant: Left Alt modifier key.
Key code constant: Right Alt modifier key.
Key code constant: ''' (apostrophe) key.
Key code constant: App switch key. Should bring up the application switcher dialog.
Key code constant: Assist key. Launches the global assist activity. Not delivered to applications.
Key code constant: '@' key.
Key code constant: A/V Receiver input key. On TV remotes, switches the input mode on an external A/V Receiver.
Key code constant: A/V Receiver power key. On TV remotes, toggles the power on an external A/V Receiver.
Key code constant: 'B' key.
Key code constant: Back key.
Key code constant: '\' key.
Key code constant: Bookmark key. On some TV remotes, bookmarks content or web pages.
Key code constant: Break / Pause key.
Key code constant: Brightness Down key. Adjusts the screen brightness down.
Key code constant: Brightness Up key. Adjusts the screen brightness up.
Key code constant: Generic Game Pad Button #1.
Key code constant: Generic Game Pad Button #10.
Key code constant: Generic Game Pad Button #11.
Key code constant: Generic Game Pad Button #12.
Key code constant: Generic Game Pad Button #13.
Key code constant: Generic Game Pad Button #14.
Key code constant: Generic Game Pad Button #15.
Key code constant: Generic Game Pad Button #16.
Key code constant: Generic Game Pad Button #2.
Key code constant: Generic Game Pad Button #3.
Key code constant: Generic Game Pad Button #4.
Key code constant: Generic Game Pad Button #5.
Key code constant: Generic Game Pad Button #6.
Key code constant: Generic Game Pad Button #7.
Key code constant: Generic Game Pad Button #8.
Key code constant: Generic Game Pad Button #9.
Key code constant: A Button key. On a game controller, the A button should be either the button labeled A or the first button on the bottom row of controller buttons.
Key code constant: B Button key. On a game controller, the B button should be either the button labeled B or the second button on the bottom row of controller buttons.
Key code constant: C Button key. On a game controller, the C button should be either the button labeled C or the third button on the bottom row of controller buttons.
Key code constant: L1 Button key. On a game controller, the L1 button should be either the button labeled L1 (or L) or the top left trigger button.
Key code constant: L2 Button key. On a game controller, the L2 button should be either the button labeled L2 or the bottom left trigger button.
Key code constant: Mode Button key. On a game controller, the button labeled Mode.
Key code constant: R1 Button key. On a game controller, the R1 button should be either the button labeled R1 (or R) or the top right trigger button.
Key code constant: R2 Button key. On a game controller, the R2 button should be either the button labeled R2 or the bottom right trigger button.
Key code constant: Select Button key. On a game controller, the button labeled Select.
Key code constant: Start Button key. On a game controller, the button labeled Start.
Key code constant: Left Thumb Button key. On a game controller, the left thumb button indicates that the left (or only) joystick is pressed.
Key code constant: Right Thumb Button key. On a game controller, the right thumb button indicates that the right joystick is pressed.
Key code constant: X Button key. On a game controller, the X button should be either the button labeled X or the first button on the upper row of controller buttons.
Key code constant: Y Button key. On a game controller, the Y button should be either the button labeled Y or the second button on the upper row of controller buttons.
Key code constant: Z Button key. On a game controller, the Z button should be either the button labeled Z or the third button on the upper row of controller buttons.
Key code constant: 'C' key.
Key code constant: Calculator special function key. Used to launch a calculator application.
Key code constant: Calendar special function key. Used to launch a calendar application.
Key code constant: Call key.
Key code constant: Camera key. Used to launch a camera application or take pictures.
Key code constant: Caps Lock key.
Key code constant: Toggle captions key. Switches the mode for closed-captioning text, for example during television shows.
Key code constant: Channel down key. On TV remotes, decrements the television channel.
Key code constant: Channel up key. On TV remotes, increments the television channel.
Key code constant: Clear key.
Key code constant: ',' key.
Key code constant: Contacts special function key. Used to launch an address book application.
Key code constant: Left Control modifier key.
Key code constant: Right Control modifier key.
Key code constant: 'D' key.
Key code constant: Backspace key.
Deletes characters before the insertion point, unlike KEYCODE_FORWARD_DEL
.
Key code constant: Directional Pad Center key. May also be synthesized from trackball motions.
Key code constant: Directional Pad Down key. May also be synthesized from trackball motions.
Key code constant: Directional Pad Left key. May also be synthesized from trackball motions.
Key code constant: Directional Pad Right key. May also be synthesized from trackball motions.
Key code constant: Directional Pad Up key. May also be synthesized from trackball motions.
Key code constant: DVR key. On some TV remotes, switches to a DVR mode for recorded shows.
Key code constant: 'E' key.
Key code constant: Japanese alphanumeric key.
Key code constant: End Call key.
Key code constant: Enter key.
Key code constant: Envelope special function key. Used to launch a mail application.
Key code constant: '=' key.
Key code constant: Escape key.
Key code constant: Explorer special function key. Used to launch a browser application.
Key code constant: 'F' key.
Key code constant: F1 key.
Key code constant: F10 key.
Key code constant: F11 key.
Key code constant: F12 key.
Key code constant: F2 key.
Key code constant: F3 key.
Key code constant: F4 key.
Key code constant: F5 key.
Key code constant: F6 key.
Key code constant: F7 key.
Key code constant: F8 key.
Key code constant: F9 key.
Key code constant: Camera Focus key. Used to focus the camera.
Key code constant: Forward key.
Navigates forward in the history stack. Complement of KEYCODE_BACK
.
Key code constant: Forward Delete key.
Deletes characters ahead of the insertion point, unlike KEYCODE_DEL
.
Key code constant: Function modifier key.
Key code constant: 'G' key.
Key code constant: '`' (backtick) key.
Key code constant: Guide key. On TV remotes, shows a programming guide.
Key code constant: 'H' key.
Key code constant: Headset Hook key. Used to hang up calls and stop media.
Key code constant: Japanese conversion key.
Key code constant: Home key. This key is handled by the framework and is never delivered to applications.
Key code constant: 'I' key.
Key code constant: Info key. Common on TV remotes to show additional information related to what is currently being viewed.
Key code constant: Insert key. Toggles insert / overwrite edit mode.
Key code constant: 'J' key.
Key code constant: 'K' key.
Key code constant: Japanese kana key.
Key code constant: Japanese katakana / hiragana key.
Key code constant: 'L' key.
Key code constant: Language Switch key. Toggles the current input language such as switching between English and Japanese on a QWERTY keyboard. On some devices, the same function may be performed by pressing Shift+Spacebar.
Key code constant: '[' key.
Key code constant: 'M' key.
Key code constant: Manner Mode key. Toggles silent or vibrate mode on and off to make the device behave more politely in certain settings such as on a crowded train. On some devices, the key may only operate when long-pressed.
Key code constant: Audio Track key Switches the audio tracks.
Key code constant: Close media key. May be used to close a CD tray, for example.
Key code constant: Eject media key. May be used to eject a CD tray, for example.
Key code constant: Fast Forward media key.
Key code constant: Play Next media key.
Key code constant: Pause media key.
Key code constant: Play media key.
Key code constant: Play/Pause media key.
Key code constant: Play Previous media key.
Key code constant: Record media key.
Key code constant: Rewind media key.
Key code constant: Stop media key.
Key code constant: Menu key.
Key code constant: Left Meta modifier key.
Key code constant: Right Meta modifier key.
Key code constant: '-'.
Key code constant: End Movement key. Used for scrolling or moving the cursor around to the end of a line or to the bottom of a list.
Key code constant: Home Movement key. Used for scrolling or moving the cursor around to the start of a line or to the top of a list.
Key code constant: Japanese non-conversion key.
Key code constant: Music special function key. Used to launch a music player application.
Key code constant: Mute key.
Mutes the microphone, unlike KEYCODE_VOLUME_MUTE
.
Key code constant: 'N' key.
Key code constant: Notification key.
Key code constant: Number modifier key.
Used to enter numeric symbols.
This key is not Num Lock; it is more like KEYCODE_ALT_LEFT
and is
interpreted as an ALT key by MetaKeyKeyListener
.
Key code constant: Numeric keypad '0' key.
Key code constant: Numeric keypad '1' key.
Key code constant: Numeric keypad '2' key.
Key code constant: Numeric keypad '3' key.
Key code constant: Numeric keypad '4' key.
Key code constant: Numeric keypad '5' key.
Key code constant: Numeric keypad '6' key.
Key code constant: Numeric keypad '7' key.
Key code constant: Numeric keypad '8' key.
Key code constant: Numeric keypad '9' key.
Key code constant: Numeric keypad '+' key (for addition).
Key code constant: Numeric keypad ',' key (for decimals or digit grouping).
Key code constant: Numeric keypad '/' key (for division).
Key code constant: Numeric keypad '.' key (for decimals or digit grouping).
Key code constant: Numeric keypad Enter key.
Key code constant: Numeric keypad '=' key.
Key code constant: Numeric keypad '(' key.
Key code constant: Numeric keypad '*' key (for multiplication).
Key code constant: Numeric keypad ')' key.
Key code constant: Numeric keypad '-' key (for subtraction).
Key code constant: Num Lock key.
This is the Num Lock key; it is different from KEYCODE_NUM
.
This key alters the behavior of other keys on the numeric keypad.
Key code constant: 'O' key.
Key code constant: 'P' key.
Key code constant: Page Down key.
Key code constant: Page Up key.
Key code constant: '.' key.
Key code constant: Picture Symbols modifier key. Used to switch symbol sets (Emoji, Kao-moji).
Key code constant: '+' key.
Key code constant: '#' key.
Key code constant: Power key.
Key code constant: Blue "programmable" key. On TV remotes, acts as a contextual/programmable key.
Key code constant: Green "programmable" key. On TV remotes, actsas a contextual/programmable key.
Key code constant: Red "programmable" key. On TV remotes, acts as a contextual/programmable key.
Key code constant: Yellow "programmable" key. On TV remotes, acts as a contextual/programmable key.
Key code constant: 'Q' key.
Key code constant: 'R' key.
Key code constant: ']' key.
Key code constant: Japanese Ro key.
Key code constant: 'S' key.
Key code constant: Scroll Lock key.
Key code constant: Search key.
Key code constant: ';' key.
Key code constant: Settings key. Starts the system settings activity.
Key code constant: Left Shift modifier key.
Key code constant: Right Shift modifier key.
Key code constant: '/' key.
Key code constant: Soft Left key. Usually situated below the display on phones and used as a multi-function feature key for selecting a software defined function shown on the bottom left of the display.
Key code constant: Soft Right key. Usually situated below the display on phones and used as a multi-function feature key for selecting a software defined function shown on the bottom right of the display.
Key code constant: Space key.
Key code constant: '*' key.
Key code constant: Set-top-box input key. On TV remotes, switches the input mode on an external Set-top-box.
Key code constant: Set-top-box power key. On TV remotes, toggles the power on an external Set-top-box.
Key code constant: Switch Charset modifier key. Used to switch character sets (Kanji, Katakana).
Key code constant: Symbol modifier key. Used to enter alternate symbols.
Key code constant: System Request / Print Screen key.
Key code constant: 'T' key.
Key code constant: Tab key.
Key code constant: TV key. On TV remotes, switches to viewing live TV.
Key code constant: TV input key. On TV remotes, switches the input on a television screen.
Key code constant: TV power key. On TV remotes, toggles the power on a television screen.
Key code constant: 'U' key.
Key code constant: Unknown key code.
Key code constant: 'V' key.
Key code constant: Volume Down key. Adjusts the speaker volume down.
Key code constant: Volume Mute key.
Mutes the speaker, unlike 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.
Key code constant: Volume Up key. Adjusts the speaker volume up.
Key code constant: 'W' key.
Key code constant: Window key. On TV remotes, toggles picture-in-picture mode or other windowing functions.
Key code constant: 'X' key.
Key code constant: 'Y' key.
Key code constant: Japanese Yen key.
Key code constant: 'Z' key.
Key code constant: Japanese full-width / half-width key.
Key code constant: Zoom in key.
Key code constant: Zoom out key.
This constant was deprecated
in API level 3.
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 a combination of META_ALT_ON
, META_ALT_LEFT_ON
and META_ALT_RIGHT_ON
.
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 CAPS LOCK meta key is on.
This mask is used to check whether the left CTRL meta key is pressed.
This mask is a combination of META_CTRL_ON
, META_CTRL_LEFT_ON
and META_CTRL_RIGHT_ON
.
This mask is used to check whether one of the CTRL meta keys is pressed.
This mask is used to check whether the right CTRL meta key is pressed.
This mask is used to check whether the FUNCTION meta key is pressed.
This mask is used to check whether the left META meta key is pressed.
This mask is a combination of META_META_ON
, META_META_LEFT_ON
and META_META_RIGHT_ON
.
This mask is used to check whether one of the META meta keys is pressed.
This mask is used to check whether the right META meta key is pressed.
This mask is used to check whether the NUM LOCK meta key is on.
This mask is used to check whether the SCROLL LOCK meta key is on.
This mask is used to check whether the left SHIFT meta key is pressed.
This mask is a combination of META_SHIFT_ON
, META_SHIFT_LEFT_ON
and META_SHIFT_RIGHT_ON
.
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. |
deviceId | 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. |
deviceId | 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.
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. |
deviceId | The device ID that generated the key event. |
scancode | Raw device scan code of the event. |
flags | The flags for this key event |
source | The input source such as SOURCE_KEYBOARD .
|
Create a new key event for a string of characters. The key code,
action, repeat count and source will automatically be set to
KEYCODE_UNKNOWN
, ACTION_MULTIPLE
, 0, and
SOURCE_KEYBOARD
for you.
time | The time (in 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 event |
Make an exact copy of an existing key event.
This constructor was deprecated
in API level 5.
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. |
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 è.
Gets the id for the device that this event came from. An id of zero indicates that 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.
Gets 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.
Gets the KeyCharacterMap
associated with the keyboard device.
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. |
Retrieve the key code of the key event. This is the physical key that was pressed, not the Unicode character.
This method was deprecated
in API level 11.
instead use getDisplayLabel()
,
getNumber()
or getUnicodeChar(int)
.
Get the character conversion data for a given key code.
results | A KeyCharacterMap.KeyData instance that will be
filled with the results. |
---|
Gets the first character in the character array that can be generated by the specified key code.
This is a convenience function that returns the same value as
getMatch(chars, 0)
.
chars | The array of matching characters to consider. |
---|
Gets the first character in the character array that can be generated by the specified key code. If there are multiple choices, prefers the one that would be generated with the specified meta key modifier state.
chars | The array of matching characters to consider. |
---|---|
metaState | The preferred meta key modifier state. |
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()
Gets a mask that includes all valid modifier key meta state bits.
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
.
Returns the state of the modifier keys.
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.
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.
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.
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.
Gets the source of the event.
SOURCE_UNKNOWN
if unknown.Gets the Unicode character generated by the specified key and meta key state combination.
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 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
.
Gets the Unicode character generated by the specified key and meta key state combination.
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 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
.
metaState | The meta key modifier state. |
---|
Returns true if only the specified modifiers keys are pressed. Returns false if a different combination of modifier keys are pressed.
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 modifiers |
---|
Returns true if no modifier keys are pressed.
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)
.
Returns the pressed state of the ALT meta key.
For ACTION_UP
events, indicates that the event has been
canceled as per FLAG_CANCELED
.
Returns the locked state of the CAPS LOCK meta key.
Returns the pressed state of the CTRL meta key.
Returns the pressed state of the FUNCTION meta key.
Returns true if the specified keycode is a gamepad button.
KEYCODE_BUTTON_A
.
For ACTION_DOWN
events, indicates that the event has been
canceled as per FLAG_LONG_PRESS
.
Returns the pressed state of the META meta key.
Returns true if this key code is a modifier key.
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
.
Returns the locked state of the NUM LOCK meta key.
Returns true if this key produces a glyph.
Returns the locked state of the SCROLL LOCK meta key.
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
.
Gets a keycode by its symbolic name such as "KEYCODE_A" or an equivalent numeric constant such as "1001".
symbolicName | The symbolic name of the keycode. |
---|
KEYCODE_UNKNOWN
if not found.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.
keyCode | The key code. |
---|
Returns true if only the specified modifier keys are pressed according to the specified meta state. Returns false if a different combination of modifier keys are pressed.
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 modifiers |
---|
Returns true if no modifiers keys are pressed according to the specified meta state.
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. |
---|
Normalizes the specified meta state.
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.
META_CAP_LOCKED
is translated to META_CAPS_LOCK_ON
.
META_ALT_LOCKED
is translated to META_ALT_ON
.
META_SYM_LOCKED
is translated to META_SYM_ON
.
Undefined meta state bits are removed.
metaState | The meta state. |
---|
Modifies the source of the event.
source | The new source. |
---|
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 is equivalent to the following expression:
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.
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 .
|