The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.view; |
| 18 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 21 | import android.text.method.MetaKeyKeyListener; |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 22 | import android.util.Log; |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 23 | import android.util.SparseIntArray; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.view.KeyCharacterMap; |
| 25 | import android.view.KeyCharacterMap.KeyData; |
| 26 | |
| 27 | /** |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 28 | * Object used to report key and button events. |
| 29 | * <p> |
| 30 | * Each key press is described by a sequence of key events. A key press |
| 31 | * starts with a key event with {@link #ACTION_DOWN}. If the key is held |
| 32 | * sufficiently long that it repeats, then the initial down is followed |
| 33 | * additional key events with {@link #ACTION_DOWN} and a non-zero value for |
| 34 | * {@link #getRepeatCount()}. The last key event is a {@link #ACTION_UP} |
| 35 | * for the key up. If the key press is canceled, the key up event will have the |
| 36 | * {@link #FLAG_CANCELED} flag set. |
| 37 | * </p><p> |
| 38 | * Key events are generally accompanied by a key code ({@link #getKeyCode()}), |
| 39 | * scan code ({@link #getScanCode()}) and meta state ({@link #getMetaState()}). |
| 40 | * Key code constants are defined in this class. Scan code constants are raw |
| 41 | * device-specific codes obtained from the OS and so are not generally meaningful |
| 42 | * to applications unless interpreted using the {@link KeyCharacterMap}. |
| 43 | * Meta states describe the pressed state of key modifiers |
| 44 | * such as {@link #META_SHIFT_ON} or {@link #META_ALT_ON}. |
| 45 | * </p><p> |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 46 | * Key codes typically correspond one-to-one with individual keys on an input device. |
| 47 | * Many keys and key combinations serve quite different functions on different |
| 48 | * input devices so care must be taken when interpreting them. Always use the |
| 49 | * {@link KeyCharacterMap} associated with the input device when mapping keys |
| 50 | * to characters. Be aware that there may be multiple key input devices active |
| 51 | * at the same time and each will have its own key character map. |
| 52 | * </p><p> |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 53 | * As soft input methods can use multiple and inventive ways of inputting text, |
| 54 | * there is no guarantee that any key press on a soft keyboard will generate a key |
| 55 | * event: this is left to the IME's discretion, and in fact sending such events is |
| 56 | * discouraged. You should never rely on receiving KeyEvents for any key on a soft |
| 57 | * input method. In particular, the default software keyboard will never send any |
| 58 | * key event to any application targetting Jelly Bean or later, and will only send |
| 59 | * events for some presses of the delete and return keys to applications targetting |
| 60 | * Ice Cream Sandwich or earlier. Be aware that other software input methods may |
| 61 | * never send key events regardless of the version. Consider using editor actions |
| 62 | * like {@link android.view.inputmethod.EditorInfo#IME_ACTION_DONE} if you need |
| 63 | * specific interaction with the software keyboard, as it gives more visibility to |
| 64 | * the user as to how your application will react to key presses. |
| 65 | * </p><p> |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 66 | * When interacting with an IME, the framework may deliver key events |
| 67 | * with the special action {@link #ACTION_MULTIPLE} that either specifies |
| 68 | * that single repeated key code or a sequence of characters to insert. |
| 69 | * </p><p> |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 70 | * In general, the framework cannot guarantee that the key events it delivers |
| 71 | * to a view always constitute complete key sequences since some events may be dropped |
| 72 | * or modified by containing views before they are delivered. The view implementation |
| 73 | * should be prepared to handle {@link #FLAG_CANCELED} and should tolerate anomalous |
| 74 | * situations such as receiving a new {@link #ACTION_DOWN} without first having |
| 75 | * received an {@link #ACTION_UP} for the prior key press. |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 76 | * </p><p> |
| 77 | * Refer to {@link InputDevice} for more information about how different kinds of |
| 78 | * input devices and sources represent keys and buttons. |
| 79 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 81 | public class KeyEvent extends InputEvent implements Parcelable { |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 82 | /** Key code constant: Unknown key code. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | public static final int KEYCODE_UNKNOWN = 0; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 84 | /** Key code constant: Soft Left key. |
| 85 | * Usually situated below the display on phones and used as a multi-function |
| 86 | * feature key for selecting a software defined function shown on the bottom left |
| 87 | * of the display. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | public static final int KEYCODE_SOFT_LEFT = 1; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 89 | /** Key code constant: Soft Right key. |
| 90 | * Usually situated below the display on phones and used as a multi-function |
| 91 | * feature key for selecting a software defined function shown on the bottom right |
| 92 | * of the display. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | public static final int KEYCODE_SOFT_RIGHT = 2; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 94 | /** Key code constant: Home key. |
| 95 | * This key is handled by the framework and is never delivered to applications. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | public static final int KEYCODE_HOME = 3; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 97 | /** Key code constant: Back key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | public static final int KEYCODE_BACK = 4; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 99 | /** Key code constant: Call key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | public static final int KEYCODE_CALL = 5; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 101 | /** Key code constant: End Call key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | public static final int KEYCODE_ENDCALL = 6; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 103 | /** Key code constant: '0' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | public static final int KEYCODE_0 = 7; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 105 | /** Key code constant: '1' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | public static final int KEYCODE_1 = 8; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 107 | /** Key code constant: '2' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | public static final int KEYCODE_2 = 9; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 109 | /** Key code constant: '3' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | public static final int KEYCODE_3 = 10; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 111 | /** Key code constant: '4' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | public static final int KEYCODE_4 = 11; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 113 | /** Key code constant: '5' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | public static final int KEYCODE_5 = 12; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 115 | /** Key code constant: '6' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | public static final int KEYCODE_6 = 13; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 117 | /** Key code constant: '7' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | public static final int KEYCODE_7 = 14; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 119 | /** Key code constant: '8' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | public static final int KEYCODE_8 = 15; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 121 | /** Key code constant: '9' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | public static final int KEYCODE_9 = 16; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 123 | /** Key code constant: '*' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | public static final int KEYCODE_STAR = 17; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 125 | /** Key code constant: '#' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | public static final int KEYCODE_POUND = 18; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 127 | /** Key code constant: Directional Pad Up key. |
| 128 | * May also be synthesized from trackball motions. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | public static final int KEYCODE_DPAD_UP = 19; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 130 | /** Key code constant: Directional Pad Down key. |
| 131 | * May also be synthesized from trackball motions. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | public static final int KEYCODE_DPAD_DOWN = 20; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 133 | /** Key code constant: Directional Pad Left key. |
| 134 | * May also be synthesized from trackball motions. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | public static final int KEYCODE_DPAD_LEFT = 21; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 136 | /** Key code constant: Directional Pad Right key. |
| 137 | * May also be synthesized from trackball motions. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | public static final int KEYCODE_DPAD_RIGHT = 22; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 139 | /** Key code constant: Directional Pad Center key. |
| 140 | * May also be synthesized from trackball motions. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | public static final int KEYCODE_DPAD_CENTER = 23; |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 142 | /** Key code constant: Volume Up key. |
| 143 | * Adjusts the speaker volume up. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | public static final int KEYCODE_VOLUME_UP = 24; |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 145 | /** Key code constant: Volume Down key. |
| 146 | * Adjusts the speaker volume down. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | public static final int KEYCODE_VOLUME_DOWN = 25; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 148 | /** Key code constant: Power key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | public static final int KEYCODE_POWER = 26; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 150 | /** Key code constant: Camera key. |
| 151 | * Used to launch a camera application or take pictures. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | public static final int KEYCODE_CAMERA = 27; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 153 | /** Key code constant: Clear key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | public static final int KEYCODE_CLEAR = 28; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 155 | /** Key code constant: 'A' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | public static final int KEYCODE_A = 29; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 157 | /** Key code constant: 'B' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | public static final int KEYCODE_B = 30; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 159 | /** Key code constant: 'C' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | public static final int KEYCODE_C = 31; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 161 | /** Key code constant: 'D' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | public static final int KEYCODE_D = 32; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 163 | /** Key code constant: 'E' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | public static final int KEYCODE_E = 33; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 165 | /** Key code constant: 'F' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | public static final int KEYCODE_F = 34; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 167 | /** Key code constant: 'G' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | public static final int KEYCODE_G = 35; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 169 | /** Key code constant: 'H' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | public static final int KEYCODE_H = 36; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 171 | /** Key code constant: 'I' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | public static final int KEYCODE_I = 37; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 173 | /** Key code constant: 'J' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | public static final int KEYCODE_J = 38; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 175 | /** Key code constant: 'K' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | public static final int KEYCODE_K = 39; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 177 | /** Key code constant: 'L' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | public static final int KEYCODE_L = 40; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 179 | /** Key code constant: 'M' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | public static final int KEYCODE_M = 41; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 181 | /** Key code constant: 'N' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | public static final int KEYCODE_N = 42; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 183 | /** Key code constant: 'O' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | public static final int KEYCODE_O = 43; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 185 | /** Key code constant: 'P' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | public static final int KEYCODE_P = 44; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 187 | /** Key code constant: 'Q' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | public static final int KEYCODE_Q = 45; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 189 | /** Key code constant: 'R' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | public static final int KEYCODE_R = 46; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 191 | /** Key code constant: 'S' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | public static final int KEYCODE_S = 47; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 193 | /** Key code constant: 'T' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | public static final int KEYCODE_T = 48; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 195 | /** Key code constant: 'U' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | public static final int KEYCODE_U = 49; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 197 | /** Key code constant: 'V' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | public static final int KEYCODE_V = 50; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 199 | /** Key code constant: 'W' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | public static final int KEYCODE_W = 51; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 201 | /** Key code constant: 'X' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | public static final int KEYCODE_X = 52; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 203 | /** Key code constant: 'Y' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | public static final int KEYCODE_Y = 53; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 205 | /** Key code constant: 'Z' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | public static final int KEYCODE_Z = 54; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 207 | /** Key code constant: ',' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | public static final int KEYCODE_COMMA = 55; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 209 | /** Key code constant: '.' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | public static final int KEYCODE_PERIOD = 56; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 211 | /** Key code constant: Left Alt modifier key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | public static final int KEYCODE_ALT_LEFT = 57; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 213 | /** Key code constant: Right Alt modifier key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | public static final int KEYCODE_ALT_RIGHT = 58; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 215 | /** Key code constant: Left Shift modifier key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | public static final int KEYCODE_SHIFT_LEFT = 59; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 217 | /** Key code constant: Right Shift modifier key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 218 | public static final int KEYCODE_SHIFT_RIGHT = 60; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 219 | /** Key code constant: Tab key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | public static final int KEYCODE_TAB = 61; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 221 | /** Key code constant: Space key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | public static final int KEYCODE_SPACE = 62; |
Jeff Brown | 224d4a1 | 2010-10-07 20:28:53 -0700 | [diff] [blame] | 223 | /** Key code constant: Symbol modifier key. |
| 224 | * Used to enter alternate symbols. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | public static final int KEYCODE_SYM = 63; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 226 | /** Key code constant: Explorer special function key. |
| 227 | * Used to launch a browser application. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | public static final int KEYCODE_EXPLORER = 64; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 229 | /** Key code constant: Envelope special function key. |
| 230 | * Used to launch a mail application. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | public static final int KEYCODE_ENVELOPE = 65; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 232 | /** Key code constant: Enter key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | public static final int KEYCODE_ENTER = 66; |
Jeff Brown | 224d4a1 | 2010-10-07 20:28:53 -0700 | [diff] [blame] | 234 | /** Key code constant: Backspace key. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 235 | * Deletes characters before the insertion point, unlike {@link #KEYCODE_FORWARD_DEL}. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | public static final int KEYCODE_DEL = 67; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 237 | /** Key code constant: '`' (backtick) key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | public static final int KEYCODE_GRAVE = 68; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 239 | /** Key code constant: '-'. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | public static final int KEYCODE_MINUS = 69; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 241 | /** Key code constant: '=' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | public static final int KEYCODE_EQUALS = 70; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 243 | /** Key code constant: '[' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | public static final int KEYCODE_LEFT_BRACKET = 71; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 245 | /** Key code constant: ']' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | public static final int KEYCODE_RIGHT_BRACKET = 72; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 247 | /** Key code constant: '\' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | public static final int KEYCODE_BACKSLASH = 73; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 249 | /** Key code constant: ';' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | public static final int KEYCODE_SEMICOLON = 74; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 251 | /** Key code constant: ''' (apostrophe) key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | public static final int KEYCODE_APOSTROPHE = 75; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 253 | /** Key code constant: '/' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | public static final int KEYCODE_SLASH = 76; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 255 | /** Key code constant: '@' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | public static final int KEYCODE_AT = 77; |
Jeff Brown | 224d4a1 | 2010-10-07 20:28:53 -0700 | [diff] [blame] | 257 | /** Key code constant: Number modifier key. |
| 258 | * Used to enter numeric symbols. |
| 259 | * This key is not Num Lock; it is more like {@link #KEYCODE_ALT_LEFT} and is |
| 260 | * interpreted as an ALT key by {@link android.text.method.MetaKeyKeyListener}. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | public static final int KEYCODE_NUM = 78; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 262 | /** Key code constant: Headset Hook key. |
| 263 | * Used to hang up calls and stop media. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | public static final int KEYCODE_HEADSETHOOK = 79; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 265 | /** Key code constant: Camera Focus key. |
| 266 | * Used to focus the camera. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | public static final int KEYCODE_FOCUS = 80; // *Camera* focus |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 268 | /** Key code constant: '+' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | public static final int KEYCODE_PLUS = 81; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 270 | /** Key code constant: Menu key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | public static final int KEYCODE_MENU = 82; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 272 | /** Key code constant: Notification key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | public static final int KEYCODE_NOTIFICATION = 83; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 274 | /** Key code constant: Search key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | public static final int KEYCODE_SEARCH = 84; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 276 | /** Key code constant: Play/Pause media key. */ |
Dianne Hackborn | 935ae46 | 2009-04-13 16:11:55 -0700 | [diff] [blame] | 277 | public static final int KEYCODE_MEDIA_PLAY_PAUSE= 85; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 278 | /** Key code constant: Stop media key. */ |
Dianne Hackborn | 935ae46 | 2009-04-13 16:11:55 -0700 | [diff] [blame] | 279 | public static final int KEYCODE_MEDIA_STOP = 86; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 280 | /** Key code constant: Play Next media key. */ |
Dianne Hackborn | 935ae46 | 2009-04-13 16:11:55 -0700 | [diff] [blame] | 281 | public static final int KEYCODE_MEDIA_NEXT = 87; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 282 | /** Key code constant: Play Previous media key. */ |
Dianne Hackborn | 935ae46 | 2009-04-13 16:11:55 -0700 | [diff] [blame] | 283 | public static final int KEYCODE_MEDIA_PREVIOUS = 88; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 284 | /** Key code constant: Rewind media key. */ |
Dianne Hackborn | 935ae46 | 2009-04-13 16:11:55 -0700 | [diff] [blame] | 285 | public static final int KEYCODE_MEDIA_REWIND = 89; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 286 | /** Key code constant: Fast Forward media key. */ |
Dianne Hackborn | 935ae46 | 2009-04-13 16:11:55 -0700 | [diff] [blame] | 287 | public static final int KEYCODE_MEDIA_FAST_FORWARD = 90; |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 288 | /** Key code constant: Mute key. |
| 289 | * Mutes the microphone, unlike {@link #KEYCODE_VOLUME_MUTE}. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | public static final int KEYCODE_MUTE = 91; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 291 | /** Key code constant: Page Up key. */ |
Chih-Wei Huang | 4fedd80 | 2009-05-27 15:52:50 +0800 | [diff] [blame] | 292 | public static final int KEYCODE_PAGE_UP = 92; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 293 | /** Key code constant: Page Down key. */ |
Chih-Wei Huang | 4fedd80 | 2009-05-27 15:52:50 +0800 | [diff] [blame] | 294 | public static final int KEYCODE_PAGE_DOWN = 93; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 295 | /** Key code constant: Picture Symbols modifier key. |
| 296 | * Used to switch symbol sets (Emoji, Kao-moji). */ |
mogimo | b032bc0 | 2009-10-03 03:13:56 +0900 | [diff] [blame] | 297 | public static final int KEYCODE_PICTSYMBOLS = 94; // switch symbol-sets (Emoji,Kao-moji) |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 298 | /** Key code constant: Switch Charset modifier key. |
| 299 | * Used to switch character sets (Kanji, Katakana). */ |
mogimo | b032bc0 | 2009-10-03 03:13:56 +0900 | [diff] [blame] | 300 | public static final int KEYCODE_SWITCH_CHARSET = 95; // switch char-sets (Kanji,Katakana) |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 301 | /** Key code constant: A Button key. |
| 302 | * On a game controller, the A button should be either the button labeled A |
Michael Wright | 6b57bde | 2013-01-28 20:35:58 -0800 | [diff] [blame] | 303 | * or the first button on the bottom row of controller buttons. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 304 | public static final int KEYCODE_BUTTON_A = 96; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 305 | /** Key code constant: B Button key. |
| 306 | * On a game controller, the B button should be either the button labeled B |
Michael Wright | 6b57bde | 2013-01-28 20:35:58 -0800 | [diff] [blame] | 307 | * or the second button on the bottom row of controller buttons. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 308 | public static final int KEYCODE_BUTTON_B = 97; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 309 | /** Key code constant: C Button key. |
| 310 | * On a game controller, the C button should be either the button labeled C |
Michael Wright | 6b57bde | 2013-01-28 20:35:58 -0800 | [diff] [blame] | 311 | * or the third button on the bottom row of controller buttons. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 312 | public static final int KEYCODE_BUTTON_C = 98; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 313 | /** Key code constant: X Button key. |
| 314 | * On a game controller, the X button should be either the button labeled X |
Michael Wright | 6b57bde | 2013-01-28 20:35:58 -0800 | [diff] [blame] | 315 | * or the first button on the upper row of controller buttons. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 316 | public static final int KEYCODE_BUTTON_X = 99; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 317 | /** Key code constant: Y Button key. |
| 318 | * On a game controller, the Y button should be either the button labeled Y |
Michael Wright | 6b57bde | 2013-01-28 20:35:58 -0800 | [diff] [blame] | 319 | * or the second button on the upper row of controller buttons. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 320 | public static final int KEYCODE_BUTTON_Y = 100; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 321 | /** Key code constant: Z Button key. |
| 322 | * On a game controller, the Z button should be either the button labeled Z |
Michael Wright | 6b57bde | 2013-01-28 20:35:58 -0800 | [diff] [blame] | 323 | * or the third button on the upper row of controller buttons. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 324 | public static final int KEYCODE_BUTTON_Z = 101; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 325 | /** Key code constant: L1 Button key. |
| 326 | * On a game controller, the L1 button should be either the button labeled L1 (or L) |
| 327 | * or the top left trigger button. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 328 | public static final int KEYCODE_BUTTON_L1 = 102; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 329 | /** Key code constant: R1 Button key. |
| 330 | * On a game controller, the R1 button should be either the button labeled R1 (or R) |
| 331 | * or the top right trigger button. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 332 | public static final int KEYCODE_BUTTON_R1 = 103; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 333 | /** Key code constant: L2 Button key. |
| 334 | * On a game controller, the L2 button should be either the button labeled L2 |
| 335 | * or the bottom left trigger button. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 336 | public static final int KEYCODE_BUTTON_L2 = 104; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 337 | /** Key code constant: R2 Button key. |
| 338 | * On a game controller, the R2 button should be either the button labeled R2 |
| 339 | * or the bottom right trigger button. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 340 | public static final int KEYCODE_BUTTON_R2 = 105; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 341 | /** Key code constant: Left Thumb Button key. |
| 342 | * On a game controller, the left thumb button indicates that the left (or only) |
| 343 | * joystick is pressed. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 344 | public static final int KEYCODE_BUTTON_THUMBL = 106; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 345 | /** Key code constant: Right Thumb Button key. |
| 346 | * On a game controller, the right thumb button indicates that the right |
| 347 | * joystick is pressed. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 348 | public static final int KEYCODE_BUTTON_THUMBR = 107; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 349 | /** Key code constant: Start Button key. |
| 350 | * On a game controller, the button labeled Start. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 351 | public static final int KEYCODE_BUTTON_START = 108; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 352 | /** Key code constant: Select Button key. |
| 353 | * On a game controller, the button labeled Select. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 354 | public static final int KEYCODE_BUTTON_SELECT = 109; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 355 | /** Key code constant: Mode Button key. |
| 356 | * On a game controller, the button labeled Mode. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 357 | public static final int KEYCODE_BUTTON_MODE = 110; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 358 | /** Key code constant: Escape key. */ |
| 359 | public static final int KEYCODE_ESCAPE = 111; |
| 360 | /** Key code constant: Forward Delete key. |
| 361 | * Deletes characters ahead of the insertion point, unlike {@link #KEYCODE_DEL}. */ |
| 362 | public static final int KEYCODE_FORWARD_DEL = 112; |
| 363 | /** Key code constant: Left Control modifier key. */ |
| 364 | public static final int KEYCODE_CTRL_LEFT = 113; |
| 365 | /** Key code constant: Right Control modifier key. */ |
| 366 | public static final int KEYCODE_CTRL_RIGHT = 114; |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 367 | /** Key code constant: Caps Lock key. */ |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 368 | public static final int KEYCODE_CAPS_LOCK = 115; |
| 369 | /** Key code constant: Scroll Lock key. */ |
| 370 | public static final int KEYCODE_SCROLL_LOCK = 116; |
| 371 | /** Key code constant: Left Meta modifier key. */ |
| 372 | public static final int KEYCODE_META_LEFT = 117; |
| 373 | /** Key code constant: Right Meta modifier key. */ |
| 374 | public static final int KEYCODE_META_RIGHT = 118; |
| 375 | /** Key code constant: Function modifier key. */ |
| 376 | public static final int KEYCODE_FUNCTION = 119; |
| 377 | /** Key code constant: System Request / Print Screen key. */ |
| 378 | public static final int KEYCODE_SYSRQ = 120; |
| 379 | /** Key code constant: Break / Pause key. */ |
| 380 | public static final int KEYCODE_BREAK = 121; |
| 381 | /** Key code constant: Home Movement key. |
| 382 | * Used for scrolling or moving the cursor around to the start of a line |
| 383 | * or to the top of a list. */ |
| 384 | public static final int KEYCODE_MOVE_HOME = 122; |
| 385 | /** Key code constant: End Movement key. |
| 386 | * Used for scrolling or moving the cursor around to the end of a line |
| 387 | * or to the bottom of a list. */ |
| 388 | public static final int KEYCODE_MOVE_END = 123; |
| 389 | /** Key code constant: Insert key. |
| 390 | * Toggles insert / overwrite edit mode. */ |
| 391 | public static final int KEYCODE_INSERT = 124; |
| 392 | /** Key code constant: Forward key. |
| 393 | * Navigates forward in the history stack. Complement of {@link #KEYCODE_BACK}. */ |
| 394 | public static final int KEYCODE_FORWARD = 125; |
| 395 | /** Key code constant: Play media key. */ |
| 396 | public static final int KEYCODE_MEDIA_PLAY = 126; |
| 397 | /** Key code constant: Pause media key. */ |
| 398 | public static final int KEYCODE_MEDIA_PAUSE = 127; |
| 399 | /** Key code constant: Close media key. |
| 400 | * May be used to close a CD tray, for example. */ |
| 401 | public static final int KEYCODE_MEDIA_CLOSE = 128; |
| 402 | /** Key code constant: Eject media key. |
| 403 | * May be used to eject a CD tray, for example. */ |
| 404 | public static final int KEYCODE_MEDIA_EJECT = 129; |
| 405 | /** Key code constant: Record media key. */ |
| 406 | public static final int KEYCODE_MEDIA_RECORD = 130; |
| 407 | /** Key code constant: F1 key. */ |
| 408 | public static final int KEYCODE_F1 = 131; |
| 409 | /** Key code constant: F2 key. */ |
| 410 | public static final int KEYCODE_F2 = 132; |
| 411 | /** Key code constant: F3 key. */ |
| 412 | public static final int KEYCODE_F3 = 133; |
| 413 | /** Key code constant: F4 key. */ |
| 414 | public static final int KEYCODE_F4 = 134; |
| 415 | /** Key code constant: F5 key. */ |
| 416 | public static final int KEYCODE_F5 = 135; |
| 417 | /** Key code constant: F6 key. */ |
| 418 | public static final int KEYCODE_F6 = 136; |
| 419 | /** Key code constant: F7 key. */ |
| 420 | public static final int KEYCODE_F7 = 137; |
| 421 | /** Key code constant: F8 key. */ |
| 422 | public static final int KEYCODE_F8 = 138; |
| 423 | /** Key code constant: F9 key. */ |
| 424 | public static final int KEYCODE_F9 = 139; |
| 425 | /** Key code constant: F10 key. */ |
| 426 | public static final int KEYCODE_F10 = 140; |
| 427 | /** Key code constant: F11 key. */ |
| 428 | public static final int KEYCODE_F11 = 141; |
| 429 | /** Key code constant: F12 key. */ |
| 430 | public static final int KEYCODE_F12 = 142; |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 431 | /** Key code constant: Num Lock key. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 432 | * This is the Num Lock key; it is different from {@link #KEYCODE_NUM}. |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 433 | * This key alters the behavior of other keys on the numeric keypad. */ |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 434 | public static final int KEYCODE_NUM_LOCK = 143; |
| 435 | /** Key code constant: Numeric keypad '0' key. */ |
| 436 | public static final int KEYCODE_NUMPAD_0 = 144; |
| 437 | /** Key code constant: Numeric keypad '1' key. */ |
| 438 | public static final int KEYCODE_NUMPAD_1 = 145; |
| 439 | /** Key code constant: Numeric keypad '2' key. */ |
| 440 | public static final int KEYCODE_NUMPAD_2 = 146; |
| 441 | /** Key code constant: Numeric keypad '3' key. */ |
| 442 | public static final int KEYCODE_NUMPAD_3 = 147; |
| 443 | /** Key code constant: Numeric keypad '4' key. */ |
| 444 | public static final int KEYCODE_NUMPAD_4 = 148; |
| 445 | /** Key code constant: Numeric keypad '5' key. */ |
| 446 | public static final int KEYCODE_NUMPAD_5 = 149; |
| 447 | /** Key code constant: Numeric keypad '6' key. */ |
| 448 | public static final int KEYCODE_NUMPAD_6 = 150; |
| 449 | /** Key code constant: Numeric keypad '7' key. */ |
| 450 | public static final int KEYCODE_NUMPAD_7 = 151; |
| 451 | /** Key code constant: Numeric keypad '8' key. */ |
| 452 | public static final int KEYCODE_NUMPAD_8 = 152; |
| 453 | /** Key code constant: Numeric keypad '9' key. */ |
| 454 | public static final int KEYCODE_NUMPAD_9 = 153; |
| 455 | /** Key code constant: Numeric keypad '/' key (for division). */ |
| 456 | public static final int KEYCODE_NUMPAD_DIVIDE = 154; |
| 457 | /** Key code constant: Numeric keypad '*' key (for multiplication). */ |
| 458 | public static final int KEYCODE_NUMPAD_MULTIPLY = 155; |
| 459 | /** Key code constant: Numeric keypad '-' key (for subtraction). */ |
| 460 | public static final int KEYCODE_NUMPAD_SUBTRACT = 156; |
| 461 | /** Key code constant: Numeric keypad '+' key (for addition). */ |
| 462 | public static final int KEYCODE_NUMPAD_ADD = 157; |
| 463 | /** Key code constant: Numeric keypad '.' key (for decimals or digit grouping). */ |
| 464 | public static final int KEYCODE_NUMPAD_DOT = 158; |
| 465 | /** Key code constant: Numeric keypad ',' key (for decimals or digit grouping). */ |
| 466 | public static final int KEYCODE_NUMPAD_COMMA = 159; |
| 467 | /** Key code constant: Numeric keypad Enter key. */ |
| 468 | public static final int KEYCODE_NUMPAD_ENTER = 160; |
| 469 | /** Key code constant: Numeric keypad '=' key. */ |
| 470 | public static final int KEYCODE_NUMPAD_EQUALS = 161; |
| 471 | /** Key code constant: Numeric keypad '(' key. */ |
| 472 | public static final int KEYCODE_NUMPAD_LEFT_PAREN = 162; |
| 473 | /** Key code constant: Numeric keypad ')' key. */ |
| 474 | public static final int KEYCODE_NUMPAD_RIGHT_PAREN = 163; |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 475 | /** Key code constant: Volume Mute key. |
| 476 | * Mutes the speaker, unlike {@link #KEYCODE_MUTE}. |
| 477 | * This key should normally be implemented as a toggle such that the first press |
| 478 | * mutes the speaker and the second press restores the original volume. */ |
| 479 | public static final int KEYCODE_VOLUME_MUTE = 164; |
Jason Bayer | 3adf490 | 2010-11-09 14:54:55 -0800 | [diff] [blame] | 480 | /** Key code constant: Info key. |
| 481 | * Common on TV remotes to show additional information related to what is |
| 482 | * currently being viewed. */ |
| 483 | public static final int KEYCODE_INFO = 165; |
| 484 | /** Key code constant: Channel up key. |
| 485 | * On TV remotes, increments the television channel. */ |
| 486 | public static final int KEYCODE_CHANNEL_UP = 166; |
| 487 | /** Key code constant: Channel down key. |
| 488 | * On TV remotes, decrements the television channel. */ |
| 489 | public static final int KEYCODE_CHANNEL_DOWN = 167; |
| 490 | /** Key code constant: Zoom in key. */ |
| 491 | public static final int KEYCODE_ZOOM_IN = 168; |
| 492 | /** Key code constant: Zoom out key. */ |
| 493 | public static final int KEYCODE_ZOOM_OUT = 169; |
| 494 | /** Key code constant: TV key. |
| 495 | * On TV remotes, switches to viewing live TV. */ |
| 496 | public static final int KEYCODE_TV = 170; |
| 497 | /** Key code constant: Window key. |
| 498 | * On TV remotes, toggles picture-in-picture mode or other windowing functions. */ |
| 499 | public static final int KEYCODE_WINDOW = 171; |
| 500 | /** Key code constant: Guide key. |
| 501 | * On TV remotes, shows a programming guide. */ |
| 502 | public static final int KEYCODE_GUIDE = 172; |
| 503 | /** Key code constant: DVR key. |
| 504 | * On some TV remotes, switches to a DVR mode for recorded shows. */ |
| 505 | public static final int KEYCODE_DVR = 173; |
| 506 | /** Key code constant: Bookmark key. |
| 507 | * On some TV remotes, bookmarks content or web pages. */ |
| 508 | public static final int KEYCODE_BOOKMARK = 174; |
| 509 | /** Key code constant: Toggle captions key. |
| 510 | * Switches the mode for closed-captioning text, for example during television shows. */ |
| 511 | public static final int KEYCODE_CAPTIONS = 175; |
| 512 | /** Key code constant: Settings key. |
| 513 | * Starts the system settings activity. */ |
| 514 | public static final int KEYCODE_SETTINGS = 176; |
| 515 | /** Key code constant: TV power key. |
| 516 | * On TV remotes, toggles the power on a television screen. */ |
| 517 | public static final int KEYCODE_TV_POWER = 177; |
| 518 | /** Key code constant: TV input key. |
| 519 | * On TV remotes, switches the input on a television screen. */ |
| 520 | public static final int KEYCODE_TV_INPUT = 178; |
| 521 | /** Key code constant: Set-top-box power key. |
| 522 | * On TV remotes, toggles the power on an external Set-top-box. */ |
| 523 | public static final int KEYCODE_STB_POWER = 179; |
| 524 | /** Key code constant: Set-top-box input key. |
| 525 | * On TV remotes, switches the input mode on an external Set-top-box. */ |
| 526 | public static final int KEYCODE_STB_INPUT = 180; |
| 527 | /** Key code constant: A/V Receiver power key. |
| 528 | * On TV remotes, toggles the power on an external A/V Receiver. */ |
| 529 | public static final int KEYCODE_AVR_POWER = 181; |
| 530 | /** Key code constant: A/V Receiver input key. |
| 531 | * On TV remotes, switches the input mode on an external A/V Receiver. */ |
| 532 | public static final int KEYCODE_AVR_INPUT = 182; |
| 533 | /** Key code constant: Red "programmable" key. |
| 534 | * On TV remotes, acts as a contextual/programmable key. */ |
| 535 | public static final int KEYCODE_PROG_RED = 183; |
| 536 | /** Key code constant: Green "programmable" key. |
| 537 | * On TV remotes, actsas a contextual/programmable key. */ |
| 538 | public static final int KEYCODE_PROG_GREEN = 184; |
| 539 | /** Key code constant: Yellow "programmable" key. |
| 540 | * On TV remotes, acts as a contextual/programmable key. */ |
| 541 | public static final int KEYCODE_PROG_YELLOW = 185; |
| 542 | /** Key code constant: Blue "programmable" key. |
| 543 | * On TV remotes, acts as a contextual/programmable key. */ |
| 544 | public static final int KEYCODE_PROG_BLUE = 186; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 545 | /** Key code constant: App switch key. |
| 546 | * Should bring up the application switcher dialog. */ |
| 547 | public static final int KEYCODE_APP_SWITCH = 187; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 548 | /** Key code constant: Generic Game Pad Button #1.*/ |
| 549 | public static final int KEYCODE_BUTTON_1 = 188; |
| 550 | /** Key code constant: Generic Game Pad Button #2.*/ |
| 551 | public static final int KEYCODE_BUTTON_2 = 189; |
| 552 | /** Key code constant: Generic Game Pad Button #3.*/ |
| 553 | public static final int KEYCODE_BUTTON_3 = 190; |
| 554 | /** Key code constant: Generic Game Pad Button #4.*/ |
| 555 | public static final int KEYCODE_BUTTON_4 = 191; |
| 556 | /** Key code constant: Generic Game Pad Button #5.*/ |
| 557 | public static final int KEYCODE_BUTTON_5 = 192; |
| 558 | /** Key code constant: Generic Game Pad Button #6.*/ |
| 559 | public static final int KEYCODE_BUTTON_6 = 193; |
| 560 | /** Key code constant: Generic Game Pad Button #7.*/ |
| 561 | public static final int KEYCODE_BUTTON_7 = 194; |
| 562 | /** Key code constant: Generic Game Pad Button #8.*/ |
| 563 | public static final int KEYCODE_BUTTON_8 = 195; |
| 564 | /** Key code constant: Generic Game Pad Button #9.*/ |
| 565 | public static final int KEYCODE_BUTTON_9 = 196; |
| 566 | /** Key code constant: Generic Game Pad Button #10.*/ |
| 567 | public static final int KEYCODE_BUTTON_10 = 197; |
| 568 | /** Key code constant: Generic Game Pad Button #11.*/ |
| 569 | public static final int KEYCODE_BUTTON_11 = 198; |
| 570 | /** Key code constant: Generic Game Pad Button #12.*/ |
| 571 | public static final int KEYCODE_BUTTON_12 = 199; |
| 572 | /** Key code constant: Generic Game Pad Button #13.*/ |
| 573 | public static final int KEYCODE_BUTTON_13 = 200; |
| 574 | /** Key code constant: Generic Game Pad Button #14.*/ |
| 575 | public static final int KEYCODE_BUTTON_14 = 201; |
| 576 | /** Key code constant: Generic Game Pad Button #15.*/ |
| 577 | public static final int KEYCODE_BUTTON_15 = 202; |
| 578 | /** Key code constant: Generic Game Pad Button #16.*/ |
| 579 | public static final int KEYCODE_BUTTON_16 = 203; |
Jeff Brown | 9812aed | 2011-03-07 17:09:51 -0800 | [diff] [blame] | 580 | /** Key code constant: Language Switch key. |
| 581 | * Toggles the current input language such as switching between English and Japanese on |
| 582 | * a QWERTY keyboard. On some devices, the same function may be performed by |
| 583 | * pressing Shift+Spacebar. */ |
| 584 | public static final int KEYCODE_LANGUAGE_SWITCH = 204; |
| 585 | /** Key code constant: Manner Mode key. |
| 586 | * Toggles silent or vibrate mode on and off to make the device behave more politely |
| 587 | * in certain settings such as on a crowded train. On some devices, the key may only |
| 588 | * operate when long-pressed. */ |
| 589 | public static final int KEYCODE_MANNER_MODE = 205; |
| 590 | /** Key code constant: 3D Mode key. |
| 591 | * Toggles the display between 2D and 3D mode. */ |
| 592 | public static final int KEYCODE_3D_MODE = 206; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 593 | /** Key code constant: Contacts special function key. |
| 594 | * Used to launch an address book application. */ |
| 595 | public static final int KEYCODE_CONTACTS = 207; |
| 596 | /** Key code constant: Calendar special function key. |
| 597 | * Used to launch a calendar application. */ |
| 598 | public static final int KEYCODE_CALENDAR = 208; |
| 599 | /** Key code constant: Music special function key. |
| 600 | * Used to launch a music player application. */ |
| 601 | public static final int KEYCODE_MUSIC = 209; |
| 602 | /** Key code constant: Calculator special function key. |
| 603 | * Used to launch a calculator application. */ |
| 604 | public static final int KEYCODE_CALCULATOR = 210; |
Yang Chuang | 7511f9c | 2012-02-10 15:18:26 +0800 | [diff] [blame] | 605 | /** Key code constant: Japanese full-width / half-width key. */ |
| 606 | public static final int KEYCODE_ZENKAKU_HANKAKU = 211; |
| 607 | /** Key code constant: Japanese alphanumeric key. */ |
| 608 | public static final int KEYCODE_EISU = 212; |
| 609 | /** Key code constant: Japanese non-conversion key. */ |
| 610 | public static final int KEYCODE_MUHENKAN = 213; |
| 611 | /** Key code constant: Japanese conversion key. */ |
| 612 | public static final int KEYCODE_HENKAN = 214; |
| 613 | /** Key code constant: Japanese katakana / hiragana key. */ |
| 614 | public static final int KEYCODE_KATAKANA_HIRAGANA = 215; |
| 615 | /** Key code constant: Japanese Yen key. */ |
| 616 | public static final int KEYCODE_YEN = 216; |
| 617 | /** Key code constant: Japanese Ro key. */ |
| 618 | public static final int KEYCODE_RO = 217; |
| 619 | /** Key code constant: Japanese kana key. */ |
| 620 | public static final int KEYCODE_KANA = 218; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 621 | /** Key code constant: Assist key. |
| 622 | * Launches the global assist activity. Not delivered to applications. */ |
| 623 | public static final int KEYCODE_ASSIST = 219; |
Michael Wright | 1df477a | 2013-01-31 16:19:18 -0800 | [diff] [blame] | 624 | /** Key code constant: Brightness Down key. |
| 625 | * Adjusts the screen brightness down. */ |
| 626 | public static final int KEYCODE_BRIGHTNESS_DOWN = 220; |
| 627 | /** Key code constant: Brightness Up key. |
| 628 | * Adjusts the screen brightness up. */ |
| 629 | public static final int KEYCODE_BRIGHTNESS_UP = 221; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 630 | /** Key code constant: Audio Track key. |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 631 | * Switches the audio tracks. */ |
| 632 | public static final int KEYCODE_MEDIA_AUDIO_TRACK = 222; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 633 | /** Key code constant: Sleep key. |
| 634 | * Puts the device to sleep. Behaves somewhat like {@link #KEYCODE_POWER} but it |
| 635 | * has no effect if the device is already asleep. */ |
| 636 | public static final int KEYCODE_SLEEP = 223; |
| 637 | /** Key code constant: Wakeup key. |
| 638 | * Wakes up the device. Behaves somewhat like {@link #KEYCODE_POWER} but it |
| 639 | * has no effect if the device is already awake. */ |
| 640 | public static final int KEYCODE_WAKEUP = 224; |
Tim Kilbourn | 87cd0dc | 2014-04-14 15:37:51 -0700 | [diff] [blame] | 641 | /** Key code constant: Pairing key. |
| 642 | * Initiates peripheral pairing mode. Useful for pairing remote control |
| 643 | * devices or game controllers, especially if no other input mode is |
| 644 | * available. */ |
| 645 | public static final int KEYCODE_PAIRING = 225; |
Jinsuk Kim | 96658f7 | 2014-05-14 15:33:43 +0900 | [diff] [blame] | 646 | /** Key code constant: Media Top Menu key. |
| 647 | * Goes to the top of media menu. */ |
| 648 | public static final int KEYCODE_MEDIA_TOP_MENU = 226; |
| 649 | /** Key code constant: '11' key. */ |
| 650 | public static final int KEYCODE_11 = 227; |
| 651 | /** Key code constant: '12' key. */ |
| 652 | public static final int KEYCODE_12 = 228; |
| 653 | /** Key code constant: Last Channel key. |
| 654 | * Goes to the last viewed channel. */ |
| 655 | public static final int KEYCODE_LAST_CHANNEL = 229; |
| 656 | /** Key code constant: TV data service key. |
| 657 | * Displays data services like weather, sports. */ |
| 658 | public static final int KEYCODE_TV_DATA_SERVICE = 230; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 659 | /** Key code constant: Voice Assist key. |
| 660 | * Launches the global voice assist activity. Not delivered to applications. */ |
| 661 | public static final int KEYCODE_VOICE_ASSIST = 231; |
ASAZU, Hideki | dbd6aba | 2014-08-27 18:03:30 +0900 | [diff] [blame] | 662 | /** Key code constant: Radio key. |
| 663 | * Toggles TV service / Radio service. */ |
| 664 | public static final int KEYCODE_TV_RADIO_SERVICE = 232; |
| 665 | /** Key code constant: Teletext key. |
| 666 | * Displays Teletext service. */ |
| 667 | public static final int KEYCODE_TV_TELETEXT = 233; |
| 668 | /** Key code constant: Number entry key. |
| 669 | * Initiates to enter multi-digit channel nubmber when each digit key is assigned |
| 670 | * for selecting separate channel. Corresponds to Number Entry Mode (0x1D) of CEC |
| 671 | * User Control Code. */ |
| 672 | public static final int KEYCODE_TV_NUMBER_ENTRY = 234; |
| 673 | /** Key code constant: Analog Terrestrial key. |
| 674 | * Switches to analog terrestrial broadcast service. */ |
| 675 | public static final int KEYCODE_TV_TERRESTRIAL_ANALOG = 235; |
| 676 | /** Key code constant: Digital Terrestrial key. |
| 677 | * Switches to digital terrestrial broadcast service. */ |
| 678 | public static final int KEYCODE_TV_TERRESTRIAL_DIGITAL = 236; |
| 679 | /** Key code constant: Satellite key. |
| 680 | * Switches to digital satellite broadcast service. */ |
| 681 | public static final int KEYCODE_TV_SATELLITE = 237; |
| 682 | /** Key code constant: BS key. |
| 683 | * Switches to BS digital satellite broadcasting service available in Japan. */ |
| 684 | public static final int KEYCODE_TV_SATELLITE_BS = 238; |
| 685 | /** Key code constant: CS key. |
| 686 | * Switches to CS digital satellite broadcasting service available in Japan. */ |
| 687 | public static final int KEYCODE_TV_SATELLITE_CS = 239; |
| 688 | /** Key code constant: BS/CS key. |
| 689 | * Toggles between BS and CS digital satellite services. */ |
| 690 | public static final int KEYCODE_TV_SATELLITE_SERVICE = 240; |
| 691 | /** Key code constant: Toggle Network key. |
| 692 | * Toggles selecting broacast services. */ |
| 693 | public static final int KEYCODE_TV_NETWORK = 241; |
| 694 | /** Key code constant: Antenna/Cable key. |
| 695 | * Toggles broadcast input source between antenna and cable. */ |
| 696 | public static final int KEYCODE_TV_ANTENNA_CABLE = 242; |
| 697 | /** Key code constant: HDMI #1 key. |
| 698 | * Switches to HDMI input #1. */ |
| 699 | public static final int KEYCODE_TV_INPUT_HDMI_1 = 243; |
| 700 | /** Key code constant: HDMI #2 key. |
| 701 | * Switches to HDMI input #2. */ |
| 702 | public static final int KEYCODE_TV_INPUT_HDMI_2 = 244; |
| 703 | /** Key code constant: HDMI #3 key. |
| 704 | * Switches to HDMI input #3. */ |
| 705 | public static final int KEYCODE_TV_INPUT_HDMI_3 = 245; |
| 706 | /** Key code constant: HDMI #4 key. |
| 707 | * Switches to HDMI input #4. */ |
| 708 | public static final int KEYCODE_TV_INPUT_HDMI_4 = 246; |
| 709 | /** Key code constant: Composite #1 key. |
| 710 | * Switches to composite video input #1. */ |
| 711 | public static final int KEYCODE_TV_INPUT_COMPOSITE_1 = 247; |
| 712 | /** Key code constant: Composite #2 key. |
| 713 | * Switches to composite video input #2. */ |
| 714 | public static final int KEYCODE_TV_INPUT_COMPOSITE_2 = 248; |
| 715 | /** Key code constant: Component #1 key. |
| 716 | * Switches to component video input #1. */ |
| 717 | public static final int KEYCODE_TV_INPUT_COMPONENT_1 = 249; |
| 718 | /** Key code constant: Component #2 key. |
| 719 | * Switches to component video input #2. */ |
| 720 | public static final int KEYCODE_TV_INPUT_COMPONENT_2 = 250; |
| 721 | /** Key code constant: VGA #1 key. |
| 722 | * Switches to VGA (analog RGB) input #1. */ |
| 723 | public static final int KEYCODE_TV_INPUT_VGA_1 = 251; |
| 724 | /** Key code constant: Audio description key. |
| 725 | * Toggles audio description off / on. */ |
| 726 | public static final int KEYCODE_TV_AUDIO_DESCRIPTION = 252; |
| 727 | /** Key code constant: Audio description mixing volume up key. |
| 728 | * Louden audio description volume as compared with normal audio volume. */ |
| 729 | public static final int KEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP = 253; |
| 730 | /** Key code constant: Audio description mixing volume down key. |
| 731 | * Lessen audio description volume as compared with normal audio volume. */ |
| 732 | public static final int KEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN = 254; |
| 733 | /** Key code constant: Zoom mode key. |
| 734 | * Changes Zoom mode (Normal, Full, Zoom, Wide-zoom, etc.) */ |
| 735 | public static final int KEYCODE_TV_ZOOM_MODE = 255; |
| 736 | /** Key code constant: Contents menu key. |
| 737 | * Goes to the title list. Corresponds to Contents Menu (0x0B) of CEC User Control |
| 738 | * Code */ |
| 739 | public static final int KEYCODE_TV_CONTENTS_MENU = 256; |
| 740 | /** Key code constant: Media context menu key. |
| 741 | * Goes to the context menu of media contents. Corresponds to Media Context-sensitive |
| 742 | * Menu (0x11) of CEC User Control Code. */ |
| 743 | public static final int KEYCODE_TV_MEDIA_CONTEXT_MENU = 257; |
| 744 | /** Key code constant: Timer programming key. |
| 745 | * Goes to the timer recording menu. Corresponds to Timer Programming (0x54) of |
| 746 | * CEC User Control Code. */ |
| 747 | public static final int KEYCODE_TV_TIMER_PROGRAMMING = 258; |
| 748 | /** Key code constant: Help key. */ |
| 749 | public static final int KEYCODE_HELP = 259; |
Michael Wright | 962c953 | 2015-08-06 15:16:22 +0100 | [diff] [blame] | 750 | /** Key code constant: Navigate to previous key. |
Joseph Cooper | 55b9ed4 | 2015-04-15 16:21:58 -0700 | [diff] [blame] | 751 | * Goes backward by one item in an ordered collection of items. */ |
| 752 | public static final int KEYCODE_NAVIGATE_PREVIOUS = 260; |
Michael Wright | 962c953 | 2015-08-06 15:16:22 +0100 | [diff] [blame] | 753 | /** Key code constant: Navigate to next key. |
Joseph Cooper | 55b9ed4 | 2015-04-15 16:21:58 -0700 | [diff] [blame] | 754 | * Advances to the next item in an ordered collection of items. */ |
| 755 | public static final int KEYCODE_NAVIGATE_NEXT = 261; |
| 756 | /** Key code constant: Navigate in key. |
Michael Wright | 962c953 | 2015-08-06 15:16:22 +0100 | [diff] [blame] | 757 | * Activates the item that currently has focus or expands to the next level of a navigation |
Joseph Cooper | 55b9ed4 | 2015-04-15 16:21:58 -0700 | [diff] [blame] | 758 | * hierarchy. */ |
| 759 | public static final int KEYCODE_NAVIGATE_IN = 262; |
| 760 | /** Key code constant: Navigate out key. |
Michael Wright | 962c953 | 2015-08-06 15:16:22 +0100 | [diff] [blame] | 761 | * Backs out one level of a navigation hierarchy or collapses the item that currently has |
Joseph Cooper | 55b9ed4 | 2015-04-15 16:21:58 -0700 | [diff] [blame] | 762 | * focus. */ |
| 763 | public static final int KEYCODE_NAVIGATE_OUT = 263; |
Anthony Hugh | 9d82668 | 2015-06-23 10:44:17 -0700 | [diff] [blame] | 764 | /** Key code constant: Primary stem key for Wear |
| 765 | * Main power/reset button on watch. */ |
| 766 | public static final int KEYCODE_STEM_PRIMARY = 264; |
| 767 | /** Key code constant: Generic stem key 1 for Wear */ |
| 768 | public static final int KEYCODE_STEM_1 = 265; |
| 769 | /** Key code constant: Generic stem key 2 for Wear */ |
| 770 | public static final int KEYCODE_STEM_2 = 266; |
| 771 | /** Key code constant: Generic stem key 3 for Wear */ |
| 772 | public static final int KEYCODE_STEM_3 = 267; |
David Stevens | a487f0c | 2015-07-31 11:00:50 -0700 | [diff] [blame] | 773 | /** Key code constant: Directional Pad Up-Left */ |
| 774 | public static final int KEYCODE_DPAD_UP_LEFT = 268; |
| 775 | /** Key code constant: Directional Pad Down-Left */ |
| 776 | public static final int KEYCODE_DPAD_DOWN_LEFT = 269; |
| 777 | /** Key code constant: Directional Pad Up-Right */ |
| 778 | public static final int KEYCODE_DPAD_UP_RIGHT = 270; |
| 779 | /** Key code constant: Directional Pad Down-Right */ |
| 780 | public static final int KEYCODE_DPAD_DOWN_RIGHT = 271; |
Michael Wright | 962c953 | 2015-08-06 15:16:22 +0100 | [diff] [blame] | 781 | /** Key code constant: Skip forward media key. */ |
| 782 | public static final int KEYCODE_MEDIA_SKIP_FORWARD = 272; |
| 783 | /** Key code constant: Skip backward media key. */ |
| 784 | public static final int KEYCODE_MEDIA_SKIP_BACKWARD = 273; |
| 785 | /** Key code constant: Step forward media key. |
| 786 | * Steps media forward, one frame at a time. */ |
| 787 | public static final int KEYCODE_MEDIA_STEP_FORWARD = 274; |
| 788 | /** Key code constant: Step backward media key. |
| 789 | * Steps media backward, one frame at a time. */ |
| 790 | public static final int KEYCODE_MEDIA_STEP_BACKWARD = 275; |
Nick Armstrong-Crews | 3a5a8c7 | 2015-09-09 09:25:03 -0700 | [diff] [blame] | 791 | /** Key code constant: put device to sleep unless a wakelock is held. */ |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 792 | public static final int KEYCODE_SOFT_SLEEP = 276; |
Michael Wright | ea84cff | 2015-10-21 18:08:30 +0100 | [diff] [blame] | 793 | /** Key code constant: Cut key. */ |
| 794 | public static final int KEYCODE_CUT = 277; |
| 795 | /** Key code constant: Copy key. */ |
| 796 | public static final int KEYCODE_COPY = 278; |
| 797 | /** Key code constant: Paste key. */ |
| 798 | public static final int KEYCODE_PASTE = 279; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 799 | |
Michael Wright | ea84cff | 2015-10-21 18:08:30 +0100 | [diff] [blame] | 800 | private static final int LAST_KEYCODE = KEYCODE_PASTE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | |
| 802 | // NOTE: If you add a new keycode here you must also add it to: |
| 803 | // isSystem() |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 804 | // isWakeKey() |
Chirayu Desai | 61c37ae | 2013-04-15 20:11:37 +0530 | [diff] [blame] | 805 | // frameworks/native/include/android/keycodes.h |
Jinsuk Kim | 96658f7 | 2014-05-14 15:33:43 +0900 | [diff] [blame] | 806 | // frameworks/native/include/input/InputEventLabels.h |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 807 | // frameworks/base/core/res/res/values/attrs.xml |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | // emulator? |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 809 | // LAST_KEYCODE |
Dianne Hackborn | 935ae46 | 2009-04-13 16:11:55 -0700 | [diff] [blame] | 810 | // |
| 811 | // Also Android currently does not reserve code ranges for vendor- |
| 812 | // specific key codes. If you have new key codes to have, you |
| 813 | // MUST contribute a patch to the open source project to define |
| 814 | // those new codes. This is intended to maintain a consistent |
| 815 | // set of key code definitions across all Android devices. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 816 | |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 817 | // Symbolic names of all metakeys in bit order from least significant to most significant. |
| 818 | // Accordingly there are exactly 32 values in this table. |
| 819 | private static final String[] META_SYMBOLIC_NAMES = new String[] { |
| 820 | "META_SHIFT_ON", |
| 821 | "META_ALT_ON", |
| 822 | "META_SYM_ON", |
| 823 | "META_FUNCTION_ON", |
| 824 | "META_ALT_LEFT_ON", |
| 825 | "META_ALT_RIGHT_ON", |
| 826 | "META_SHIFT_LEFT_ON", |
| 827 | "META_SHIFT_RIGHT_ON", |
| 828 | "META_CAP_LOCKED", |
| 829 | "META_ALT_LOCKED", |
| 830 | "META_SYM_LOCKED", |
| 831 | "0x00000800", |
| 832 | "META_CTRL_ON", |
| 833 | "META_CTRL_LEFT_ON", |
| 834 | "META_CTRL_RIGHT_ON", |
| 835 | "0x00008000", |
| 836 | "META_META_ON", |
| 837 | "META_META_LEFT_ON", |
| 838 | "META_META_RIGHT_ON", |
| 839 | "0x00080000", |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 840 | "META_CAPS_LOCK_ON", |
| 841 | "META_NUM_LOCK_ON", |
| 842 | "META_SCROLL_LOCK_ON", |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 843 | "0x00800000", |
| 844 | "0x01000000", |
| 845 | "0x02000000", |
| 846 | "0x04000000", |
| 847 | "0x08000000", |
| 848 | "0x10000000", |
| 849 | "0x20000000", |
| 850 | "0x40000000", |
| 851 | "0x80000000", |
| 852 | }; |
| 853 | |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 854 | private static final String LABEL_PREFIX = "KEYCODE_"; |
| 855 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 856 | /** |
| 857 | * @deprecated There are now more than MAX_KEYCODE keycodes. |
| 858 | * Use {@link #getMaxKeyCode()} instead. |
| 859 | */ |
| 860 | @Deprecated |
| 861 | public static final int MAX_KEYCODE = 84; |
| 862 | |
| 863 | /** |
| 864 | * {@link #getAction} value: the key has been pressed down. |
| 865 | */ |
| 866 | public static final int ACTION_DOWN = 0; |
| 867 | /** |
| 868 | * {@link #getAction} value: the key has been released. |
| 869 | */ |
| 870 | public static final int ACTION_UP = 1; |
| 871 | /** |
| 872 | * {@link #getAction} value: multiple duplicate key events have |
| 873 | * occurred in a row, or a complex string is being delivered. If the |
| 874 | * key code is not {#link {@link #KEYCODE_UNKNOWN} then the |
| 875 | * {#link {@link #getRepeatCount()} method returns the number of times |
| 876 | * the given key code should be executed. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 877 | * Otherwise, if the key code is {@link #KEYCODE_UNKNOWN}, then |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 878 | * this is a sequence of characters as returned by {@link #getCharacters}. |
| 879 | */ |
| 880 | public static final int ACTION_MULTIPLE = 2; |
| 881 | |
| 882 | /** |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 883 | * SHIFT key locked in CAPS mode. |
| 884 | * Reserved for use by {@link MetaKeyKeyListener} for a published constant in its API. |
| 885 | * @hide |
| 886 | */ |
| 887 | public static final int META_CAP_LOCKED = 0x100; |
| 888 | |
| 889 | /** |
| 890 | * ALT key locked. |
| 891 | * Reserved for use by {@link MetaKeyKeyListener} for a published constant in its API. |
| 892 | * @hide |
| 893 | */ |
| 894 | public static final int META_ALT_LOCKED = 0x200; |
| 895 | |
| 896 | /** |
| 897 | * SYM key locked. |
| 898 | * Reserved for use by {@link MetaKeyKeyListener} for a published constant in its API. |
| 899 | * @hide |
| 900 | */ |
| 901 | public static final int META_SYM_LOCKED = 0x400; |
| 902 | |
| 903 | /** |
| 904 | * Text is in selection mode. |
| 905 | * Reserved for use by {@link MetaKeyKeyListener} for a private unpublished constant |
| 906 | * in its API that is currently being retained for legacy reasons. |
| 907 | * @hide |
| 908 | */ |
| 909 | public static final int META_SELECTING = 0x800; |
| 910 | |
| 911 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | * <p>This mask is used to check whether one of the ALT meta keys is pressed.</p> |
| 913 | * |
| 914 | * @see #isAltPressed() |
| 915 | * @see #getMetaState() |
| 916 | * @see #KEYCODE_ALT_LEFT |
| 917 | * @see #KEYCODE_ALT_RIGHT |
| 918 | */ |
| 919 | public static final int META_ALT_ON = 0x02; |
| 920 | |
| 921 | /** |
| 922 | * <p>This mask is used to check whether the left ALT meta key is pressed.</p> |
| 923 | * |
| 924 | * @see #isAltPressed() |
| 925 | * @see #getMetaState() |
| 926 | * @see #KEYCODE_ALT_LEFT |
| 927 | */ |
| 928 | public static final int META_ALT_LEFT_ON = 0x10; |
| 929 | |
| 930 | /** |
| 931 | * <p>This mask is used to check whether the right the ALT meta key is pressed.</p> |
| 932 | * |
| 933 | * @see #isAltPressed() |
| 934 | * @see #getMetaState() |
| 935 | * @see #KEYCODE_ALT_RIGHT |
| 936 | */ |
| 937 | public static final int META_ALT_RIGHT_ON = 0x20; |
| 938 | |
| 939 | /** |
| 940 | * <p>This mask is used to check whether one of the SHIFT meta keys is pressed.</p> |
| 941 | * |
| 942 | * @see #isShiftPressed() |
| 943 | * @see #getMetaState() |
| 944 | * @see #KEYCODE_SHIFT_LEFT |
| 945 | * @see #KEYCODE_SHIFT_RIGHT |
| 946 | */ |
| 947 | public static final int META_SHIFT_ON = 0x1; |
| 948 | |
| 949 | /** |
| 950 | * <p>This mask is used to check whether the left SHIFT meta key is pressed.</p> |
| 951 | * |
| 952 | * @see #isShiftPressed() |
| 953 | * @see #getMetaState() |
| 954 | * @see #KEYCODE_SHIFT_LEFT |
| 955 | */ |
| 956 | public static final int META_SHIFT_LEFT_ON = 0x40; |
| 957 | |
| 958 | /** |
| 959 | * <p>This mask is used to check whether the right SHIFT meta key is pressed.</p> |
| 960 | * |
| 961 | * @see #isShiftPressed() |
| 962 | * @see #getMetaState() |
| 963 | * @see #KEYCODE_SHIFT_RIGHT |
| 964 | */ |
| 965 | public static final int META_SHIFT_RIGHT_ON = 0x80; |
| 966 | |
| 967 | /** |
| 968 | * <p>This mask is used to check whether the SYM meta key is pressed.</p> |
| 969 | * |
| 970 | * @see #isSymPressed() |
| 971 | * @see #getMetaState() |
| 972 | */ |
| 973 | public static final int META_SYM_ON = 0x4; |
| 974 | |
| 975 | /** |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 976 | * <p>This mask is used to check whether the FUNCTION meta key is pressed.</p> |
| 977 | * |
| 978 | * @see #isFunctionPressed() |
| 979 | * @see #getMetaState() |
| 980 | */ |
| 981 | public static final int META_FUNCTION_ON = 0x8; |
| 982 | |
| 983 | /** |
| 984 | * <p>This mask is used to check whether one of the CTRL meta keys is pressed.</p> |
| 985 | * |
| 986 | * @see #isCtrlPressed() |
| 987 | * @see #getMetaState() |
| 988 | * @see #KEYCODE_CTRL_LEFT |
| 989 | * @see #KEYCODE_CTRL_RIGHT |
| 990 | */ |
| 991 | public static final int META_CTRL_ON = 0x1000; |
| 992 | |
| 993 | /** |
| 994 | * <p>This mask is used to check whether the left CTRL meta key is pressed.</p> |
| 995 | * |
| 996 | * @see #isCtrlPressed() |
| 997 | * @see #getMetaState() |
| 998 | * @see #KEYCODE_CTRL_LEFT |
| 999 | */ |
| 1000 | public static final int META_CTRL_LEFT_ON = 0x2000; |
| 1001 | |
| 1002 | /** |
| 1003 | * <p>This mask is used to check whether the right CTRL meta key is pressed.</p> |
| 1004 | * |
| 1005 | * @see #isCtrlPressed() |
| 1006 | * @see #getMetaState() |
| 1007 | * @see #KEYCODE_CTRL_RIGHT |
| 1008 | */ |
| 1009 | public static final int META_CTRL_RIGHT_ON = 0x4000; |
| 1010 | |
| 1011 | /** |
| 1012 | * <p>This mask is used to check whether one of the META meta keys is pressed.</p> |
| 1013 | * |
| 1014 | * @see #isMetaPressed() |
| 1015 | * @see #getMetaState() |
| 1016 | * @see #KEYCODE_META_LEFT |
| 1017 | * @see #KEYCODE_META_RIGHT |
| 1018 | */ |
| 1019 | public static final int META_META_ON = 0x10000; |
| 1020 | |
| 1021 | /** |
| 1022 | * <p>This mask is used to check whether the left META meta key is pressed.</p> |
| 1023 | * |
| 1024 | * @see #isMetaPressed() |
| 1025 | * @see #getMetaState() |
| 1026 | * @see #KEYCODE_META_LEFT |
| 1027 | */ |
| 1028 | public static final int META_META_LEFT_ON = 0x20000; |
| 1029 | |
| 1030 | /** |
| 1031 | * <p>This mask is used to check whether the right META meta key is pressed.</p> |
| 1032 | * |
| 1033 | * @see #isMetaPressed() |
| 1034 | * @see #getMetaState() |
| 1035 | * @see #KEYCODE_META_RIGHT |
| 1036 | */ |
| 1037 | public static final int META_META_RIGHT_ON = 0x40000; |
| 1038 | |
| 1039 | /** |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1040 | * <p>This mask is used to check whether the CAPS LOCK meta key is on.</p> |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1041 | * |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1042 | * @see #isCapsLockOn() |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1043 | * @see #getMetaState() |
| 1044 | * @see #KEYCODE_CAPS_LOCK |
| 1045 | */ |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1046 | public static final int META_CAPS_LOCK_ON = 0x100000; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1047 | |
| 1048 | /** |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1049 | * <p>This mask is used to check whether the NUM LOCK meta key is on.</p> |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1050 | * |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1051 | * @see #isNumLockOn() |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1052 | * @see #getMetaState() |
| 1053 | * @see #KEYCODE_NUM_LOCK |
| 1054 | */ |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1055 | public static final int META_NUM_LOCK_ON = 0x200000; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1056 | |
| 1057 | /** |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1058 | * <p>This mask is used to check whether the SCROLL LOCK meta key is on.</p> |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1059 | * |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1060 | * @see #isScrollLockOn() |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1061 | * @see #getMetaState() |
| 1062 | * @see #KEYCODE_SCROLL_LOCK |
| 1063 | */ |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1064 | public static final int META_SCROLL_LOCK_ON = 0x400000; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1065 | |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 1066 | /** |
| 1067 | * This mask is a combination of {@link #META_SHIFT_ON}, {@link #META_SHIFT_LEFT_ON} |
| 1068 | * and {@link #META_SHIFT_RIGHT_ON}. |
| 1069 | */ |
Jeff Brown | c1df907 | 2010-12-21 16:38:50 -0800 | [diff] [blame] | 1070 | public static final int META_SHIFT_MASK = META_SHIFT_ON |
| 1071 | | META_SHIFT_LEFT_ON | META_SHIFT_RIGHT_ON; |
| 1072 | |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 1073 | /** |
| 1074 | * This mask is a combination of {@link #META_ALT_ON}, {@link #META_ALT_LEFT_ON} |
| 1075 | * and {@link #META_ALT_RIGHT_ON}. |
| 1076 | */ |
Jeff Brown | c1df907 | 2010-12-21 16:38:50 -0800 | [diff] [blame] | 1077 | public static final int META_ALT_MASK = META_ALT_ON |
| 1078 | | META_ALT_LEFT_ON | META_ALT_RIGHT_ON; |
| 1079 | |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 1080 | /** |
| 1081 | * This mask is a combination of {@link #META_CTRL_ON}, {@link #META_CTRL_LEFT_ON} |
| 1082 | * and {@link #META_CTRL_RIGHT_ON}. |
| 1083 | */ |
Jeff Brown | c1df907 | 2010-12-21 16:38:50 -0800 | [diff] [blame] | 1084 | public static final int META_CTRL_MASK = META_CTRL_ON |
| 1085 | | META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON; |
| 1086 | |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 1087 | /** |
| 1088 | * This mask is a combination of {@link #META_META_ON}, {@link #META_META_LEFT_ON} |
| 1089 | * and {@link #META_META_RIGHT_ON}. |
| 1090 | */ |
| 1091 | public static final int META_META_MASK = META_META_ON |
Jeff Brown | c1df907 | 2010-12-21 16:38:50 -0800 | [diff] [blame] | 1092 | | META_META_LEFT_ON | META_META_RIGHT_ON; |
| 1093 | |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1094 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | * This mask is set if the device woke because of this key event. |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1096 | * |
| 1097 | * @deprecated This flag will never be set by the system since the system |
| 1098 | * consumes all wake keys itself. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1099 | */ |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1100 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | public static final int FLAG_WOKE_HERE = 0x1; |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | /** |
| 1104 | * This mask is set if the key event was generated by a software keyboard. |
| 1105 | */ |
| 1106 | public static final int FLAG_SOFT_KEYBOARD = 0x2; |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1107 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1108 | /** |
| 1109 | * This mask is set if we don't want the key event to cause us to leave |
| 1110 | * touch mode. |
| 1111 | */ |
| 1112 | public static final int FLAG_KEEP_TOUCH_MODE = 0x4; |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1114 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1115 | * This mask is set if an event was known to come from a trusted part |
| 1116 | * of the system. That is, the event is known to come from the user, |
| 1117 | * and could not have been spoofed by a third party component. |
| 1118 | */ |
| 1119 | public static final int FLAG_FROM_SYSTEM = 0x8; |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1120 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1121 | /** |
| 1122 | * This mask is used for compatibility, to identify enter keys that are |
| 1123 | * coming from an IME whose enter key has been auto-labelled "next" or |
| 1124 | * "done". This allows TextView to dispatch these as normal enter keys |
| 1125 | * for old applications, but still do the appropriate action when |
| 1126 | * receiving them. |
| 1127 | */ |
| 1128 | public static final int FLAG_EDITOR_ACTION = 0x10; |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1129 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1130 | /** |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 1131 | * When associated with up key events, this indicates that the key press |
| 1132 | * has been canceled. Typically this is used with virtual touch screen |
| 1133 | * keys, where the user can slide from the virtual key area on to the |
| 1134 | * display: in that case, the application will receive a canceled up |
| 1135 | * event and should not perform the action normally associated with the |
| 1136 | * key. Note that for this to work, the application can not perform an |
| 1137 | * action for a key until it receives an up or the long press timeout has |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1138 | * expired. |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 1139 | */ |
| 1140 | public static final int FLAG_CANCELED = 0x20; |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1141 | |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 1142 | /** |
| 1143 | * This key event was generated by a virtual (on-screen) hard key area. |
| 1144 | * Typically this is an area of the touchscreen, outside of the regular |
| 1145 | * display, dedicated to "hardware" buttons. |
| 1146 | */ |
| 1147 | public static final int FLAG_VIRTUAL_HARD_KEY = 0x40; |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1148 | |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 1149 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1150 | * This flag is set for the first key repeat that occurs after the |
| 1151 | * long press timeout. |
| 1152 | */ |
| 1153 | public static final int FLAG_LONG_PRESS = 0x80; |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1154 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1155 | /** |
| 1156 | * Set when a key event has {@link #FLAG_CANCELED} set because a long |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1157 | * press action was executed while it was down. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1158 | */ |
| 1159 | public static final int FLAG_CANCELED_LONG_PRESS = 0x100; |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1160 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1161 | /** |
| 1162 | * Set for {@link #ACTION_UP} when this event's key code is still being |
| 1163 | * tracked from its initial down. That is, somebody requested that tracking |
| 1164 | * started on the key down and a long press has not caused |
| 1165 | * the tracking to be canceled. |
| 1166 | */ |
| 1167 | public static final int FLAG_TRACKING = 0x200; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1168 | |
| 1169 | /** |
| 1170 | * Set when a key event has been synthesized to implement default behavior |
| 1171 | * for an event that the application did not handle. |
| 1172 | * Fallback key events are generated by unhandled trackball motions |
| 1173 | * (to emulate a directional keypad) and by certain unhandled key presses |
| 1174 | * that are declared in the key map (such as special function numeric keypad |
| 1175 | * keys when numlock is off). |
| 1176 | */ |
| 1177 | public static final int FLAG_FALLBACK = 0x400; |
| 1178 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1179 | /** |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 1180 | * Signifies that the key is being predispatched. |
| 1181 | * @hide |
| 1182 | */ |
| 1183 | public static final int FLAG_PREDISPATCH = 0x20000000; |
| 1184 | |
| 1185 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1186 | * Private control to determine when an app is tracking a key sequence. |
| 1187 | * @hide |
| 1188 | */ |
| 1189 | public static final int FLAG_START_TRACKING = 0x40000000; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 1190 | |
| 1191 | /** |
| 1192 | * Private flag that indicates when the system has detected that this key event |
| 1193 | * may be inconsistent with respect to the sequence of previously delivered key events, |
| 1194 | * such as when a key up event is sent but the key was not down. |
| 1195 | * |
| 1196 | * @hide |
| 1197 | * @see #isTainted |
| 1198 | * @see #setTainted |
| 1199 | */ |
| 1200 | public static final int FLAG_TAINTED = 0x80000000; |
| 1201 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1202 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1203 | * Returns the maximum keycode. |
| 1204 | */ |
| 1205 | public static int getMaxKeyCode() { |
| 1206 | return LAST_KEYCODE; |
| 1207 | } |
| 1208 | |
| 1209 | /** |
| 1210 | * Get the character that is produced by putting accent on the character |
| 1211 | * c. |
| 1212 | * For example, getDeadChar('`', 'e') returns è. |
| 1213 | */ |
| 1214 | public static int getDeadChar(int accent, int c) { |
| 1215 | return KeyCharacterMap.getDeadChar(accent, c); |
| 1216 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1217 | |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 1218 | static final boolean DEBUG = false; |
| 1219 | static final String TAG = "KeyEvent"; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1220 | |
| 1221 | private static final int MAX_RECYCLED = 10; |
| 1222 | private static final Object gRecyclerLock = new Object(); |
| 1223 | private static int gRecyclerUsed; |
| 1224 | private static KeyEvent gRecyclerTop; |
| 1225 | |
| 1226 | private KeyEvent mNext; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1227 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1228 | private int mDeviceId; |
| 1229 | private int mSource; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1230 | private int mMetaState; |
| 1231 | private int mAction; |
| 1232 | private int mKeyCode; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1233 | private int mScanCode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1234 | private int mRepeatCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | private int mFlags; |
| 1236 | private long mDownTime; |
| 1237 | private long mEventTime; |
| 1238 | private String mCharacters; |
| 1239 | |
| 1240 | public interface Callback { |
| 1241 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1242 | * Called when a key down event has occurred. If you return true, |
| 1243 | * you can first call {@link KeyEvent#startTracking() |
| 1244 | * KeyEvent.startTracking()} to have the framework track the event |
| 1245 | * through its {@link #onKeyUp(int, KeyEvent)} and also call your |
| 1246 | * {@link #onKeyLongPress(int, KeyEvent)} if it occurs. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1247 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1248 | * @param keyCode The value in event.getKeyCode(). |
| 1249 | * @param event Description of the key event. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1250 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1251 | * @return If you handled the event, return true. If you want to allow |
| 1252 | * the event to be handled by the next receiver, return false. |
| 1253 | */ |
| 1254 | boolean onKeyDown(int keyCode, KeyEvent event); |
| 1255 | |
| 1256 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1257 | * Called when a long press has occurred. If you return true, |
| 1258 | * the final key up will have {@link KeyEvent#FLAG_CANCELED} and |
| 1259 | * {@link KeyEvent#FLAG_CANCELED_LONG_PRESS} set. Note that in |
| 1260 | * order to receive this callback, someone in the event change |
| 1261 | * <em>must</em> return true from {@link #onKeyDown} <em>and</em> |
| 1262 | * call {@link KeyEvent#startTracking()} on the event. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1263 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1264 | * @param keyCode The value in event.getKeyCode(). |
| 1265 | * @param event Description of the key event. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1266 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1267 | * @return If you handled the event, return true. If you want to allow |
| 1268 | * the event to be handled by the next receiver, return false. |
| 1269 | */ |
| 1270 | boolean onKeyLongPress(int keyCode, KeyEvent event); |
| 1271 | |
| 1272 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1273 | * Called when a key up event has occurred. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1274 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1275 | * @param keyCode The value in event.getKeyCode(). |
| 1276 | * @param event Description of the key event. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1277 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1278 | * @return If you handled the event, return true. If you want to allow |
| 1279 | * the event to be handled by the next receiver, return false. |
| 1280 | */ |
| 1281 | boolean onKeyUp(int keyCode, KeyEvent event); |
| 1282 | |
| 1283 | /** |
Kevin Hufnagle | b248b1f | 2016-09-13 19:36:20 -0700 | [diff] [blame^] | 1284 | * Called when a user's interaction with an analog control, such as |
| 1285 | * flinging a trackball, generates simulated down/up events for the same |
| 1286 | * key multiple times in quick succession. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1287 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1288 | * @param keyCode The value in event.getKeyCode(). |
| 1289 | * @param count Number of pairs as returned by event.getRepeatCount(). |
| 1290 | * @param event Description of the key event. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1291 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1292 | * @return If you handled the event, return true. If you want to allow |
| 1293 | * the event to be handled by the next receiver, return false. |
| 1294 | */ |
| 1295 | boolean onKeyMultiple(int keyCode, int count, KeyEvent event); |
| 1296 | } |
| 1297 | |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 1298 | private static native String nativeKeyCodeToString(int keyCode); |
| 1299 | private static native int nativeKeyCodeFromString(String keyCode); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1300 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1301 | private KeyEvent() { |
| 1302 | } |
| 1303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1304 | /** |
| 1305 | * Create a new key event. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1306 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1307 | * @param action Action code: either {@link #ACTION_DOWN}, |
| 1308 | * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. |
| 1309 | * @param code The key code. |
| 1310 | */ |
| 1311 | public KeyEvent(int action, int code) { |
| 1312 | mAction = action; |
| 1313 | mKeyCode = code; |
| 1314 | mRepeatCount = 0; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 1315 | mDeviceId = KeyCharacterMap.VIRTUAL_KEYBOARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | /** |
| 1319 | * Create a new key event. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1320 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1322 | * at which this key code originally went down. |
| 1323 | * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1324 | * at which this event happened. |
| 1325 | * @param action Action code: either {@link #ACTION_DOWN}, |
| 1326 | * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. |
| 1327 | * @param code The key code. |
| 1328 | * @param repeat A repeat count for down events (> 0 if this is after the |
| 1329 | * initial down) or event count for multiple events. |
| 1330 | */ |
| 1331 | public KeyEvent(long downTime, long eventTime, int action, |
| 1332 | int code, int repeat) { |
| 1333 | mDownTime = downTime; |
| 1334 | mEventTime = eventTime; |
| 1335 | mAction = action; |
| 1336 | mKeyCode = code; |
| 1337 | mRepeatCount = repeat; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 1338 | mDeviceId = KeyCharacterMap.VIRTUAL_KEYBOARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | /** |
| 1342 | * Create a new key event. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1343 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1344 | * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1345 | * at which this key code originally went down. |
| 1346 | * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1347 | * at which this event happened. |
| 1348 | * @param action Action code: either {@link #ACTION_DOWN}, |
| 1349 | * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. |
| 1350 | * @param code The key code. |
| 1351 | * @param repeat A repeat count for down events (> 0 if this is after the |
| 1352 | * initial down) or event count for multiple events. |
| 1353 | * @param metaState Flags indicating which meta keys are currently pressed. |
| 1354 | */ |
| 1355 | public KeyEvent(long downTime, long eventTime, int action, |
| 1356 | int code, int repeat, int metaState) { |
| 1357 | mDownTime = downTime; |
| 1358 | mEventTime = eventTime; |
| 1359 | mAction = action; |
| 1360 | mKeyCode = code; |
| 1361 | mRepeatCount = repeat; |
| 1362 | mMetaState = metaState; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 1363 | mDeviceId = KeyCharacterMap.VIRTUAL_KEYBOARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | /** |
| 1367 | * Create a new key event. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1368 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1369 | * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1370 | * at which this key code originally went down. |
| 1371 | * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1372 | * at which this event happened. |
| 1373 | * @param action Action code: either {@link #ACTION_DOWN}, |
| 1374 | * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. |
| 1375 | * @param code The key code. |
| 1376 | * @param repeat A repeat count for down events (> 0 if this is after the |
| 1377 | * initial down) or event count for multiple events. |
| 1378 | * @param metaState Flags indicating which meta keys are currently pressed. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1379 | * @param deviceId The device ID that generated the key event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1380 | * @param scancode Raw device scan code of the event. |
| 1381 | */ |
| 1382 | public KeyEvent(long downTime, long eventTime, int action, |
| 1383 | int code, int repeat, int metaState, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1384 | int deviceId, int scancode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1385 | mDownTime = downTime; |
| 1386 | mEventTime = eventTime; |
| 1387 | mAction = action; |
| 1388 | mKeyCode = code; |
| 1389 | mRepeatCount = repeat; |
| 1390 | mMetaState = metaState; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1391 | mDeviceId = deviceId; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1392 | mScanCode = scancode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | /** |
| 1396 | * Create a new key event. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1397 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1399 | * at which this key code originally went down. |
| 1400 | * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1401 | * at which this event happened. |
| 1402 | * @param action Action code: either {@link #ACTION_DOWN}, |
| 1403 | * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. |
| 1404 | * @param code The key code. |
| 1405 | * @param repeat A repeat count for down events (> 0 if this is after the |
| 1406 | * initial down) or event count for multiple events. |
| 1407 | * @param metaState Flags indicating which meta keys are currently pressed. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1408 | * @param deviceId The device ID that generated the key event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1409 | * @param scancode Raw device scan code of the event. |
| 1410 | * @param flags The flags for this key event |
| 1411 | */ |
| 1412 | public KeyEvent(long downTime, long eventTime, int action, |
| 1413 | int code, int repeat, int metaState, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1414 | int deviceId, int scancode, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1415 | mDownTime = downTime; |
| 1416 | mEventTime = eventTime; |
| 1417 | mAction = action; |
| 1418 | mKeyCode = code; |
| 1419 | mRepeatCount = repeat; |
| 1420 | mMetaState = metaState; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1421 | mDeviceId = deviceId; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1422 | mScanCode = scancode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1423 | mFlags = flags; |
| 1424 | } |
| 1425 | |
| 1426 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1427 | * Create a new key event. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1428 | * |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1429 | * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1430 | * at which this key code originally went down. |
| 1431 | * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1432 | * at which this event happened. |
| 1433 | * @param action Action code: either {@link #ACTION_DOWN}, |
| 1434 | * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. |
| 1435 | * @param code The key code. |
| 1436 | * @param repeat A repeat count for down events (> 0 if this is after the |
| 1437 | * initial down) or event count for multiple events. |
| 1438 | * @param metaState Flags indicating which meta keys are currently pressed. |
| 1439 | * @param deviceId The device ID that generated the key event. |
| 1440 | * @param scancode Raw device scan code of the event. |
| 1441 | * @param flags The flags for this key event |
| 1442 | * @param source The input source such as {@link InputDevice#SOURCE_KEYBOARD}. |
| 1443 | */ |
| 1444 | public KeyEvent(long downTime, long eventTime, int action, |
| 1445 | int code, int repeat, int metaState, |
| 1446 | int deviceId, int scancode, int flags, int source) { |
| 1447 | mDownTime = downTime; |
| 1448 | mEventTime = eventTime; |
| 1449 | mAction = action; |
| 1450 | mKeyCode = code; |
| 1451 | mRepeatCount = repeat; |
| 1452 | mMetaState = metaState; |
| 1453 | mDeviceId = deviceId; |
| 1454 | mScanCode = scancode; |
| 1455 | mFlags = flags; |
| 1456 | mSource = source; |
| 1457 | } |
| 1458 | |
| 1459 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1460 | * Create a new key event for a string of characters. The key code, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1461 | * action, repeat count and source will automatically be set to |
| 1462 | * {@link #KEYCODE_UNKNOWN}, {@link #ACTION_MULTIPLE}, 0, and |
| 1463 | * {@link InputDevice#SOURCE_KEYBOARD} for you. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1464 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1465 | * @param time The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1466 | * at which this event occured. |
| 1467 | * @param characters The string of characters. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1468 | * @param deviceId The device ID that generated the key event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1469 | * @param flags The flags for this key event |
| 1470 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1471 | public KeyEvent(long time, String characters, int deviceId, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1472 | mDownTime = time; |
| 1473 | mEventTime = time; |
| 1474 | mCharacters = characters; |
| 1475 | mAction = ACTION_MULTIPLE; |
| 1476 | mKeyCode = KEYCODE_UNKNOWN; |
| 1477 | mRepeatCount = 0; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1478 | mDeviceId = deviceId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | mFlags = flags; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1480 | mSource = InputDevice.SOURCE_KEYBOARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1484 | * Make an exact copy of an existing key event. |
| 1485 | */ |
| 1486 | public KeyEvent(KeyEvent origEvent) { |
| 1487 | mDownTime = origEvent.mDownTime; |
| 1488 | mEventTime = origEvent.mEventTime; |
| 1489 | mAction = origEvent.mAction; |
| 1490 | mKeyCode = origEvent.mKeyCode; |
| 1491 | mRepeatCount = origEvent.mRepeatCount; |
| 1492 | mMetaState = origEvent.mMetaState; |
| 1493 | mDeviceId = origEvent.mDeviceId; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1494 | mSource = origEvent.mSource; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1495 | mScanCode = origEvent.mScanCode; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1496 | mFlags = origEvent.mFlags; |
| 1497 | mCharacters = origEvent.mCharacters; |
| 1498 | } |
| 1499 | |
| 1500 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1501 | * Copy an existing key event, modifying its time and repeat count. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1502 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1503 | * @deprecated Use {@link #changeTimeRepeat(KeyEvent, long, int)} |
| 1504 | * instead. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1505 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | * @param origEvent The existing event to be copied. |
| 1507 | * @param eventTime The new event time |
| 1508 | * (in {@link android.os.SystemClock#uptimeMillis}) of the event. |
| 1509 | * @param newRepeat The new repeat count of the event. |
| 1510 | */ |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1511 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1512 | public KeyEvent(KeyEvent origEvent, long eventTime, int newRepeat) { |
| 1513 | mDownTime = origEvent.mDownTime; |
| 1514 | mEventTime = eventTime; |
| 1515 | mAction = origEvent.mAction; |
| 1516 | mKeyCode = origEvent.mKeyCode; |
| 1517 | mRepeatCount = newRepeat; |
| 1518 | mMetaState = origEvent.mMetaState; |
| 1519 | mDeviceId = origEvent.mDeviceId; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1520 | mSource = origEvent.mSource; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1521 | mScanCode = origEvent.mScanCode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | mFlags = origEvent.mFlags; |
| 1523 | mCharacters = origEvent.mCharacters; |
| 1524 | } |
| 1525 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1526 | private static KeyEvent obtain() { |
| 1527 | final KeyEvent ev; |
| 1528 | synchronized (gRecyclerLock) { |
| 1529 | ev = gRecyclerTop; |
| 1530 | if (ev == null) { |
| 1531 | return new KeyEvent(); |
| 1532 | } |
| 1533 | gRecyclerTop = ev.mNext; |
| 1534 | gRecyclerUsed -= 1; |
| 1535 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1536 | ev.mNext = null; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 1537 | ev.prepareForReuse(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1538 | return ev; |
| 1539 | } |
| 1540 | |
| 1541 | /** |
| 1542 | * Obtains a (potentially recycled) key event. |
| 1543 | * |
| 1544 | * @hide |
| 1545 | */ |
| 1546 | public static KeyEvent obtain(long downTime, long eventTime, int action, |
| 1547 | int code, int repeat, int metaState, |
| 1548 | int deviceId, int scancode, int flags, int source, String characters) { |
| 1549 | KeyEvent ev = obtain(); |
| 1550 | ev.mDownTime = downTime; |
| 1551 | ev.mEventTime = eventTime; |
| 1552 | ev.mAction = action; |
| 1553 | ev.mKeyCode = code; |
| 1554 | ev.mRepeatCount = repeat; |
| 1555 | ev.mMetaState = metaState; |
| 1556 | ev.mDeviceId = deviceId; |
| 1557 | ev.mScanCode = scancode; |
| 1558 | ev.mFlags = flags; |
| 1559 | ev.mSource = source; |
| 1560 | ev.mCharacters = characters; |
| 1561 | return ev; |
| 1562 | } |
| 1563 | |
| 1564 | /** |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 1565 | * Obtains a (potentially recycled) copy of another key event. |
| 1566 | * |
| 1567 | * @hide |
| 1568 | */ |
| 1569 | public static KeyEvent obtain(KeyEvent other) { |
| 1570 | KeyEvent ev = obtain(); |
| 1571 | ev.mDownTime = other.mDownTime; |
| 1572 | ev.mEventTime = other.mEventTime; |
| 1573 | ev.mAction = other.mAction; |
| 1574 | ev.mKeyCode = other.mKeyCode; |
| 1575 | ev.mRepeatCount = other.mRepeatCount; |
| 1576 | ev.mMetaState = other.mMetaState; |
| 1577 | ev.mDeviceId = other.mDeviceId; |
| 1578 | ev.mScanCode = other.mScanCode; |
| 1579 | ev.mFlags = other.mFlags; |
| 1580 | ev.mSource = other.mSource; |
| 1581 | ev.mCharacters = other.mCharacters; |
| 1582 | return ev; |
| 1583 | } |
| 1584 | |
| 1585 | /** @hide */ |
| 1586 | @Override |
| 1587 | public KeyEvent copy() { |
| 1588 | return obtain(this); |
| 1589 | } |
| 1590 | |
| 1591 | /** |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1592 | * Recycles a key event. |
| 1593 | * Key events should only be recycled if they are owned by the system since user |
| 1594 | * code expects them to be essentially immutable, "tracking" notwithstanding. |
| 1595 | * |
| 1596 | * @hide |
| 1597 | */ |
Jeff Brown | 92cc2d8 | 2011-12-02 01:19:47 -0800 | [diff] [blame] | 1598 | @Override |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1599 | public final void recycle() { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 1600 | super.recycle(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1601 | mCharacters = null; |
| 1602 | |
| 1603 | synchronized (gRecyclerLock) { |
| 1604 | if (gRecyclerUsed < MAX_RECYCLED) { |
| 1605 | gRecyclerUsed++; |
| 1606 | mNext = gRecyclerTop; |
| 1607 | gRecyclerTop = this; |
| 1608 | } |
| 1609 | } |
| 1610 | } |
| 1611 | |
Jeff Brown | 92cc2d8 | 2011-12-02 01:19:47 -0800 | [diff] [blame] | 1612 | /** @hide */ |
| 1613 | @Override |
| 1614 | public final void recycleIfNeededAfterDispatch() { |
| 1615 | // Do nothing. |
| 1616 | } |
| 1617 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1618 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1619 | * Create a new key event that is the same as the given one, but whose |
| 1620 | * event time and repeat count are replaced with the given value. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1621 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1622 | * @param event The existing event to be copied. This is not modified. |
| 1623 | * @param eventTime The new event time |
| 1624 | * (in {@link android.os.SystemClock#uptimeMillis}) of the event. |
| 1625 | * @param newRepeat The new repeat count of the event. |
| 1626 | */ |
| 1627 | public static KeyEvent changeTimeRepeat(KeyEvent event, long eventTime, |
| 1628 | int newRepeat) { |
| 1629 | return new KeyEvent(event, eventTime, newRepeat); |
| 1630 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1631 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1632 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1633 | * Create a new key event that is the same as the given one, but whose |
| 1634 | * event time and repeat count are replaced with the given value. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1635 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1636 | * @param event The existing event to be copied. This is not modified. |
| 1637 | * @param eventTime The new event time |
| 1638 | * (in {@link android.os.SystemClock#uptimeMillis}) of the event. |
| 1639 | * @param newRepeat The new repeat count of the event. |
| 1640 | * @param newFlags New flags for the event, replacing the entire value |
| 1641 | * in the original event. |
| 1642 | */ |
| 1643 | public static KeyEvent changeTimeRepeat(KeyEvent event, long eventTime, |
| 1644 | int newRepeat, int newFlags) { |
| 1645 | KeyEvent ret = new KeyEvent(event); |
| 1646 | ret.mEventTime = eventTime; |
| 1647 | ret.mRepeatCount = newRepeat; |
| 1648 | ret.mFlags = newFlags; |
| 1649 | return ret; |
| 1650 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1651 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1652 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1653 | * Copy an existing key event, modifying its action. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1654 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1655 | * @param origEvent The existing event to be copied. |
| 1656 | * @param action The new action code of the event. |
| 1657 | */ |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1658 | private KeyEvent(KeyEvent origEvent, int action) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1659 | mDownTime = origEvent.mDownTime; |
| 1660 | mEventTime = origEvent.mEventTime; |
| 1661 | mAction = action; |
| 1662 | mKeyCode = origEvent.mKeyCode; |
| 1663 | mRepeatCount = origEvent.mRepeatCount; |
| 1664 | mMetaState = origEvent.mMetaState; |
| 1665 | mDeviceId = origEvent.mDeviceId; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1666 | mSource = origEvent.mSource; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1667 | mScanCode = origEvent.mScanCode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1668 | mFlags = origEvent.mFlags; |
| 1669 | // Don't copy mCharacters, since one way or the other we'll lose it |
| 1670 | // when changing the action. |
| 1671 | } |
| 1672 | |
| 1673 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1674 | * Create a new key event that is the same as the given one, but whose |
| 1675 | * action is replaced with the given value. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1676 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1677 | * @param event The existing event to be copied. This is not modified. |
| 1678 | * @param action The new action code of the event. |
| 1679 | */ |
| 1680 | public static KeyEvent changeAction(KeyEvent event, int action) { |
| 1681 | return new KeyEvent(event, action); |
| 1682 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1683 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1684 | /** |
| 1685 | * Create a new key event that is the same as the given one, but whose |
| 1686 | * flags are replaced with the given value. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1687 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1688 | * @param event The existing event to be copied. This is not modified. |
| 1689 | * @param flags The new flags constant. |
| 1690 | */ |
| 1691 | public static KeyEvent changeFlags(KeyEvent event, int flags) { |
| 1692 | event = new KeyEvent(event); |
| 1693 | event.mFlags = flags; |
| 1694 | return event; |
| 1695 | } |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 1696 | |
| 1697 | /** @hide */ |
| 1698 | @Override |
| 1699 | public final boolean isTainted() { |
| 1700 | return (mFlags & FLAG_TAINTED) != 0; |
| 1701 | } |
| 1702 | |
| 1703 | /** @hide */ |
| 1704 | @Override |
| 1705 | public final void setTainted(boolean tainted) { |
| 1706 | mFlags = tainted ? mFlags | FLAG_TAINTED : mFlags & ~FLAG_TAINTED; |
| 1707 | } |
| 1708 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1709 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1710 | * Don't use in new code, instead explicitly check |
| 1711 | * {@link #getAction()}. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1712 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1713 | * @return If the action is ACTION_DOWN, returns true; else false. |
| 1714 | * |
| 1715 | * @deprecated |
| 1716 | * @hide |
| 1717 | */ |
| 1718 | @Deprecated public final boolean isDown() { |
| 1719 | return mAction == ACTION_DOWN; |
| 1720 | } |
| 1721 | |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 1722 | /** Is this a system key? System keys can not be used for menu shortcuts. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | */ |
| 1724 | public final boolean isSystem() { |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 1725 | return isSystemKey(mKeyCode); |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | /** @hide */ |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 1729 | public final boolean isWakeKey() { |
| 1730 | return isWakeKey(mKeyCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1731 | } |
| 1732 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1733 | /** |
| 1734 | * Returns true if the specified keycode is a gamepad button. |
| 1735 | * @return True if the keycode is a gamepad button, such as {@link #KEYCODE_BUTTON_A}. |
| 1736 | */ |
| 1737 | public static final boolean isGamepadButton(int keyCode) { |
| 1738 | switch (keyCode) { |
| 1739 | case KeyEvent.KEYCODE_BUTTON_A: |
| 1740 | case KeyEvent.KEYCODE_BUTTON_B: |
| 1741 | case KeyEvent.KEYCODE_BUTTON_C: |
| 1742 | case KeyEvent.KEYCODE_BUTTON_X: |
| 1743 | case KeyEvent.KEYCODE_BUTTON_Y: |
| 1744 | case KeyEvent.KEYCODE_BUTTON_Z: |
| 1745 | case KeyEvent.KEYCODE_BUTTON_L1: |
| 1746 | case KeyEvent.KEYCODE_BUTTON_R1: |
| 1747 | case KeyEvent.KEYCODE_BUTTON_L2: |
| 1748 | case KeyEvent.KEYCODE_BUTTON_R2: |
| 1749 | case KeyEvent.KEYCODE_BUTTON_THUMBL: |
| 1750 | case KeyEvent.KEYCODE_BUTTON_THUMBR: |
| 1751 | case KeyEvent.KEYCODE_BUTTON_START: |
| 1752 | case KeyEvent.KEYCODE_BUTTON_SELECT: |
| 1753 | case KeyEvent.KEYCODE_BUTTON_MODE: |
| 1754 | case KeyEvent.KEYCODE_BUTTON_1: |
| 1755 | case KeyEvent.KEYCODE_BUTTON_2: |
| 1756 | case KeyEvent.KEYCODE_BUTTON_3: |
| 1757 | case KeyEvent.KEYCODE_BUTTON_4: |
| 1758 | case KeyEvent.KEYCODE_BUTTON_5: |
| 1759 | case KeyEvent.KEYCODE_BUTTON_6: |
| 1760 | case KeyEvent.KEYCODE_BUTTON_7: |
| 1761 | case KeyEvent.KEYCODE_BUTTON_8: |
| 1762 | case KeyEvent.KEYCODE_BUTTON_9: |
| 1763 | case KeyEvent.KEYCODE_BUTTON_10: |
| 1764 | case KeyEvent.KEYCODE_BUTTON_11: |
| 1765 | case KeyEvent.KEYCODE_BUTTON_12: |
| 1766 | case KeyEvent.KEYCODE_BUTTON_13: |
| 1767 | case KeyEvent.KEYCODE_BUTTON_14: |
| 1768 | case KeyEvent.KEYCODE_BUTTON_15: |
| 1769 | case KeyEvent.KEYCODE_BUTTON_16: |
| 1770 | return true; |
| 1771 | default: |
| 1772 | return false; |
| 1773 | } |
| 1774 | } |
| 1775 | |
Michael Wright | 25b0c30 | 2013-07-10 12:54:06 -0700 | [diff] [blame] | 1776 | /** Whether key will, by default, trigger a click on the focused view. |
| 1777 | * @hide |
| 1778 | */ |
| 1779 | public static final boolean isConfirmKey(int keyCode) { |
| 1780 | switch (keyCode) { |
| 1781 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 1782 | case KeyEvent.KEYCODE_ENTER: |
Michael Wright | aa1a94d | 2015-11-26 16:04:54 +0000 | [diff] [blame] | 1783 | case KeyEvent.KEYCODE_SPACE: |
Selim Cinek | ce2bd0f | 2016-02-19 16:16:54 -0800 | [diff] [blame] | 1784 | case KeyEvent.KEYCODE_NUMPAD_ENTER: |
Michael Wright | 25b0c30 | 2013-07-10 12:54:06 -0700 | [diff] [blame] | 1785 | return true; |
| 1786 | default: |
| 1787 | return false; |
| 1788 | } |
| 1789 | } |
| 1790 | |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 1791 | /** |
| 1792 | * Whether this key is a media key, which can be send to apps that are |
| 1793 | * interested in media key events. |
| 1794 | * |
| 1795 | * @hide |
| 1796 | */ |
| 1797 | public static final boolean isMediaKey(int keyCode) { |
| 1798 | switch (keyCode) { |
| 1799 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 1800 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 1801 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 1802 | case KeyEvent.KEYCODE_MUTE: |
| 1803 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 1804 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 1805 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 1806 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 1807 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 1808 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 1809 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 1810 | return true; |
| 1811 | } |
| 1812 | return false; |
| 1813 | } |
| 1814 | |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 1815 | |
| 1816 | /** Is this a system key? System keys can not be used for menu shortcuts. |
| 1817 | * @hide |
| 1818 | */ |
| 1819 | public static final boolean isSystemKey(int keyCode) { |
| 1820 | switch (keyCode) { |
| 1821 | case KeyEvent.KEYCODE_MENU: |
| 1822 | case KeyEvent.KEYCODE_SOFT_RIGHT: |
| 1823 | case KeyEvent.KEYCODE_HOME: |
| 1824 | case KeyEvent.KEYCODE_BACK: |
| 1825 | case KeyEvent.KEYCODE_CALL: |
| 1826 | case KeyEvent.KEYCODE_ENDCALL: |
| 1827 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 1828 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 1829 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 1830 | case KeyEvent.KEYCODE_MUTE: |
| 1831 | case KeyEvent.KEYCODE_POWER: |
| 1832 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 1833 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 1834 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 1835 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 1836 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 1837 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 1838 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 1839 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 1840 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 1841 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 1842 | case KeyEvent.KEYCODE_CAMERA: |
| 1843 | case KeyEvent.KEYCODE_FOCUS: |
| 1844 | case KeyEvent.KEYCODE_SEARCH: |
| 1845 | case KeyEvent.KEYCODE_BRIGHTNESS_DOWN: |
| 1846 | case KeyEvent.KEYCODE_BRIGHTNESS_UP: |
| 1847 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 1848 | return true; |
| 1849 | } |
| 1850 | |
| 1851 | return false; |
| 1852 | } |
| 1853 | |
| 1854 | /** @hide */ |
| 1855 | public static final boolean isWakeKey(int keyCode) { |
| 1856 | switch (keyCode) { |
| 1857 | case KeyEvent.KEYCODE_BACK: |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 1858 | case KeyEvent.KEYCODE_MENU: |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 1859 | case KeyEvent.KEYCODE_WAKEUP: |
Michael Wright | 8ac485a | 2014-06-04 12:38:18 -0700 | [diff] [blame] | 1860 | case KeyEvent.KEYCODE_PAIRING: |
Chenjie Luo | bad498f | 2016-01-13 11:01:59 -0800 | [diff] [blame] | 1861 | case KeyEvent.KEYCODE_STEM_1: |
| 1862 | case KeyEvent.KEYCODE_STEM_2: |
| 1863 | case KeyEvent.KEYCODE_STEM_3: |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 1864 | return true; |
| 1865 | } |
| 1866 | return false; |
| 1867 | } |
| 1868 | |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 1869 | /** @hide */ |
| 1870 | public static final boolean isMetaKey(int keyCode) { |
| 1871 | return keyCode == KeyEvent.KEYCODE_META_LEFT || keyCode == KeyEvent.KEYCODE_META_RIGHT; |
| 1872 | } |
| 1873 | |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 1874 | /** @hide */ |
| 1875 | public static final boolean isAltKey(int keyCode) { |
| 1876 | return keyCode == KeyEvent.KEYCODE_ALT_LEFT || keyCode == KeyEvent.KEYCODE_ALT_RIGHT; |
| 1877 | } |
| 1878 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1879 | /** {@inheritDoc} */ |
| 1880 | @Override |
| 1881 | public final int getDeviceId() { |
| 1882 | return mDeviceId; |
| 1883 | } |
| 1884 | |
| 1885 | /** {@inheritDoc} */ |
| 1886 | @Override |
| 1887 | public final int getSource() { |
| 1888 | return mSource; |
| 1889 | } |
| 1890 | |
| 1891 | /** {@inheritDoc} */ |
| 1892 | @Override |
| 1893 | public final void setSource(int source) { |
| 1894 | mSource = source; |
| 1895 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1896 | |
| 1897 | /** |
| 1898 | * <p>Returns the state of the meta keys.</p> |
| 1899 | * |
| 1900 | * @return an integer in which each bit set to 1 represents a pressed |
| 1901 | * meta key |
| 1902 | * |
| 1903 | * @see #isAltPressed() |
| 1904 | * @see #isShiftPressed() |
| 1905 | * @see #isSymPressed() |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1906 | * @see #isCtrlPressed() |
| 1907 | * @see #isMetaPressed() |
| 1908 | * @see #isFunctionPressed() |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1909 | * @see #isCapsLockOn() |
| 1910 | * @see #isNumLockOn() |
| 1911 | * @see #isScrollLockOn() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1912 | * @see #META_ALT_ON |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1913 | * @see #META_ALT_LEFT_ON |
| 1914 | * @see #META_ALT_RIGHT_ON |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1915 | * @see #META_SHIFT_ON |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1916 | * @see #META_SHIFT_LEFT_ON |
| 1917 | * @see #META_SHIFT_RIGHT_ON |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1918 | * @see #META_SYM_ON |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1919 | * @see #META_FUNCTION_ON |
| 1920 | * @see #META_CTRL_ON |
| 1921 | * @see #META_CTRL_LEFT_ON |
| 1922 | * @see #META_CTRL_RIGHT_ON |
| 1923 | * @see #META_META_ON |
| 1924 | * @see #META_META_LEFT_ON |
| 1925 | * @see #META_META_RIGHT_ON |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1926 | * @see #META_CAPS_LOCK_ON |
| 1927 | * @see #META_NUM_LOCK_ON |
| 1928 | * @see #META_SCROLL_LOCK_ON |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 1929 | * @see #getModifiers |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1930 | */ |
| 1931 | public final int getMetaState() { |
| 1932 | return mMetaState; |
| 1933 | } |
| 1934 | |
| 1935 | /** |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 1936 | * Returns the state of the modifier keys. |
| 1937 | * <p> |
| 1938 | * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, |
| 1939 | * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are |
| 1940 | * not considered modifier keys. Consequently, this function specifically masks out |
| 1941 | * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. |
| 1942 | * </p><p> |
| 1943 | * The value returned consists of the meta state (from {@link #getMetaState}) |
| 1944 | * normalized using {@link #normalizeMetaState(int)} and then masked with |
| 1945 | * {@link #getModifierMetaStateMask} so that only valid modifier bits are retained. |
| 1946 | * </p> |
| 1947 | * |
| 1948 | * @return An integer in which each bit set to 1 represents a pressed modifier key. |
| 1949 | * @see #getMetaState |
| 1950 | */ |
| 1951 | public final int getModifiers() { |
| 1952 | return normalizeMetaState(mMetaState) & META_MODIFIER_MASK; |
| 1953 | } |
| 1954 | |
| 1955 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1956 | * Returns the flags for this key event. |
| 1957 | * |
| 1958 | * @see #FLAG_WOKE_HERE |
| 1959 | */ |
| 1960 | public final int getFlags() { |
| 1961 | return mFlags; |
| 1962 | } |
| 1963 | |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 1964 | // Mask of all modifier key meta states. Specifically excludes locked keys like caps lock. |
| 1965 | private static final int META_MODIFIER_MASK = |
| 1966 | META_SHIFT_ON | META_SHIFT_LEFT_ON | META_SHIFT_RIGHT_ON |
| 1967 | | META_ALT_ON | META_ALT_LEFT_ON | META_ALT_RIGHT_ON |
| 1968 | | META_CTRL_ON | META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON |
| 1969 | | META_META_ON | META_META_LEFT_ON | META_META_RIGHT_ON |
| 1970 | | META_SYM_ON | META_FUNCTION_ON; |
| 1971 | |
| 1972 | // Mask of all lock key meta states. |
| 1973 | private static final int META_LOCK_MASK = |
| 1974 | META_CAPS_LOCK_ON | META_NUM_LOCK_ON | META_SCROLL_LOCK_ON; |
| 1975 | |
| 1976 | // Mask of all valid meta states. |
| 1977 | private static final int META_ALL_MASK = META_MODIFIER_MASK | META_LOCK_MASK; |
| 1978 | |
| 1979 | // Mask of all synthetic meta states that are reserved for API compatibility with |
| 1980 | // historical uses in MetaKeyKeyListener. |
| 1981 | private static final int META_SYNTHETIC_MASK = |
| 1982 | META_CAP_LOCKED | META_ALT_LOCKED | META_SYM_LOCKED | META_SELECTING; |
| 1983 | |
| 1984 | // Mask of all meta states that are not valid use in specifying a modifier key. |
| 1985 | // These bits are known to be used for purposes other than specifying modifiers. |
| 1986 | private static final int META_INVALID_MODIFIER_MASK = |
| 1987 | META_LOCK_MASK | META_SYNTHETIC_MASK; |
| 1988 | |
| 1989 | /** |
| 1990 | * Gets a mask that includes all valid modifier key meta state bits. |
| 1991 | * <p> |
| 1992 | * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, |
| 1993 | * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are |
| 1994 | * not considered modifier keys. Consequently, the mask specifically excludes |
| 1995 | * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. |
| 1996 | * </p> |
| 1997 | * |
| 1998 | * @return The modifier meta state mask which is a combination of |
| 1999 | * {@link #META_SHIFT_ON}, {@link #META_SHIFT_LEFT_ON}, {@link #META_SHIFT_RIGHT_ON}, |
| 2000 | * {@link #META_ALT_ON}, {@link #META_ALT_LEFT_ON}, {@link #META_ALT_RIGHT_ON}, |
| 2001 | * {@link #META_CTRL_ON}, {@link #META_CTRL_LEFT_ON}, {@link #META_CTRL_RIGHT_ON}, |
| 2002 | * {@link #META_META_ON}, {@link #META_META_LEFT_ON}, {@link #META_META_RIGHT_ON}, |
| 2003 | * {@link #META_SYM_ON}, {@link #META_FUNCTION_ON}. |
| 2004 | */ |
| 2005 | public static int getModifierMetaStateMask() { |
| 2006 | return META_MODIFIER_MASK; |
| 2007 | } |
| 2008 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2009 | /** |
| 2010 | * Returns true if this key code is a modifier key. |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 2011 | * <p> |
| 2012 | * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, |
| 2013 | * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are |
| 2014 | * not considered modifier keys. Consequently, this function return false |
| 2015 | * for those keys. |
| 2016 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2017 | * |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 2018 | * @return True if the key code is one of |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2019 | * {@link #KEYCODE_SHIFT_LEFT} {@link #KEYCODE_SHIFT_RIGHT}, |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2020 | * {@link #KEYCODE_ALT_LEFT}, {@link #KEYCODE_ALT_RIGHT}, |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2021 | * {@link #KEYCODE_CTRL_LEFT}, {@link #KEYCODE_CTRL_RIGHT}, |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 2022 | * {@link #KEYCODE_META_LEFT}, or {@link #KEYCODE_META_RIGHT}, |
| 2023 | * {@link #KEYCODE_SYM}, {@link #KEYCODE_NUM}, {@link #KEYCODE_FUNCTION}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2024 | */ |
| 2025 | public static boolean isModifierKey(int keyCode) { |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2026 | switch (keyCode) { |
| 2027 | case KEYCODE_SHIFT_LEFT: |
| 2028 | case KEYCODE_SHIFT_RIGHT: |
| 2029 | case KEYCODE_ALT_LEFT: |
| 2030 | case KEYCODE_ALT_RIGHT: |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2031 | case KEYCODE_CTRL_LEFT: |
| 2032 | case KEYCODE_CTRL_RIGHT: |
| 2033 | case KEYCODE_META_LEFT: |
| 2034 | case KEYCODE_META_RIGHT: |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 2035 | case KEYCODE_SYM: |
| 2036 | case KEYCODE_NUM: |
| 2037 | case KEYCODE_FUNCTION: |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2038 | return true; |
| 2039 | default: |
| 2040 | return false; |
| 2041 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | /** |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 2045 | * Normalizes the specified meta state. |
| 2046 | * <p> |
| 2047 | * The meta state is normalized such that if either the left or right modifier meta state |
| 2048 | * bits are set then the result will also include the universal bit for that modifier. |
| 2049 | * </p><p> |
| 2050 | * If the specified meta state contains {@link #META_ALT_LEFT_ON} then |
| 2051 | * the result will also contain {@link #META_ALT_ON} in addition to {@link #META_ALT_LEFT_ON} |
| 2052 | * and the other bits that were specified in the input. The same is process is |
| 2053 | * performed for shift, control and meta. |
| 2054 | * </p><p> |
| 2055 | * If the specified meta state contains synthetic meta states defined by |
| 2056 | * {@link MetaKeyKeyListener}, then those states are translated here and the original |
| 2057 | * synthetic meta states are removed from the result. |
| 2058 | * {@link MetaKeyKeyListener#META_CAP_LOCKED} is translated to {@link #META_CAPS_LOCK_ON}. |
| 2059 | * {@link MetaKeyKeyListener#META_ALT_LOCKED} is translated to {@link #META_ALT_ON}. |
| 2060 | * {@link MetaKeyKeyListener#META_SYM_LOCKED} is translated to {@link #META_SYM_ON}. |
| 2061 | * </p><p> |
| 2062 | * Undefined meta state bits are removed. |
| 2063 | * </p> |
| 2064 | * |
| 2065 | * @param metaState The meta state. |
| 2066 | * @return The normalized meta state. |
| 2067 | */ |
| 2068 | public static int normalizeMetaState(int metaState) { |
| 2069 | if ((metaState & (META_SHIFT_LEFT_ON | META_SHIFT_RIGHT_ON)) != 0) { |
| 2070 | metaState |= META_SHIFT_ON; |
| 2071 | } |
| 2072 | if ((metaState & (META_ALT_LEFT_ON | META_ALT_RIGHT_ON)) != 0) { |
| 2073 | metaState |= META_ALT_ON; |
| 2074 | } |
| 2075 | if ((metaState & (META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON)) != 0) { |
| 2076 | metaState |= META_CTRL_ON; |
| 2077 | } |
| 2078 | if ((metaState & (META_META_LEFT_ON | META_META_RIGHT_ON)) != 0) { |
| 2079 | metaState |= META_META_ON; |
| 2080 | } |
| 2081 | if ((metaState & MetaKeyKeyListener.META_CAP_LOCKED) != 0) { |
| 2082 | metaState |= META_CAPS_LOCK_ON; |
| 2083 | } |
| 2084 | if ((metaState & MetaKeyKeyListener.META_ALT_LOCKED) != 0) { |
| 2085 | metaState |= META_ALT_ON; |
| 2086 | } |
| 2087 | if ((metaState & MetaKeyKeyListener.META_SYM_LOCKED) != 0) { |
| 2088 | metaState |= META_SYM_ON; |
| 2089 | } |
| 2090 | return metaState & META_ALL_MASK; |
| 2091 | } |
| 2092 | |
| 2093 | /** |
| 2094 | * Returns true if no modifiers keys are pressed according to the specified meta state. |
| 2095 | * <p> |
| 2096 | * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, |
| 2097 | * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are |
| 2098 | * not considered modifier keys. Consequently, this function ignores |
| 2099 | * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. |
| 2100 | * </p><p> |
| 2101 | * The meta state is normalized prior to comparison using {@link #normalizeMetaState(int)}. |
| 2102 | * </p> |
| 2103 | * |
| 2104 | * @param metaState The meta state to consider. |
| 2105 | * @return True if no modifier keys are pressed. |
| 2106 | * @see #hasNoModifiers() |
| 2107 | */ |
| 2108 | public static boolean metaStateHasNoModifiers(int metaState) { |
| 2109 | return (normalizeMetaState(metaState) & META_MODIFIER_MASK) == 0; |
| 2110 | } |
| 2111 | |
| 2112 | /** |
| 2113 | * Returns true if only the specified modifier keys are pressed according to |
| 2114 | * the specified meta state. Returns false if a different combination of modifier |
| 2115 | * keys are pressed. |
| 2116 | * <p> |
| 2117 | * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, |
| 2118 | * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are |
| 2119 | * not considered modifier keys. Consequently, this function ignores |
| 2120 | * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. |
| 2121 | * </p><p> |
| 2122 | * If the specified modifier mask includes directional modifiers, such as |
| 2123 | * {@link #META_SHIFT_LEFT_ON}, then this method ensures that the |
| 2124 | * modifier is pressed on that side. |
| 2125 | * If the specified modifier mask includes non-directional modifiers, such as |
| 2126 | * {@link #META_SHIFT_ON}, then this method ensures that the modifier |
| 2127 | * is pressed on either side. |
| 2128 | * If the specified modifier mask includes both directional and non-directional modifiers |
| 2129 | * for the same type of key, such as {@link #META_SHIFT_ON} and {@link #META_SHIFT_LEFT_ON}, |
| 2130 | * then this method throws an illegal argument exception. |
| 2131 | * </p> |
| 2132 | * |
| 2133 | * @param metaState The meta state to consider. |
| 2134 | * @param modifiers The meta state of the modifier keys to check. May be a combination |
| 2135 | * of modifier meta states as defined by {@link #getModifierMetaStateMask()}. May be 0 to |
| 2136 | * ensure that no modifier keys are pressed. |
| 2137 | * @return True if only the specified modifier keys are pressed. |
| 2138 | * @throws IllegalArgumentException if the modifiers parameter contains invalid modifiers |
| 2139 | * @see #hasModifiers |
| 2140 | */ |
| 2141 | public static boolean metaStateHasModifiers(int metaState, int modifiers) { |
| 2142 | // Note: For forward compatibility, we allow the parameter to contain meta states |
| 2143 | // that we do not recognize but we explicitly disallow meta states that |
| 2144 | // are not valid modifiers. |
| 2145 | if ((modifiers & META_INVALID_MODIFIER_MASK) != 0) { |
| 2146 | throw new IllegalArgumentException("modifiers must not contain " |
| 2147 | + "META_CAPS_LOCK_ON, META_NUM_LOCK_ON, META_SCROLL_LOCK_ON, " |
| 2148 | + "META_CAP_LOCKED, META_ALT_LOCKED, META_SYM_LOCKED, " |
| 2149 | + "or META_SELECTING"); |
| 2150 | } |
| 2151 | |
| 2152 | metaState = normalizeMetaState(metaState) & META_MODIFIER_MASK; |
| 2153 | metaState = metaStateFilterDirectionalModifiers(metaState, modifiers, |
| 2154 | META_SHIFT_ON, META_SHIFT_LEFT_ON, META_SHIFT_RIGHT_ON); |
| 2155 | metaState = metaStateFilterDirectionalModifiers(metaState, modifiers, |
| 2156 | META_ALT_ON, META_ALT_LEFT_ON, META_ALT_RIGHT_ON); |
| 2157 | metaState = metaStateFilterDirectionalModifiers(metaState, modifiers, |
| 2158 | META_CTRL_ON, META_CTRL_LEFT_ON, META_CTRL_RIGHT_ON); |
| 2159 | metaState = metaStateFilterDirectionalModifiers(metaState, modifiers, |
| 2160 | META_META_ON, META_META_LEFT_ON, META_META_RIGHT_ON); |
| 2161 | return metaState == modifiers; |
| 2162 | } |
| 2163 | |
| 2164 | private static int metaStateFilterDirectionalModifiers(int metaState, |
| 2165 | int modifiers, int basic, int left, int right) { |
| 2166 | final boolean wantBasic = (modifiers & basic) != 0; |
| 2167 | final int directional = left | right; |
| 2168 | final boolean wantLeftOrRight = (modifiers & directional) != 0; |
| 2169 | |
| 2170 | if (wantBasic) { |
| 2171 | if (wantLeftOrRight) { |
| 2172 | throw new IllegalArgumentException("modifiers must not contain " |
| 2173 | + metaStateToString(basic) + " combined with " |
| 2174 | + metaStateToString(left) + " or " + metaStateToString(right)); |
| 2175 | } |
| 2176 | return metaState & ~directional; |
| 2177 | } else if (wantLeftOrRight) { |
| 2178 | return metaState & ~basic; |
| 2179 | } else { |
| 2180 | return metaState; |
| 2181 | } |
| 2182 | } |
| 2183 | |
| 2184 | /** |
| 2185 | * Returns true if no modifier keys are pressed. |
| 2186 | * <p> |
| 2187 | * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, |
| 2188 | * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are |
| 2189 | * not considered modifier keys. Consequently, this function ignores |
| 2190 | * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. |
| 2191 | * </p><p> |
| 2192 | * The meta state is normalized prior to comparison using {@link #normalizeMetaState(int)}. |
| 2193 | * </p> |
| 2194 | * |
| 2195 | * @return True if no modifier keys are pressed. |
| 2196 | * @see #metaStateHasNoModifiers |
| 2197 | */ |
| 2198 | public final boolean hasNoModifiers() { |
| 2199 | return metaStateHasNoModifiers(mMetaState); |
| 2200 | } |
| 2201 | |
| 2202 | /** |
| 2203 | * Returns true if only the specified modifiers keys are pressed. |
| 2204 | * Returns false if a different combination of modifier keys are pressed. |
| 2205 | * <p> |
| 2206 | * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, |
| 2207 | * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are |
| 2208 | * not considered modifier keys. Consequently, this function ignores |
| 2209 | * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. |
| 2210 | * </p><p> |
| 2211 | * If the specified modifier mask includes directional modifiers, such as |
| 2212 | * {@link #META_SHIFT_LEFT_ON}, then this method ensures that the |
| 2213 | * modifier is pressed on that side. |
| 2214 | * If the specified modifier mask includes non-directional modifiers, such as |
| 2215 | * {@link #META_SHIFT_ON}, then this method ensures that the modifier |
| 2216 | * is pressed on either side. |
| 2217 | * If the specified modifier mask includes both directional and non-directional modifiers |
| 2218 | * for the same type of key, such as {@link #META_SHIFT_ON} and {@link #META_SHIFT_LEFT_ON}, |
| 2219 | * then this method throws an illegal argument exception. |
| 2220 | * </p> |
| 2221 | * |
| 2222 | * @param modifiers The meta state of the modifier keys to check. May be a combination |
| 2223 | * of modifier meta states as defined by {@link #getModifierMetaStateMask()}. May be 0 to |
| 2224 | * ensure that no modifier keys are pressed. |
| 2225 | * @return True if only the specified modifier keys are pressed. |
| 2226 | * @throws IllegalArgumentException if the modifiers parameter contains invalid modifiers |
| 2227 | * @see #metaStateHasModifiers |
| 2228 | */ |
| 2229 | public final boolean hasModifiers(int modifiers) { |
| 2230 | return metaStateHasModifiers(mMetaState, modifiers); |
| 2231 | } |
| 2232 | |
| 2233 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2234 | * <p>Returns the pressed state of the ALT meta key.</p> |
| 2235 | * |
| 2236 | * @return true if the ALT key is pressed, false otherwise |
| 2237 | * |
| 2238 | * @see #KEYCODE_ALT_LEFT |
| 2239 | * @see #KEYCODE_ALT_RIGHT |
| 2240 | * @see #META_ALT_ON |
| 2241 | */ |
| 2242 | public final boolean isAltPressed() { |
| 2243 | return (mMetaState & META_ALT_ON) != 0; |
| 2244 | } |
| 2245 | |
| 2246 | /** |
| 2247 | * <p>Returns the pressed state of the SHIFT meta key.</p> |
| 2248 | * |
| 2249 | * @return true if the SHIFT key is pressed, false otherwise |
| 2250 | * |
| 2251 | * @see #KEYCODE_SHIFT_LEFT |
| 2252 | * @see #KEYCODE_SHIFT_RIGHT |
| 2253 | * @see #META_SHIFT_ON |
| 2254 | */ |
| 2255 | public final boolean isShiftPressed() { |
| 2256 | return (mMetaState & META_SHIFT_ON) != 0; |
| 2257 | } |
| 2258 | |
| 2259 | /** |
| 2260 | * <p>Returns the pressed state of the SYM meta key.</p> |
| 2261 | * |
| 2262 | * @return true if the SYM key is pressed, false otherwise |
| 2263 | * |
| 2264 | * @see #KEYCODE_SYM |
| 2265 | * @see #META_SYM_ON |
| 2266 | */ |
| 2267 | public final boolean isSymPressed() { |
| 2268 | return (mMetaState & META_SYM_ON) != 0; |
| 2269 | } |
| 2270 | |
| 2271 | /** |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2272 | * <p>Returns the pressed state of the CTRL meta key.</p> |
| 2273 | * |
| 2274 | * @return true if the CTRL key is pressed, false otherwise |
| 2275 | * |
| 2276 | * @see #KEYCODE_CTRL_LEFT |
| 2277 | * @see #KEYCODE_CTRL_RIGHT |
| 2278 | * @see #META_CTRL_ON |
| 2279 | */ |
| 2280 | public final boolean isCtrlPressed() { |
| 2281 | return (mMetaState & META_CTRL_ON) != 0; |
| 2282 | } |
| 2283 | |
| 2284 | /** |
| 2285 | * <p>Returns the pressed state of the META meta key.</p> |
| 2286 | * |
| 2287 | * @return true if the META key is pressed, false otherwise |
| 2288 | * |
| 2289 | * @see #KEYCODE_META_LEFT |
| 2290 | * @see #KEYCODE_META_RIGHT |
| 2291 | * @see #META_META_ON |
| 2292 | */ |
| 2293 | public final boolean isMetaPressed() { |
| 2294 | return (mMetaState & META_META_ON) != 0; |
| 2295 | } |
| 2296 | |
| 2297 | /** |
| 2298 | * <p>Returns the pressed state of the FUNCTION meta key.</p> |
| 2299 | * |
| 2300 | * @return true if the FUNCTION key is pressed, false otherwise |
| 2301 | * |
| 2302 | * @see #KEYCODE_FUNCTION |
| 2303 | * @see #META_FUNCTION_ON |
| 2304 | */ |
| 2305 | public final boolean isFunctionPressed() { |
| 2306 | return (mMetaState & META_FUNCTION_ON) != 0; |
| 2307 | } |
| 2308 | |
| 2309 | /** |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2310 | * <p>Returns the locked state of the CAPS LOCK meta key.</p> |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2311 | * |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2312 | * @return true if the CAPS LOCK key is on, false otherwise |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2313 | * |
| 2314 | * @see #KEYCODE_CAPS_LOCK |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2315 | * @see #META_CAPS_LOCK_ON |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2316 | */ |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2317 | public final boolean isCapsLockOn() { |
| 2318 | return (mMetaState & META_CAPS_LOCK_ON) != 0; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | /** |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2322 | * <p>Returns the locked state of the NUM LOCK meta key.</p> |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2323 | * |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2324 | * @return true if the NUM LOCK key is on, false otherwise |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2325 | * |
| 2326 | * @see #KEYCODE_NUM_LOCK |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2327 | * @see #META_NUM_LOCK_ON |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2328 | */ |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2329 | public final boolean isNumLockOn() { |
| 2330 | return (mMetaState & META_NUM_LOCK_ON) != 0; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | /** |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2334 | * <p>Returns the locked state of the SCROLL LOCK meta key.</p> |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2335 | * |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2336 | * @return true if the SCROLL LOCK key is on, false otherwise |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2337 | * |
| 2338 | * @see #KEYCODE_SCROLL_LOCK |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2339 | * @see #META_SCROLL_LOCK_ON |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2340 | */ |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2341 | public final boolean isScrollLockOn() { |
| 2342 | return (mMetaState & META_SCROLL_LOCK_ON) != 0; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2346 | * Retrieve the action of this key event. May be either |
| 2347 | * {@link #ACTION_DOWN}, {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2348 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2349 | * @return The event action: ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE. |
| 2350 | */ |
| 2351 | public final int getAction() { |
| 2352 | return mAction; |
| 2353 | } |
| 2354 | |
| 2355 | /** |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 2356 | * For {@link #ACTION_UP} events, indicates that the event has been |
| 2357 | * canceled as per {@link #FLAG_CANCELED}. |
| 2358 | */ |
| 2359 | public final boolean isCanceled() { |
| 2360 | return (mFlags&FLAG_CANCELED) != 0; |
| 2361 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2362 | |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 2363 | /** |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 2364 | * Set {@link #FLAG_CANCELED} flag for the key event. |
| 2365 | * |
| 2366 | * @hide |
| 2367 | */ |
| 2368 | @Override |
| 2369 | public final void cancel() { |
| 2370 | mFlags |= FLAG_CANCELED; |
| 2371 | } |
| 2372 | |
| 2373 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2374 | * Call this during {@link Callback#onKeyDown} to have the system track |
| 2375 | * the key through its final up (possibly including a long press). Note |
| 2376 | * that only one key can be tracked at a time -- if another key down |
| 2377 | * event is received while a previous one is being tracked, tracking is |
| 2378 | * stopped on the previous event. |
| 2379 | */ |
| 2380 | public final void startTracking() { |
| 2381 | mFlags |= FLAG_START_TRACKING; |
| 2382 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2383 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2384 | /** |
| 2385 | * For {@link #ACTION_UP} events, indicates that the event is still being |
| 2386 | * tracked from its initial down event as per |
| 2387 | * {@link #FLAG_TRACKING}. |
| 2388 | */ |
| 2389 | public final boolean isTracking() { |
| 2390 | return (mFlags&FLAG_TRACKING) != 0; |
| 2391 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2392 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2393 | /** |
| 2394 | * For {@link #ACTION_DOWN} events, indicates that the event has been |
| 2395 | * canceled as per {@link #FLAG_LONG_PRESS}. |
| 2396 | */ |
| 2397 | public final boolean isLongPress() { |
| 2398 | return (mFlags&FLAG_LONG_PRESS) != 0; |
| 2399 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2400 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2401 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | * Retrieve the key code of the key event. This is the physical key that |
| 2403 | * was pressed, <em>not</em> the Unicode character. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2404 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2405 | * @return The key code of the event. |
| 2406 | */ |
| 2407 | public final int getKeyCode() { |
| 2408 | return mKeyCode; |
| 2409 | } |
| 2410 | |
| 2411 | /** |
| 2412 | * For the special case of a {@link #ACTION_MULTIPLE} event with key |
| 2413 | * code of {@link #KEYCODE_UNKNOWN}, this is a raw string of characters |
| 2414 | * associated with the event. In all other cases it is null. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2415 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2416 | * @return Returns a String of 1 or more characters associated with |
| 2417 | * the event. |
| 2418 | */ |
| 2419 | public final String getCharacters() { |
| 2420 | return mCharacters; |
| 2421 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2423 | /** |
| 2424 | * Retrieve the hardware key id of this key event. These values are not |
| 2425 | * reliable and vary from device to device. |
| 2426 | * |
| 2427 | * {@more} |
| 2428 | * Mostly this is here for debugging purposes. |
| 2429 | */ |
| 2430 | public final int getScanCode() { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2431 | return mScanCode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2432 | } |
| 2433 | |
| 2434 | /** |
| 2435 | * Retrieve the repeat count of the event. For both key up and key down |
| 2436 | * events, this is the number of times the key has repeated with the first |
| 2437 | * down starting at 0 and counting up from there. For multiple key |
| 2438 | * events, this is the number of down/up pairs that have occurred. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2439 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2440 | * @return The number of times the key has repeated. |
| 2441 | */ |
| 2442 | public final int getRepeatCount() { |
| 2443 | return mRepeatCount; |
| 2444 | } |
| 2445 | |
| 2446 | /** |
| 2447 | * Retrieve the time of the most recent key down event, |
| 2448 | * in the {@link android.os.SystemClock#uptimeMillis} time base. If this |
| 2449 | * is a down event, this will be the same as {@link #getEventTime()}. |
| 2450 | * Note that when chording keys, this value is the down time of the |
| 2451 | * most recently pressed key, which may <em>not</em> be the same physical |
| 2452 | * key of this event. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2453 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2454 | * @return Returns the most recent key down time, in the |
| 2455 | * {@link android.os.SystemClock#uptimeMillis} time base |
| 2456 | */ |
| 2457 | public final long getDownTime() { |
| 2458 | return mDownTime; |
| 2459 | } |
| 2460 | |
| 2461 | /** |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 2462 | * Retrieve the time this event occurred, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2463 | * in the {@link android.os.SystemClock#uptimeMillis} time base. |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 2464 | * |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2465 | * @return Returns the time this event occurred, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2466 | * in the {@link android.os.SystemClock#uptimeMillis} time base. |
| 2467 | */ |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 2468 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2469 | public final long getEventTime() { |
| 2470 | return mEventTime; |
| 2471 | } |
| 2472 | |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 2473 | /** |
| 2474 | * Retrieve the time this event occurred, |
| 2475 | * in the {@link android.os.SystemClock#uptimeMillis} time base but with |
| 2476 | * nanosecond (instead of millisecond) precision. |
| 2477 | * <p> |
| 2478 | * The value is in nanosecond precision but it may not have nanosecond accuracy. |
| 2479 | * </p> |
| 2480 | * |
| 2481 | * @return Returns the time this event occurred, |
| 2482 | * in the {@link android.os.SystemClock#uptimeMillis} time base but with |
| 2483 | * nanosecond (instead of millisecond) precision. |
| 2484 | * |
| 2485 | * @hide |
| 2486 | */ |
Jeff Brown | 4e91a18 | 2011-04-07 11:38:09 -0700 | [diff] [blame] | 2487 | @Override |
| 2488 | public final long getEventTimeNano() { |
| 2489 | return mEventTime * 1000000L; |
| 2490 | } |
| 2491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2492 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2493 | * Renamed to {@link #getDeviceId}. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2494 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2495 | * @hide |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2496 | * @deprecated use {@link #getDeviceId()} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2497 | */ |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2498 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2499 | public final int getKeyboardDevice() { |
| 2500 | return mDeviceId; |
| 2501 | } |
| 2502 | |
| 2503 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2504 | * Gets the {@link KeyCharacterMap} associated with the keyboard device. |
| 2505 | * |
| 2506 | * @return The associated key character map. |
Andrew Sapperstein | 8ab3dc7 | 2011-06-23 18:56:44 -0700 | [diff] [blame] | 2507 | * @throws {@link KeyCharacterMap.UnavailableException} if the key character map |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2508 | * could not be loaded because it was malformed or the default key character map |
| 2509 | * is missing from the system. |
| 2510 | * |
Andrew Sapperstein | 8ab3dc7 | 2011-06-23 18:56:44 -0700 | [diff] [blame] | 2511 | * @see KeyCharacterMap#load |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2512 | */ |
| 2513 | public final KeyCharacterMap getKeyCharacterMap() { |
| 2514 | return KeyCharacterMap.load(mDeviceId); |
| 2515 | } |
| 2516 | |
| 2517 | /** |
| 2518 | * Gets the primary character for this key. |
| 2519 | * In other words, the label that is physically printed on it. |
| 2520 | * |
| 2521 | * @return The display label character, or 0 if none (eg. for non-printing keys). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2522 | */ |
| 2523 | public char getDisplayLabel() { |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2524 | return getKeyCharacterMap().getDisplayLabel(mKeyCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2526 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2527 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2528 | * Gets the Unicode character generated by the specified key and meta |
| 2529 | * key state combination. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2530 | * <p> |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2531 | * Returns the Unicode character that the specified key would produce |
| 2532 | * when the specified meta bits (see {@link MetaKeyKeyListener}) |
| 2533 | * were active. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2534 | * </p><p> |
| 2535 | * Returns 0 if the key is not one that is used to type Unicode |
| 2536 | * characters. |
| 2537 | * </p><p> |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2538 | * If the return value has bit {@link KeyCharacterMap#COMBINING_ACCENT} set, the |
| 2539 | * key is a "dead key" that should be combined with another to |
| 2540 | * actually produce a character -- see {@link KeyCharacterMap#getDeadChar} -- |
| 2541 | * after masking with {@link KeyCharacterMap#COMBINING_ACCENT_MASK}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2542 | * </p> |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2543 | * |
| 2544 | * @return The associated character or combining accent, or 0 if none. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2545 | */ |
| 2546 | public int getUnicodeChar() { |
| 2547 | return getUnicodeChar(mMetaState); |
| 2548 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2551 | * Gets the Unicode character generated by the specified key and meta |
| 2552 | * key state combination. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2553 | * <p> |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2554 | * Returns the Unicode character that the specified key would produce |
| 2555 | * when the specified meta bits (see {@link MetaKeyKeyListener}) |
| 2556 | * were active. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2557 | * </p><p> |
| 2558 | * Returns 0 if the key is not one that is used to type Unicode |
| 2559 | * characters. |
| 2560 | * </p><p> |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2561 | * If the return value has bit {@link KeyCharacterMap#COMBINING_ACCENT} set, the |
| 2562 | * key is a "dead key" that should be combined with another to |
| 2563 | * actually produce a character -- see {@link KeyCharacterMap#getDeadChar} -- |
| 2564 | * after masking with {@link KeyCharacterMap#COMBINING_ACCENT_MASK}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2565 | * </p> |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2566 | * |
| 2567 | * @param metaState The meta key modifier state. |
| 2568 | * @return The associated character or combining accent, or 0 if none. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2569 | */ |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2570 | public int getUnicodeChar(int metaState) { |
| 2571 | return getKeyCharacterMap().get(mKeyCode, metaState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2572 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2573 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2574 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2575 | * Get the character conversion data for a given key code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2576 | * |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2577 | * @param results A {@link KeyCharacterMap.KeyData} instance that will be |
| 2578 | * filled with the results. |
| 2579 | * @return True if the key was mapped. If the key was not mapped, results is not modified. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2580 | * |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2581 | * @deprecated instead use {@link #getDisplayLabel()}, |
| 2582 | * {@link #getNumber()} or {@link #getUnicodeChar(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2583 | */ |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2584 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2585 | public boolean getKeyData(KeyData results) { |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2586 | return getKeyCharacterMap().getKeyData(mKeyCode, results); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2587 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2589 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2590 | * Gets the first character in the character array that can be generated |
| 2591 | * by the specified key code. |
| 2592 | * <p> |
| 2593 | * This is a convenience function that returns the same value as |
| 2594 | * {@link #getMatch(char[],int) getMatch(chars, 0)}. |
| 2595 | * </p> |
| 2596 | * |
| 2597 | * @param chars The array of matching characters to consider. |
| 2598 | * @return The matching associated character, or 0 if none. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2599 | */ |
| 2600 | public char getMatch(char[] chars) { |
| 2601 | return getMatch(chars, 0); |
| 2602 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2603 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2604 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2605 | * Gets the first character in the character array that can be generated |
| 2606 | * by the specified key code. If there are multiple choices, prefers |
| 2607 | * the one that would be generated with the specified meta key modifier state. |
| 2608 | * |
| 2609 | * @param chars The array of matching characters to consider. |
| 2610 | * @param metaState The preferred meta key modifier state. |
| 2611 | * @return The matching associated character, or 0 if none. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2612 | */ |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2613 | public char getMatch(char[] chars, int metaState) { |
| 2614 | return getKeyCharacterMap().getMatch(mKeyCode, chars, metaState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2615 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2618 | * Gets the number or symbol associated with the key. |
| 2619 | * <p> |
| 2620 | * The character value is returned, not the numeric value. |
| 2621 | * If the key is not a number, but is a symbol, the symbol is retuned. |
| 2622 | * </p><p> |
| 2623 | * This method is intended to to support dial pads and other numeric or |
| 2624 | * symbolic entry on keyboards where certain keys serve dual function |
| 2625 | * as alphabetic and symbolic keys. This method returns the number |
| 2626 | * or symbol associated with the key independent of whether the user |
| 2627 | * has pressed the required modifier. |
| 2628 | * </p><p> |
| 2629 | * For example, on one particular keyboard the keys on the top QWERTY row generate |
| 2630 | * numbers when ALT is pressed such that ALT-Q maps to '1'. So for that keyboard |
| 2631 | * when {@link #getNumber} is called with {@link KeyEvent#KEYCODE_Q} it returns '1' |
| 2632 | * so that the user can type numbers without pressing ALT when it makes sense. |
| 2633 | * </p> |
| 2634 | * |
| 2635 | * @return The associated numeric or symbolic character, or 0 if none. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2636 | */ |
| 2637 | public char getNumber() { |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2638 | return getKeyCharacterMap().getNumber(mKeyCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2639 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2640 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2641 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2642 | * Returns true if this key produces a glyph. |
| 2643 | * |
| 2644 | * @return True if the key is a printing key. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2645 | */ |
| 2646 | public boolean isPrintingKey() { |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2647 | return getKeyCharacterMap().isPrintingKey(mKeyCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2648 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2649 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2650 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2651 | * @deprecated Use {@link #dispatch(Callback, DispatcherState, Object)} instead. |
| 2652 | */ |
| 2653 | @Deprecated |
| 2654 | public final boolean dispatch(Callback receiver) { |
| 2655 | return dispatch(receiver, null, null); |
| 2656 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2657 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2658 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2659 | * Deliver this key event to a {@link Callback} interface. If this is |
| 2660 | * an ACTION_MULTIPLE event and it is not handled, then an attempt will |
| 2661 | * be made to deliver a single normal event. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2662 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2663 | * @param receiver The Callback that will be given the event. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2664 | * @param state State information retained across events. |
| 2665 | * @param target The target of the dispatch, for use in tracking. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2666 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2667 | * @return The return value from the Callback method that was called. |
| 2668 | */ |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2669 | public final boolean dispatch(Callback receiver, DispatcherState state, |
| 2670 | Object target) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2671 | switch (mAction) { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2672 | case ACTION_DOWN: { |
| 2673 | mFlags &= ~FLAG_START_TRACKING; |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2674 | if (DEBUG) Log.v(TAG, "Key down to " + target + " in " + state |
| 2675 | + ": " + this); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2676 | boolean res = receiver.onKeyDown(mKeyCode, this); |
| 2677 | if (state != null) { |
| 2678 | if (res && mRepeatCount == 0 && (mFlags&FLAG_START_TRACKING) != 0) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2679 | if (DEBUG) Log.v(TAG, " Start tracking!"); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2680 | state.startTracking(this, target); |
| 2681 | } else if (isLongPress() && state.isTracking(this)) { |
| 2682 | try { |
| 2683 | if (receiver.onKeyLongPress(mKeyCode, this)) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2684 | if (DEBUG) Log.v(TAG, " Clear from long press!"); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2685 | state.performedLongPress(this); |
| 2686 | res = true; |
| 2687 | } |
| 2688 | } catch (AbstractMethodError e) { |
| 2689 | } |
| 2690 | } |
| 2691 | } |
| 2692 | return res; |
| 2693 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2694 | case ACTION_UP: |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2695 | if (DEBUG) Log.v(TAG, "Key up to " + target + " in " + state |
| 2696 | + ": " + this); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2697 | if (state != null) { |
| 2698 | state.handleUpEvent(this); |
| 2699 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2700 | return receiver.onKeyUp(mKeyCode, this); |
| 2701 | case ACTION_MULTIPLE: |
| 2702 | final int count = mRepeatCount; |
| 2703 | final int code = mKeyCode; |
| 2704 | if (receiver.onKeyMultiple(code, count, this)) { |
| 2705 | return true; |
| 2706 | } |
| 2707 | if (code != KeyEvent.KEYCODE_UNKNOWN) { |
| 2708 | mAction = ACTION_DOWN; |
| 2709 | mRepeatCount = 0; |
| 2710 | boolean handled = receiver.onKeyDown(code, this); |
| 2711 | if (handled) { |
| 2712 | mAction = ACTION_UP; |
| 2713 | receiver.onKeyUp(code, this); |
| 2714 | } |
| 2715 | mAction = ACTION_MULTIPLE; |
| 2716 | mRepeatCount = count; |
| 2717 | return handled; |
| 2718 | } |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2719 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2720 | } |
| 2721 | return false; |
| 2722 | } |
| 2723 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2724 | /** |
| 2725 | * Use with {@link KeyEvent#dispatch(Callback, DispatcherState, Object)} |
| 2726 | * for more advanced key dispatching, such as long presses. |
| 2727 | */ |
| 2728 | public static class DispatcherState { |
| 2729 | int mDownKeyCode; |
| 2730 | Object mDownTarget; |
| 2731 | SparseIntArray mActiveLongPresses = new SparseIntArray(); |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2732 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2733 | /** |
| 2734 | * Reset back to initial state. |
| 2735 | */ |
| 2736 | public void reset() { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2737 | if (DEBUG) Log.v(TAG, "Reset: " + this); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2738 | mDownKeyCode = 0; |
| 2739 | mDownTarget = null; |
| 2740 | mActiveLongPresses.clear(); |
| 2741 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2742 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2743 | /** |
| 2744 | * Stop any tracking associated with this target. |
| 2745 | */ |
| 2746 | public void reset(Object target) { |
| 2747 | if (mDownTarget == target) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2748 | if (DEBUG) Log.v(TAG, "Reset in " + target + ": " + this); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2749 | mDownKeyCode = 0; |
| 2750 | mDownTarget = null; |
| 2751 | } |
| 2752 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2753 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2754 | /** |
| 2755 | * Start tracking the key code associated with the given event. This |
| 2756 | * can only be called on a key down. It will allow you to see any |
| 2757 | * long press associated with the key, and will result in |
| 2758 | * {@link KeyEvent#isTracking} return true on the long press and up |
| 2759 | * events. |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2760 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2761 | * <p>This is only needed if you are directly dispatching events, rather |
| 2762 | * than handling them in {@link Callback#onKeyDown}. |
| 2763 | */ |
| 2764 | public void startTracking(KeyEvent event, Object target) { |
| 2765 | if (event.getAction() != ACTION_DOWN) { |
| 2766 | throw new IllegalArgumentException( |
| 2767 | "Can only start tracking on a down event"); |
| 2768 | } |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2769 | if (DEBUG) Log.v(TAG, "Start trackingt in " + target + ": " + this); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2770 | mDownKeyCode = event.getKeyCode(); |
| 2771 | mDownTarget = target; |
| 2772 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2773 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2774 | /** |
| 2775 | * Return true if the key event is for a key code that is currently |
| 2776 | * being tracked by the dispatcher. |
| 2777 | */ |
| 2778 | public boolean isTracking(KeyEvent event) { |
| 2779 | return mDownKeyCode == event.getKeyCode(); |
| 2780 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2781 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2782 | /** |
| 2783 | * Keep track of the given event's key code as having performed an |
| 2784 | * action with a long press, so no action should occur on the up. |
| 2785 | * <p>This is only needed if you are directly dispatching events, rather |
| 2786 | * than handling them in {@link Callback#onKeyLongPress}. |
| 2787 | */ |
| 2788 | public void performedLongPress(KeyEvent event) { |
| 2789 | mActiveLongPresses.put(event.getKeyCode(), 1); |
| 2790 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2791 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2792 | /** |
| 2793 | * Handle key up event to stop tracking. This resets the dispatcher state, |
| 2794 | * and updates the key event state based on it. |
| 2795 | * <p>This is only needed if you are directly dispatching events, rather |
| 2796 | * than handling them in {@link Callback#onKeyUp}. |
| 2797 | */ |
| 2798 | public void handleUpEvent(KeyEvent event) { |
| 2799 | final int keyCode = event.getKeyCode(); |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2800 | if (DEBUG) Log.v(TAG, "Handle key up " + event + ": " + this); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2801 | int index = mActiveLongPresses.indexOfKey(keyCode); |
| 2802 | if (index >= 0) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2803 | if (DEBUG) Log.v(TAG, " Index: " + index); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2804 | event.mFlags |= FLAG_CANCELED | FLAG_CANCELED_LONG_PRESS; |
| 2805 | mActiveLongPresses.removeAt(index); |
| 2806 | } |
| 2807 | if (mDownKeyCode == keyCode) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2808 | if (DEBUG) Log.v(TAG, " Tracking!"); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2809 | event.mFlags |= FLAG_TRACKING; |
| 2810 | mDownKeyCode = 0; |
| 2811 | mDownTarget = null; |
| 2812 | } |
| 2813 | } |
| 2814 | } |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2815 | |
| 2816 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2817 | public String toString() { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2818 | StringBuilder msg = new StringBuilder(); |
| 2819 | msg.append("KeyEvent { action=").append(actionToString(mAction)); |
| 2820 | msg.append(", keyCode=").append(keyCodeToString(mKeyCode)); |
| 2821 | msg.append(", scanCode=").append(mScanCode); |
| 2822 | if (mCharacters != null) { |
| 2823 | msg.append(", characters=\"").append(mCharacters).append("\""); |
| 2824 | } |
| 2825 | msg.append(", metaState=").append(metaStateToString(mMetaState)); |
| 2826 | msg.append(", flags=0x").append(Integer.toHexString(mFlags)); |
| 2827 | msg.append(", repeatCount=").append(mRepeatCount); |
| 2828 | msg.append(", eventTime=").append(mEventTime); |
| 2829 | msg.append(", downTime=").append(mDownTime); |
| 2830 | msg.append(", deviceId=").append(mDeviceId); |
| 2831 | msg.append(", source=0x").append(Integer.toHexString(mSource)); |
| 2832 | msg.append(" }"); |
| 2833 | return msg.toString(); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | /** |
| 2837 | * Returns a string that represents the symbolic name of the specified action |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2838 | * such as "ACTION_DOWN", or an equivalent numeric constant such as "35" if unknown. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2839 | * |
| 2840 | * @param action The action. |
| 2841 | * @return The symbolic name of the specified action. |
| 2842 | * @hide |
| 2843 | */ |
| 2844 | public static String actionToString(int action) { |
| 2845 | switch (action) { |
| 2846 | case ACTION_DOWN: |
| 2847 | return "ACTION_DOWN"; |
| 2848 | case ACTION_UP: |
| 2849 | return "ACTION_UP"; |
| 2850 | case ACTION_MULTIPLE: |
| 2851 | return "ACTION_MULTIPLE"; |
| 2852 | default: |
| 2853 | return Integer.toString(action); |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | /** |
| 2858 | * Returns a string that represents the symbolic name of the specified keycode |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2859 | * such as "KEYCODE_A", "KEYCODE_DPAD_UP", or an equivalent numeric constant |
| 2860 | * such as "1001" if unknown. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2861 | * |
| 2862 | * @param keyCode The key code. |
| 2863 | * @return The symbolic name of the specified keycode. |
| 2864 | * |
| 2865 | * @see KeyCharacterMap#getDisplayLabel |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2866 | */ |
| 2867 | public static String keyCodeToString(int keyCode) { |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 2868 | String symbolicName = nativeKeyCodeToString(keyCode); |
| 2869 | return symbolicName != null ? LABEL_PREFIX + symbolicName : Integer.toString(keyCode); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2870 | } |
| 2871 | |
| 2872 | /** |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2873 | * Gets a keycode by its symbolic name such as "KEYCODE_A" or an equivalent |
| 2874 | * numeric constant such as "1001". |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2875 | * |
| 2876 | * @param symbolicName The symbolic name of the keycode. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2877 | * @return The keycode or {@link #KEYCODE_UNKNOWN} if not found. |
Michael Wright | 072137c | 2013-04-24 20:41:20 -0700 | [diff] [blame] | 2878 | * @see #keycodeToString(int) |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2879 | */ |
| 2880 | public static int keyCodeFromString(String symbolicName) { |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 2881 | if (symbolicName.startsWith(LABEL_PREFIX)) { |
| 2882 | symbolicName = symbolicName.substring(LABEL_PREFIX.length()); |
Michael Wright | 973efa0 | 2014-05-13 15:38:56 -0700 | [diff] [blame] | 2883 | int keyCode = nativeKeyCodeFromString(symbolicName); |
| 2884 | if (keyCode > 0) { |
| 2885 | return keyCode; |
| 2886 | } |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2887 | } |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2888 | try { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2889 | return Integer.parseInt(symbolicName, 10); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2890 | } catch (NumberFormatException ex) { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2891 | return KEYCODE_UNKNOWN; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2892 | } |
| 2893 | } |
| 2894 | |
| 2895 | /** |
| 2896 | * Returns a string that represents the symbolic name of the specified combined meta |
| 2897 | * key modifier state flags such as "0", "META_SHIFT_ON", |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2898 | * "META_ALT_ON|META_SHIFT_ON" or an equivalent numeric constant such as "0x10000000" |
| 2899 | * if unknown. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2900 | * |
| 2901 | * @param metaState The meta state. |
| 2902 | * @return The symbolic name of the specified combined meta state flags. |
| 2903 | * @hide |
| 2904 | */ |
| 2905 | public static String metaStateToString(int metaState) { |
| 2906 | if (metaState == 0) { |
| 2907 | return "0"; |
| 2908 | } |
| 2909 | StringBuilder result = null; |
| 2910 | int i = 0; |
| 2911 | while (metaState != 0) { |
| 2912 | final boolean isSet = (metaState & 1) != 0; |
| 2913 | metaState >>>= 1; // unsigned shift! |
| 2914 | if (isSet) { |
| 2915 | final String name = META_SYMBOLIC_NAMES[i]; |
| 2916 | if (result == null) { |
| 2917 | if (metaState == 0) { |
| 2918 | return name; |
| 2919 | } |
| 2920 | result = new StringBuilder(name); |
| 2921 | } else { |
| 2922 | result.append('|'); |
| 2923 | result.append(name); |
| 2924 | } |
| 2925 | } |
| 2926 | i += 1; |
| 2927 | } |
| 2928 | return result.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | public static final Parcelable.Creator<KeyEvent> CREATOR |
| 2932 | = new Parcelable.Creator<KeyEvent>() { |
| 2933 | public KeyEvent createFromParcel(Parcel in) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2934 | in.readInt(); // skip token, we already know this is a KeyEvent |
| 2935 | return KeyEvent.createFromParcelBody(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | public KeyEvent[] newArray(int size) { |
| 2939 | return new KeyEvent[size]; |
| 2940 | } |
| 2941 | }; |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2942 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2943 | /** @hide */ |
| 2944 | public static KeyEvent createFromParcelBody(Parcel in) { |
| 2945 | return new KeyEvent(in); |
| 2946 | } |
RoboErik | 01fe661 | 2014-02-13 14:19:04 -0800 | [diff] [blame] | 2947 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2948 | private KeyEvent(Parcel in) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2949 | mDeviceId = in.readInt(); |
| 2950 | mSource = in.readInt(); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2951 | mAction = in.readInt(); |
| 2952 | mKeyCode = in.readInt(); |
| 2953 | mRepeatCount = in.readInt(); |
| 2954 | mMetaState = in.readInt(); |
| 2955 | mScanCode = in.readInt(); |
| 2956 | mFlags = in.readInt(); |
| 2957 | mDownTime = in.readLong(); |
| 2958 | mEventTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | public void writeToParcel(Parcel out, int flags) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2962 | out.writeInt(PARCEL_TOKEN_KEY_EVENT); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2963 | |
| 2964 | out.writeInt(mDeviceId); |
| 2965 | out.writeInt(mSource); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2966 | out.writeInt(mAction); |
| 2967 | out.writeInt(mKeyCode); |
| 2968 | out.writeInt(mRepeatCount); |
| 2969 | out.writeInt(mMetaState); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2970 | out.writeInt(mScanCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | out.writeInt(mFlags); |
| 2972 | out.writeLong(mDownTime); |
| 2973 | out.writeLong(mEventTime); |
| 2974 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | } |