public class

KeyEvent

extends Object
implements Parcelable
java.lang.Object
   ↳ android.view.KeyEvent

Class Overview

Contains constants for key events.

Summary

Nested Classes
public class KeyEvent.Callback  
Constants
int ACTION_DOWN getAction() value: the key has been pressed down.
int ACTION_MULTIPLE getAction() value: multiple duplicate key events have occurred in a row, or a complex string is being delivered.
int ACTION_UP getAction() value: the key has been released.
Creator<KeyEvent> CREATOR
int FLAG_EDITOR_ACTION This mask is used for compatibility, to identify enter keys that are coming from an IME whose enter key has been auto-labelled "next" or "done".
int FLAG_FROM_SYSTEM This mask is set if an event was known to come from a trusted part of the system.
int FLAG_KEEP_TOUCH_MODE This mask is set if we don't want the key event to cause us to leave touch mode.
int FLAG_SOFT_KEYBOARD This mask is set if the key event was generated by a software keyboard.
int FLAG_WOKE_HERE This mask is set if the device woke because of this key event.
int KEYCODE_0
int KEYCODE_1
int KEYCODE_2
int KEYCODE_3
int KEYCODE_4
int KEYCODE_5
int KEYCODE_6
int KEYCODE_7
int KEYCODE_8
int KEYCODE_9
int KEYCODE_A
int KEYCODE_ALT_LEFT
int KEYCODE_ALT_RIGHT
int KEYCODE_APOSTROPHE
int KEYCODE_AT
int KEYCODE_B
int KEYCODE_BACK
int KEYCODE_BACKSLASH
int KEYCODE_C
int KEYCODE_CALL
int KEYCODE_CAMERA
int KEYCODE_CLEAR
int KEYCODE_COMMA
int KEYCODE_D
int KEYCODE_DEL
int KEYCODE_DPAD_CENTER
int KEYCODE_DPAD_DOWN
int KEYCODE_DPAD_LEFT
int KEYCODE_DPAD_RIGHT
int KEYCODE_DPAD_UP
int KEYCODE_E
int KEYCODE_ENDCALL
int KEYCODE_ENTER
int KEYCODE_ENVELOPE
int KEYCODE_EQUALS
int KEYCODE_EXPLORER
int KEYCODE_F
int KEYCODE_FOCUS
int KEYCODE_G
int KEYCODE_GRAVE
int KEYCODE_H
int KEYCODE_HEADSETHOOK
int KEYCODE_HOME
int KEYCODE_I
int KEYCODE_J
int KEYCODE_K
int KEYCODE_L
int KEYCODE_LEFT_BRACKET
int KEYCODE_M
int KEYCODE_MEDIA_FAST_FORWARD
int KEYCODE_MEDIA_NEXT
int KEYCODE_MEDIA_PLAY_PAUSE
int KEYCODE_MEDIA_PREVIOUS
int KEYCODE_MEDIA_REWIND
int KEYCODE_MEDIA_STOP
int KEYCODE_MENU
int KEYCODE_MINUS
int KEYCODE_MUTE
int KEYCODE_N
int KEYCODE_NOTIFICATION
int KEYCODE_NUM
int KEYCODE_O
int KEYCODE_P
int KEYCODE_PERIOD
int KEYCODE_PLUS
int KEYCODE_POUND
int KEYCODE_POWER
int KEYCODE_Q
int KEYCODE_R
int KEYCODE_RIGHT_BRACKET
int KEYCODE_S
int KEYCODE_SEARCH
int KEYCODE_SEMICOLON
int KEYCODE_SHIFT_LEFT
int KEYCODE_SHIFT_RIGHT
int KEYCODE_SLASH
int KEYCODE_SOFT_LEFT
int KEYCODE_SOFT_RIGHT
int KEYCODE_SPACE
int KEYCODE_STAR
int KEYCODE_SYM
int KEYCODE_T
int KEYCODE_TAB
int KEYCODE_U
int KEYCODE_UNKNOWN
int KEYCODE_V
int KEYCODE_VOLUME_DOWN
int KEYCODE_VOLUME_UP
int KEYCODE_W
int KEYCODE_X
int KEYCODE_Y
int KEYCODE_Z
int MAX_KEYCODE This constant is deprecated. There are now more than MAX_KEYCODE keycodes. Use getMaxKeyCode() instead.
int META_ALT_LEFT_ON

This mask is used to check whether the left ALT meta key is pressed.

int META_ALT_ON

This mask is used to check whether one of the ALT meta keys is pressed.

int META_ALT_RIGHT_ON

This mask is used to check whether the right the ALT meta key is pressed.

int META_SHIFT_LEFT_ON

This mask is used to check whether the left SHIFT meta key is pressed.

int META_SHIFT_ON

This mask is used to check whether one of the SHIFT meta keys is pressed.

int META_SHIFT_RIGHT_ON

This mask is used to check whether the right SHIFT meta key is pressed.

int META_SYM_ON

This mask is used to check whether the SYM meta key is pressed.

[Expand]
Inherited Constants
From interface android.os.Parcelable
Public Constructors
KeyEvent(int action, int code)
Create a new key event.
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 device, int scancode)
Create a new key event.
KeyEvent(long downTime, long eventTime, int action, int code, int repeat, int metaState, int device, int scancode, int flags)
Create a new key event.
KeyEvent(long time, String characters, int device, int flags)
Create a new key event for a string of characters.
KeyEvent(KeyEvent origEvent)
Make an exact copy of an existing key event.
KeyEvent(KeyEvent origEvent, long eventTime, int newRepeat)
Copy an existing key event, modifying its time and repeat count.
Public Methods
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.
int describeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
final boolean dispatch(KeyEvent.Callback receiver)
Deliver this key event to a KeyEvent.Callback interface.
final int getAction()
Retrieve the action of this key event.
final 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.
final int getDeviceId()
Return the id for the keyboard that this event came from.
char getDisplayLabel()
Get the primary character for this key.
final long getDownTime()
Retrieve the time of the most recent key down event, in the uptimeMillis() time base.
final long getEventTime()
Retrieve the time this event occurred, in the uptimeMillis() time base.
final int getFlags()
Returns the flags for this key event.
final int getKeyCode()
Retrieve the key code of the key event.
boolean getKeyData(KeyCharacterMap.KeyData results)
Get the characters conversion data for the key event..
char getMatch(char[] chars, int modifiers)
If one of the chars in the array can be generated by the keyCode of this key event, return the char; otherwise return '\0'.
char getMatch(char[] chars)
The same as getMatch(chars, 0).
static int getMaxKeyCode()
Returns the maximum keycode.
final int getMetaState()

Returns the state of the meta keys.

char getNumber()
Gets the number or symbol associated with the key.
final int getRepeatCount()
Retrieve the repeat count of the event.
final int getScanCode()
Retrieve the hardware key id of this key event. These values are not reliable and vary from device to device.
int getUnicodeChar(int meta)

Returns the Unicode character that the key would produce.

int getUnicodeChar()

Returns the Unicode character that the key would produce.

final boolean isAltPressed()

Returns the pressed state of the ALT meta key.

static boolean isModifierKey(int keyCode)
Returns true if this key code is a modifier key.
boolean isPrintingKey()
Does the key code of this key produce a glyph?
final boolean isShiftPressed()

Returns the pressed state of the SHIFT meta key.

final boolean isSymPressed()

Returns the pressed state of the SYM meta key.

final boolean isSystem()
Is this a system key? System keys can not be used for menu shortcuts.
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.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Constants

public static final int ACTION_DOWN

getAction() value: the key has been pressed down.

Constant Value: 0 (0x00000000)

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 KEYCODE_UNKNOWN, then this is a sequence of characters as returned by getCharacters().

Constant Value: 2 (0x00000002)

public static final int ACTION_UP

getAction() value: the key has been released.

Constant Value: 1 (0x00000001)

public static final Creator<KeyEvent> CREATOR

public static final 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". This allows TextView to dispatch these as normal enter keys for old applications, but still do the appropriate action when receiving them.

Constant Value: 16 (0x00000010)

public static final int FLAG_FROM_SYSTEM

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.

Constant Value: 8 (0x00000008)

public static final int FLAG_KEEP_TOUCH_MODE

This mask is set if we don't want the key event to cause us to leave touch mode.

Constant Value: 4 (0x00000004)

public static final int FLAG_SOFT_KEYBOARD

This mask is set if the key event was generated by a software keyboard.

Constant Value: 2 (0x00000002)

public static final int FLAG_WOKE_HERE

This mask is set if the device woke because of this key event.

Constant Value: 1 (0x00000001)

public static final int KEYCODE_0

Constant Value: 7 (0x00000007)

public static final int KEYCODE_1

Constant Value: 8 (0x00000008)

public static final int KEYCODE_2

Constant Value: 9 (0x00000009)

public static final int KEYCODE_3

Constant Value: 10 (0x0000000a)

public static final int KEYCODE_4

Constant Value: 11 (0x0000000b)

public static final int KEYCODE_5

Constant Value: 12 (0x0000000c)

public static final int KEYCODE_6

Constant Value: 13 (0x0000000d)

public static final int KEYCODE_7

Constant Value: 14 (0x0000000e)

public static final int KEYCODE_8

Constant Value: 15 (0x0000000f)

public static final int KEYCODE_9

Constant Value: 16 (0x00000010)

public static final int KEYCODE_A

Constant Value: 29 (0x0000001d)

public static final int KEYCODE_ALT_LEFT

Constant Value: 57 (0x00000039)

public static final int KEYCODE_ALT_RIGHT

Constant Value: 58 (0x0000003a)

public static final int KEYCODE_APOSTROPHE

Constant Value: 75 (0x0000004b)

public static final int KEYCODE_AT

Constant Value: 77 (0x0000004d)

public static final int KEYCODE_B

Constant Value: 30 (0x0000001e)

public static final int KEYCODE_BACK

Constant Value: 4 (0x00000004)

public static final int KEYCODE_BACKSLASH

Constant Value: 73 (0x00000049)

public static final int KEYCODE_C

Constant Value: 31 (0x0000001f)

public static final int KEYCODE_CALL

Constant Value: 5 (0x00000005)

public static final int KEYCODE_CAMERA

Constant Value: 27 (0x0000001b)

public static final int KEYCODE_CLEAR

Constant Value: 28 (0x0000001c)

public static final int KEYCODE_COMMA

Constant Value: 55 (0x00000037)

public static final int KEYCODE_D

Constant Value: 32 (0x00000020)

public static final int KEYCODE_DEL

Constant Value: 67 (0x00000043)

public static final int KEYCODE_DPAD_CENTER

Constant Value: 23 (0x00000017)

public static final int KEYCODE_DPAD_DOWN

Constant Value: 20 (0x00000014)

public static final int KEYCODE_DPAD_LEFT

Constant Value: 21 (0x00000015)

public static final int KEYCODE_DPAD_RIGHT

Constant Value: 22 (0x00000016)

public static final int KEYCODE_DPAD_UP

Constant Value: 19 (0x00000013)

public static final int KEYCODE_E

Constant Value: 33 (0x00000021)

public static final int KEYCODE_ENDCALL

Constant Value: 6 (0x00000006)

public static final int KEYCODE_ENTER

Constant Value: 66 (0x00000042)

public static final int KEYCODE_ENVELOPE

Constant Value: 65 (0x00000041)

public static final int KEYCODE_EQUALS

Constant Value: 70 (0x00000046)

public static final int KEYCODE_EXPLORER

Constant Value: 64 (0x00000040)

public static final int KEYCODE_F

Constant Value: 34 (0x00000022)

public static final int KEYCODE_FOCUS

Constant Value: 80 (0x00000050)

public static final int KEYCODE_G

Constant Value: 35 (0x00000023)

public static final int KEYCODE_GRAVE

Constant Value: 68 (0x00000044)

public static final int KEYCODE_H

Constant Value: 36 (0x00000024)

public static final int KEYCODE_HEADSETHOOK

Constant Value: 79 (0x0000004f)

public static final int KEYCODE_HOME

Constant Value: 3 (0x00000003)

public static final int KEYCODE_I

Constant Value: 37 (0x00000025)

public static final int KEYCODE_J

Constant Value: 38 (0x00000026)

public static final int KEYCODE_K

Constant Value: 39 (0x00000027)

public static final int KEYCODE_L

Constant Value: 40 (0x00000028)

public static final int KEYCODE_LEFT_BRACKET

Constant Value: 71 (0x00000047)

public static final int KEYCODE_M

Constant Value: 41 (0x00000029)

public static final int KEYCODE_MEDIA_FAST_FORWARD

Constant Value: 90 (0x0000005a)

public static final int KEYCODE_MEDIA_NEXT

Constant Value: 87 (0x00000057)

public static final int KEYCODE_MEDIA_PLAY_PAUSE

Constant Value: 85 (0x00000055)

public static final int KEYCODE_MEDIA_PREVIOUS

Constant Value: 88 (0x00000058)

public static final int KEYCODE_MEDIA_REWIND

Constant Value: 89 (0x00000059)

public static final int KEYCODE_MEDIA_STOP

Constant Value: 86 (0x00000056)

public static final int KEYCODE_MENU

Constant Value: 82 (0x00000052)

public static final int KEYCODE_MINUS

Constant Value: 69 (0x00000045)

public static final int KEYCODE_MUTE

Constant Value: 91 (0x0000005b)

public static final int KEYCODE_N

Constant Value: 42 (0x0000002a)

public static final int KEYCODE_NOTIFICATION

Constant Value: 83 (0x00000053)

public static final int KEYCODE_NUM

Constant Value: 78 (0x0000004e)

public static final int KEYCODE_O

Constant Value: 43 (0x0000002b)

public static final int KEYCODE_P

Constant Value: 44 (0x0000002c)

public static final int KEYCODE_PERIOD

Constant Value: 56 (0x00000038)

public static final int KEYCODE_PLUS

Constant Value: 81 (0x00000051)

public static final int KEYCODE_POUND

Constant Value: 18 (0x00000012)

public static final int KEYCODE_POWER

Constant Value: 26 (0x0000001a)

public static final int KEYCODE_Q

Constant Value: 45 (0x0000002d)

public static final int KEYCODE_R

Constant Value: 46 (0x0000002e)

public static final int KEYCODE_RIGHT_BRACKET

Constant Value: 72 (0x00000048)

public static final int KEYCODE_S

Constant Value: 47 (0x0000002f)

public static final int KEYCODE_SEARCH

Constant Value: 84 (0x00000054)

public static final int KEYCODE_SEMICOLON

Constant Value: 74 (0x0000004a)

public static final int KEYCODE_SHIFT_LEFT

Constant Value: 59 (0x0000003b)

public static final int KEYCODE_SHIFT_RIGHT

Constant Value: 60 (0x0000003c)

public static final int KEYCODE_SLASH

Constant Value: 76 (0x0000004c)

public static final int KEYCODE_SOFT_LEFT

Constant Value: 1 (0x00000001)

public static final int KEYCODE_SOFT_RIGHT

Constant Value: 2 (0x00000002)

public static final int KEYCODE_SPACE

Constant Value: 62 (0x0000003e)

public static final int KEYCODE_STAR

Constant Value: 17 (0x00000011)

public static final int KEYCODE_SYM

Constant Value: 63 (0x0000003f)

public static final int KEYCODE_T

Constant Value: 48 (0x00000030)

public static final int KEYCODE_TAB

Constant Value: 61 (0x0000003d)

public static final int KEYCODE_U

Constant Value: 49 (0x00000031)

public static final int KEYCODE_UNKNOWN

Constant Value: 0 (0x00000000)

public static final int KEYCODE_V

Constant Value: 50 (0x00000032)

public static final int KEYCODE_VOLUME_DOWN

Constant Value: 25 (0x00000019)

public static final int KEYCODE_VOLUME_UP

Constant Value: 24 (0x00000018)

public static final int KEYCODE_W

Constant Value: 51 (0x00000033)

public static final int KEYCODE_X

Constant Value: 52 (0x00000034)

public static final int KEYCODE_Y

Constant Value: 53 (0x00000035)

public static final int KEYCODE_Z

Constant Value: 54 (0x00000036)

public static final int MAX_KEYCODE

This constant is deprecated.There are now more than MAX_KEYCODE keycodes. Use getMaxKeyCode() instead.

Constant Value: 84 (0x00000054)

public static final int META_ALT_LEFT_ON

This mask is used to check whether the left ALT meta key is pressed.

Constant Value: 16 (0x00000010)

public static final int META_ALT_ON

This mask is used to check whether one of the ALT meta keys is pressed.

Constant Value: 2 (0x00000002)

public static final int META_ALT_RIGHT_ON

This mask is used to check whether the right the ALT meta key is pressed.

Constant Value: 32 (0x00000020)

public static final int META_SHIFT_LEFT_ON

This mask is used to check whether the left SHIFT meta key is pressed.

Constant Value: 64 (0x00000040)

public static final int META_SHIFT_ON

This mask is used to check whether one of the SHIFT meta keys is pressed.

Constant Value: 1 (0x00000001)

public static final int META_SHIFT_RIGHT_ON

This mask is used to check whether the right SHIFT meta key is pressed.

Constant Value: 128 (0x00000080)

public static final int META_SYM_ON

This mask is used to check whether the SYM meta key is pressed.

Constant Value: 4 (0x00000004)

Public Constructors

public KeyEvent (int action, int code)

Create a new key event.

Parameters
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)

Create a new key event.

Parameters
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.

public KeyEvent (long downTime, long eventTime, int action, int code, int repeat, int metaState)

Create a new key event.

Parameters
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.

public KeyEvent (long downTime, long eventTime, int action, int code, int repeat, int metaState, int device, int scancode)

Create a new key event.

Parameters
downTime The time (in uptimeMillis()) at which this key code originally went down.
eventTime The time (in uptimeMillis()) at which this event happened.
action Action code: either ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.
code The key code.
repeat A repeat count for down events (> 0 if this is after the initial down) or event count for multiple events.
metaState Flags indicating which meta keys are currently pressed.
device The device ID that generated the key event.
scancode Raw device scan code of the event.

public KeyEvent (long downTime, long eventTime, int action, int code, int repeat, int metaState, int device, int scancode, int flags)

Create a new key event.

Parameters
downTime The time (in uptimeMillis()) at which this key code originally went down.
eventTime The time (in uptimeMillis()) at which this event happened.
action Action code: either ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.
code The key code.
repeat A repeat count for down events (> 0 if this is after the initial down) or event count for multiple events.
metaState Flags indicating which meta keys are currently pressed.
device The device ID that generated the key event.
scancode Raw device scan code of the event.
flags The flags for this key event

public KeyEvent (long time, String characters, int device, int flags)

Create a new key event for a string of characters. The key code, action, and repeat could will automatically be set to KEYCODE_UNKNOWN, ACTION_MULTIPLE, and 0 for you.

Parameters
time The time (in uptimeMillis()) at which this event occured.
characters The string of characters.
device The device ID that generated the key event.
flags The flags for this key event

public KeyEvent (KeyEvent origEvent)

Make an exact copy of an existing key event.

public KeyEvent (KeyEvent origEvent, long eventTime, int newRepeat)

Copy an existing key event, modifying its time and repeat count.

Parameters
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.

Public Methods

public 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.

Parameters
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)

Create a new key event that is the same as the given one, but whose flags are replaced with the given value.

Parameters
event The existing event to be copied. This is not modified.
flags The new flags constant.

public 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.

Parameters
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.

public int describeContents ()

Describe the kinds of special objects contained in this Parcelable's marshalled representation.

Returns
  • a bitmask indicating the set of special object types marshalled by the Parcelable.

public final boolean dispatch (KeyEvent.Callback receiver)

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.

Parameters
receiver The Callback that will be given the event.
Returns
  • The return value from the Callback method that was called.

public final int getAction ()

Retrieve the action of this key event. May be either ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.

Returns
  • The event action: ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.

public final 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. In all other cases it is null.

Returns
  • Returns a String of 1 or more characters associated with the event.

public static int getDeadChar (int accent, int c)

Get the character that is produced by putting accent on the character c. For example, getDeadChar('`', 'e') returns è.

public final int getDeviceId ()

Return the id for the keyboard that this event came from. A device id of 0 indicates the event didn't come from a physical device and maps to the default keymap. The other numbers are arbitrary and you shouldn't depend on the values.

See Also

public char getDisplayLabel ()

Get the primary character for this key. In other words, the label that is physically printed on it.

public final long getDownTime ()

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.

Returns
  • Returns the most recent key down time, in the uptimeMillis() time base

public final long getEventTime ()

Retrieve the time this event occurred, in the uptimeMillis() time base.

Returns
  • Returns the time this event occurred, in the uptimeMillis() time base.

public final int getFlags ()

Returns the flags for this key event.

See Also

public final int getKeyCode ()

Retrieve the key code of the key event. This is the physical key that was pressed, not the Unicode character.

Returns
  • The key code of the event.

public boolean getKeyData (KeyCharacterMap.KeyData results)

Get the characters conversion data for the key event..

Parameters
results a KeyCharacterMap.KeyData that will be filled with the results.
Returns
  • whether the key was mapped or not. If the key was not mapped, results is not modified.

public char getMatch (char[] chars, int modifiers)

If one of the chars in the array can be generated by the keyCode of this key event, return the char; otherwise return '\0'.

Parameters
chars the characters to try to find
modifiers the modifier bits to prefer. If any of these bits are set, if there are multiple choices, that could work, the one for this modifier will be set.

public char getMatch (char[] chars)

The same as getMatch(chars, 0).

public static int getMaxKeyCode ()

Returns the maximum keycode.

public final int getMetaState ()

Returns the state of the meta keys.

Returns
  • an integer in which each bit set to 1 represents a pressed meta key

public char getNumber ()

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.

public final int getRepeatCount ()

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.

Returns
  • The number of times the key has repeated.

public final int getScanCode ()

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.

public int getUnicodeChar (int meta)

Returns the Unicode character that the key would produce.

Returns 0 if the key is not one that is used to type Unicode characters.

If the return value has bit COMBINING_ACCENT set, the key is a "dead key" that should be combined with another to actually produce a character -- see getDeadChar(int, int) -- after masking with COMBINING_ACCENT_MASK.

public int getUnicodeChar ()

Returns the Unicode character that the key would produce.

Returns 0 if the key is not one that is used to type Unicode characters.

If the return value has bit COMBINING_ACCENT set, the key is a "dead key" that should be combined with another to actually produce a character -- see getDeadChar(int, int) -- after masking with COMBINING_ACCENT_MASK.

public final boolean isAltPressed ()

Returns the pressed state of the ALT meta key.

Returns
  • true if the ALT key is pressed, false otherwise

public static boolean isModifierKey (int keyCode)

Returns true if this key code is a modifier key.

Returns

public boolean isPrintingKey ()

Does the key code of this key produce a glyph?

public final boolean isShiftPressed ()

Returns the pressed state of the SHIFT meta key.

Returns
  • true if the SHIFT key is pressed, false otherwise

public final boolean isSymPressed ()

Returns the pressed state of the SYM meta key.

Returns
  • true if the SYM key is pressed, false otherwise

public final boolean isSystem ()

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

public String toString ()

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation simply concatenates the class name, the '@' sign and a hexadecimal representation of the object's hashCode(), that is, it is equivalent to the following expression:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
  • a printable representation of this object.

public void writeToParcel (Parcel out, int flags)

Flatten this object in to a Parcel.

Parameters
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.