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