Reference:Android.view.KeyEvent
From Triled Wiki
android.view
public class android.view.KeyEvent
| java.lang.Object | ||
| android.view.KeyEvent | Parcelable | |
[edit] Nested Classes
| KeyEvent.Callback |
[edit] Summary
[edit] Constants
| Value | ||||
|---|---|---|---|---|
| int | ACTION_DOWN | getAction() value: the key has been pressed down. | 0 | 0x00000000 |
| int | ACTION_MULTIPLE | getAction() value: multiple duplicate key events have occurred in a row. | 2 | 0x00000002 |
| int | ACTION_UP | getAction() value: the key has been released. | 1 | 0x00000001 |
| Creator | CREATOR | |||
| int | KEYCODE_0 | 7 | 0x00000007 | |
| int | KEYCODE_1 | 8 | 0x00000008 | |
| int | KEYCODE_2 | 9 | 0x00000009 | |
| int | KEYCODE_3 | 10 | 0x0000000a | |
| int | KEYCODE_4 | 11 | 0x0000000b | |
| int | KEYCODE_5 | 12 | 0x0000000c | |
| int | KEYCODE_6 | 13 | 0x0000000d | |
| int | KEYCODE_7 | 14 | 0x0000000e | |
| int | KEYCODE_8 | 15 | 0x0000000f | |
| int | KEYCODE_9 | 16 | 0x00000010 | |
| int | KEYCODE_A | 29 | 0x0000001d | |
| int | KEYCODE_ALT | 57 | 0x00000039 | |
| int | KEYCODE_APOSTROPHE | 73 | 0x00000049 | |
| int | KEYCODE_AT | 75 | 0x0000004b | |
| int | KEYCODE_B | 30 | 0x0000001e | |
| int | KEYCODE_BACK | 4 | 0x00000004 | |
| int | KEYCODE_BACKSLASH | 71 | 0x00000047 | |
| int | KEYCODE_C | 31 | 0x0000001f | |
| int | KEYCODE_CALL | 5 | 0x00000005 | |
| int | KEYCODE_CAMERA | 27 | 0x0000001b | |
| int | KEYCODE_CAP | 58 | 0x0000003a | |
| int | KEYCODE_CLEAR | 28 | 0x0000001c | |
| int | KEYCODE_COMMA | 55 | 0x00000037 | |
| int | KEYCODE_D | 32 | 0x00000020 | |
| int | KEYCODE_DEL | 65 | 0x00000041 | |
| int | KEYCODE_DPAD_CENTER | 23 | 0x00000017 | |
| int | KEYCODE_DPAD_DOWN | 20 | 0x00000014 | |
| int | KEYCODE_DPAD_LEFT | 21 | 0x00000015 | |
| int | KEYCODE_DPAD_RIGHT | 22 | 0x00000016 | |
| int | KEYCODE_DPAD_UP | 19 | 0x00000013 | |
| int | KEYCODE_E | 33 | 0x00000021 | |
| int | KEYCODE_ENDCALL | 6 | 0x00000006 | |
| int | KEYCODE_ENVELOPE | 63 | 0x0000003f | |
| int | KEYCODE_EQUALS | 68 | 0x00000044 | |
| int | KEYCODE_EXPLORER | 62 | 0x0000003e | |
| int | KEYCODE_F | 34 | 0x00000022 | |
| int | KEYCODE_FOCUS | 78 | 0x0000004e | |
| int | KEYCODE_G | 35 | 0x00000023 | |
| int | KEYCODE_GRAVE | 66 | 0x00000042 | |
| int | KEYCODE_H | 36 | 0x00000024 | |
| int | KEYCODE_HEADSETHOOK | 77 | 0x0000004d | |
| int | KEYCODE_HOME | 3 | 0x00000003 | |
| int | KEYCODE_I | 37 | 0x00000025 | |
| int | KEYCODE_J | 38 | 0x00000026 | |
| int | KEYCODE_K | 39 | 0x00000027 | |
| int | KEYCODE_L | 40 | 0x00000028 | |
| int | KEYCODE_LEFT_BRACKET | 69 | 0x00000045 | |
| int | KEYCODE_M | 41 | 0x00000029 | |
| int | KEYCODE_MINUS | 67 | 0x00000043 | |
| int | KEYCODE_N | 42 | 0x0000002a | |
| int | KEYCODE_NEWLINE | 64 | 0x00000040 | |
| int | KEYCODE_NUM | 76 | 0x0000004c | |
| int | KEYCODE_O | 43 | 0x0000002b | |
| int | KEYCODE_P | 44 | 0x0000002c | |
| int | KEYCODE_PERIOD | 56 | 0x00000038 | |
| int | KEYCODE_PLUS | 79 | 0x0000004f | |
| int | KEYCODE_POUND | 18 | 0x00000012 | |
| int | KEYCODE_POWER | 26 | 0x0000001a | |
| int | KEYCODE_Q | 45 | 0x0000002d | |
| int | KEYCODE_R | 46 | 0x0000002e | |
| int | KEYCODE_RIGHT_BRACKET | 70 | 0x00000046 | |
| int | KEYCODE_S | 47 | 0x0000002f | |
| int | KEYCODE_SEMICOLON | 72 | 0x00000048 | |
| int | KEYCODE_SLASH | 74 | 0x0000004a | |
| int | KEYCODE_SOFT_LEFT | 1 | 0x00000001 | |
| int | KEYCODE_SOFT_RIGHT | 2 | 0x00000002 | |
| int | KEYCODE_SPACE | 60 | 0x0000003c | |
| int | KEYCODE_STAR | 17 | 0x00000011 | |
| int | KEYCODE_SYM | 61 | 0x0000003d | |
| int | KEYCODE_T | 48 | 0x00000030 | |
| int | KEYCODE_TAB | 59 | 0x0000003b | |
| int | KEYCODE_U | 49 | 0x00000031 | |
| int | KEYCODE_UNKNOWN | 0 | 0x00000000 | |
| int | KEYCODE_V | 50 | 0x00000032 | |
| int | KEYCODE_VOLUME_DOWN | 25 | 0x00000019 | |
| int | KEYCODE_VOLUME_UP | 24 | 0x00000018 | |
| int | KEYCODE_W | 51 | 0x00000033 | |
| int | KEYCODE_X | 52 | 0x00000034 | |
| int | KEYCODE_Y | 53 | 0x00000035 | |
| int | KEYCODE_Z | 54 | 0x00000036 | |
| int | MAX_KEYCODE | 79 | 0x0000004f | |
| int | META_ALT_ON |
This mask is used to check whether the FN meta key is pressed. | 2 | 0x00000002 |
| int | META_CAP_ON |
This mask is used to check whether the CAP meta key is pressed. | 1 | 0x00000001 |
| int | META_SYM_ON |
This mask is used to check whether the SYM meta key is pressed. | 4 | 0x00000004 |
[edit] 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 (KeyEvent origEvent, long eventTime, int newRepeat) | |||||
| Copy an existing key event, modifying its time and repeat count. | |||||
[edit] Public Methods
| final | boolean | dispatch (Callback receiver) | |||
| Deliver this key event to a KeyEvent.Callback interface. | |||||
| final | int | getAction () | |||
| Retrieve the action of this key event. | |||||
| final | int | getDeviceId () | |||
| Return the id for the keyboard that this event came from. | |||||
| 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 | getKeyCode () | |||
| Retrieve the key code of the key event. | |||||
| final | int | getKeyboardDevice () | |||
| Renamed to getDeviceId(). | |||||
| final | int | getMetaState () | |||
|
Returns the state of the meta keys. | |||||
| 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. | |||||
| final | boolean | isAltPressed () | |||
|
Returns the pressed state of the FN meta key. | |||||
| final | boolean | isCapPressed () | |||
|
Returns the pressed state of the CAP meta key. | |||||
| final | boolean | isDown () | |||
| Don't use in new code, instead explicitly check getAction(). | |||||
| static | boolean | isModifierKey (int keyCode) | |||
| Returns true if this key code is a modifier 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 () | ||||
| Answers a string containing a concise, human-readable description of the receiver. | |||||
| void | writeToParcel (Parcel out) | ||||
[edit] Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait[edit] Methods inherited from interface android.os.Parcelable
[edit] Details
[edit] Constants
[edit] public static final int ACTION_DOWN
getAction() value: the key has been pressed down. Constant Value: 0 (0x00000000)
[edit] public static final int ACTION_MULTIPLE
getAction() value: multiple duplicate key events have occurred in a row. The {#link getRepeatCount() method returns the number of duplicates. Constant Value: 2 (0x00000002)
[edit] public static final int ACTION_UP
getAction() value: the key has been released. Constant Value: 1 (0x00000001)
[edit] public static final Creator CREATOR
[edit] public static final int KEYCODE_0
Constant Value: 7 (0x00000007)
[edit] public static final int KEYCODE_1
Constant Value: 8 (0x00000008)
[edit] public static final int KEYCODE_2
Constant Value: 9 (0x00000009)
[edit] public static final int KEYCODE_3
Constant Value: 10 (0x0000000a)
[edit] public static final int KEYCODE_4
Constant Value: 11 (0x0000000b)
[edit] public static final int KEYCODE_5
Constant Value: 12 (0x0000000c)
[edit] public static final int KEYCODE_6
Constant Value: 13 (0x0000000d)
[edit] public static final int KEYCODE_7
Constant Value: 14 (0x0000000e)
[edit] public static final int KEYCODE_8
Constant Value: 15 (0x0000000f)
[edit] public static final int KEYCODE_9
Constant Value: 16 (0x00000010)
[edit] public static final int KEYCODE_A
Constant Value: 29 (0x0000001d)
[edit] public static final int KEYCODE_ALT
Constant Value: 57 (0x00000039)
[edit] public static final int KEYCODE_APOSTROPHE
Constant Value: 73 (0x00000049)
[edit] public static final int KEYCODE_AT
Constant Value: 75 (0x0000004b)
[edit] public static final int KEYCODE_B
Constant Value: 30 (0x0000001e)
[edit] public static final int KEYCODE_BACK
Constant Value: 4 (0x00000004)
[edit] public static final int KEYCODE_BACKSLASH
Constant Value: 71 (0x00000047)
[edit] public static final int KEYCODE_C
Constant Value: 31 (0x0000001f)
[edit] public static final int KEYCODE_CALL
Constant Value: 5 (0x00000005)
[edit] public static final int KEYCODE_CAMERA
Constant Value: 27 (0x0000001b)
[edit] public static final int KEYCODE_CAP
Constant Value: 58 (0x0000003a)
[edit] public static final int KEYCODE_CLEAR
Constant Value: 28 (0x0000001c)
[edit] public static final int KEYCODE_COMMA
Constant Value: 55 (0x00000037)
[edit] public static final int KEYCODE_D
Constant Value: 32 (0x00000020)
[edit] public static final int KEYCODE_DEL
Constant Value: 65 (0x00000041)
[edit] public static final int KEYCODE_DPAD_CENTER
Constant Value: 23 (0x00000017)
[edit] public static final int KEYCODE_DPAD_DOWN
Constant Value: 20 (0x00000014)
[edit] public static final int KEYCODE_DPAD_LEFT
Constant Value: 21 (0x00000015)
[edit] public static final int KEYCODE_DPAD_RIGHT
Constant Value: 22 (0x00000016)
[edit] public static final int KEYCODE_DPAD_UP
Constant Value: 19 (0x00000013)
[edit] public static final int KEYCODE_E
Constant Value: 33 (0x00000021)
[edit] public static final int KEYCODE_ENDCALL
Constant Value: 6 (0x00000006)
[edit] public static final int KEYCODE_ENVELOPE
Constant Value: 63 (0x0000003f)
[edit] public static final int KEYCODE_EQUALS
Constant Value: 68 (0x00000044)
[edit] public static final int KEYCODE_EXPLORER
Constant Value: 62 (0x0000003e)
[edit] public static final int KEYCODE_F
Constant Value: 34 (0x00000022)
[edit] public static final int KEYCODE_FOCUS
Constant Value: 78 (0x0000004e)
[edit] public static final int KEYCODE_G
Constant Value: 35 (0x00000023)
[edit] public static final int KEYCODE_GRAVE
Constant Value: 66 (0x00000042)
[edit] public static final int KEYCODE_H
Constant Value: 36 (0x00000024)
[edit] public static final int KEYCODE_HEADSETHOOK
Constant Value: 77 (0x0000004d)
[edit] public static final int KEYCODE_HOME
Constant Value: 3 (0x00000003)
[edit] public static final int KEYCODE_I
Constant Value: 37 (0x00000025)
[edit] public static final int KEYCODE_J
Constant Value: 38 (0x00000026)
[edit] public static final int KEYCODE_K
Constant Value: 39 (0x00000027)
[edit] public static final int KEYCODE_L
Constant Value: 40 (0x00000028)
[edit] public static final int KEYCODE_LEFT_BRACKET
Constant Value: 69 (0x00000045)
[edit] public static final int KEYCODE_M
Constant Value: 41 (0x00000029)
[edit] public static final int KEYCODE_MINUS
Constant Value: 67 (0x00000043)
[edit] public static final int KEYCODE_N
Constant Value: 42 (0x0000002a)
[edit] public static final int KEYCODE_NEWLINE
Constant Value: 64 (0x00000040)
[edit] public static final int KEYCODE_NUM
Constant Value: 76 (0x0000004c)
[edit] public static final int KEYCODE_O
Constant Value: 43 (0x0000002b)
[edit] public static final int KEYCODE_P
Constant Value: 44 (0x0000002c)
[edit] public static final int KEYCODE_PERIOD
Constant Value: 56 (0x00000038)
[edit] public static final int KEYCODE_PLUS
Constant Value: 79 (0x0000004f)
[edit] public static final int KEYCODE_POUND
Constant Value: 18 (0x00000012)
[edit] public static final int KEYCODE_POWER
Constant Value: 26 (0x0000001a)
[edit] public static final int KEYCODE_Q
Constant Value: 45 (0x0000002d)
[edit] public static final int KEYCODE_R
Constant Value: 46 (0x0000002e)
[edit] public static final int KEYCODE_RIGHT_BRACKET
Constant Value: 70 (0x00000046)
[edit] public static final int KEYCODE_S
Constant Value: 47 (0x0000002f)
[edit] public static final int KEYCODE_SEMICOLON
Constant Value: 72 (0x00000048)
[edit] public static final int KEYCODE_SLASH
Constant Value: 74 (0x0000004a)
[edit] public static final int KEYCODE_SOFT_LEFT
Constant Value: 1 (0x00000001)
[edit] public static final int KEYCODE_SOFT_RIGHT
Constant Value: 2 (0x00000002)
[edit] public static final int KEYCODE_SPACE
Constant Value: 60 (0x0000003c)
[edit] public static final int KEYCODE_STAR
Constant Value: 17 (0x00000011)
[edit] public static final int KEYCODE_SYM
Constant Value: 61 (0x0000003d)
[edit] public static final int KEYCODE_T
Constant Value: 48 (0x00000030)
[edit] public static final int KEYCODE_TAB
Constant Value: 59 (0x0000003b)
[edit] public static final int KEYCODE_U
Constant Value: 49 (0x00000031)
[edit] public static final int KEYCODE_UNKNOWN
Constant Value: 0 (0x00000000)
[edit] public static final int KEYCODE_V
Constant Value: 50 (0x00000032)
[edit] public static final int KEYCODE_VOLUME_DOWN
Constant Value: 25 (0x00000019)
[edit] public static final int KEYCODE_VOLUME_UP
Constant Value: 24 (0x00000018)
[edit] public static final int KEYCODE_W
Constant Value: 51 (0x00000033)
[edit] public static final int KEYCODE_X
Constant Value: 52 (0x00000034)
[edit] public static final int KEYCODE_Y
Constant Value: 53 (0x00000035)
[edit] public static final int KEYCODE_Z
Constant Value: 54 (0x00000036)
[edit] public static final int MAX_KEYCODE
Constant Value: 79 (0x0000004f)
[edit] public static final int META_ALT_ON
This mask is used to check whether the FN meta key is pressed.
See Also
- isAltPressed()
- getMetaState() Constant Value: 2 (0x00000002)
[edit] public static final int META_CAP_ON
This mask is used to check whether the CAP meta key is pressed.
See Also
- isCapPressed()
- getMetaState() Constant Value: 1 (0x00000001)
[edit] public static final int META_SYM_ON
This mask is used to check whether the SYM meta key is pressed.
See Also
- isSymPressed()
- getMetaState() Constant Value: 4 (0x00000004)
[edit] Public Constructors
[edit] 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. |
[edit] 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. |
[edit] 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. |
[edit] 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. |
[edit] 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. |
[edit] Public Methods
[edit] public final boolean dispatch(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.
[edit] 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.
[edit] 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
[edit] 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
[edit] 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.
[edit] 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.
[edit] public final int getKeyboardDevice()
Renamed to getDeviceId().
[edit] 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
See Also
[edit] 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.
[edit] 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.
[edit] public final boolean isAltPressed()
Returns the pressed state of the FN meta key.
Returns
- true if the FN key is pressed, false otherwise
See Also
[edit] public final boolean isCapPressed()
Returns the pressed state of the CAP meta key.
Returns
- true if the CAP key is pressed, false otherwise
See Also
[edit] public final boolean isDown()
Don't use in new code, instead explicitly check getAction().
Returns
- If the action is ACTION_DOWN, returns true; else false.
[edit] public static boolean isModifierKey(int keyCode)
Returns true if this key code is a modifier key.
Returns
- whether the provided keyCode is one of KEYCODE_CAP, KEYCODE_ALT or KEYCODE_SYM.
[edit] public final boolean isSymPressed()
Returns the pressed state of the SYM meta key.
Returns
- true if the SYM key is pressed, false otherwise
See Also
[edit] public final boolean isSystem()
Is this a system key? System keys can not be used for menu shortcuts.
[edit] public String toString()
Answers a string containing a concise, human-readable description of the receiver.
[edit] public void writeToParcel(Parcel out)
[edit] References
- Original documentation page for Android SDK build m5-rc15e - 14 apr 2008 17:27
