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