blob: e249c777caf60634d636e832f340746911fee38f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.view;
18
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +010019import static android.view.Display.INVALID_DISPLAY;
20
Siarhei Vishniakoude1f9042018-05-09 09:54:43 -070021import android.annotation.NonNull;
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -060022import android.annotation.Nullable;
Siarhei Vishniakou4c96a5e2018-04-24 17:57:44 -070023import android.annotation.TestApi;
Artur Satayevad9254c2019-12-10 17:47:54 +000024import android.compat.annotation.UnsupportedAppUsage;
Mathew Inwood8c854f82018-09-14 12:35:36 +010025import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.os.Parcel;
27import android.os.Parcelable;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080028import android.text.method.MetaKeyKeyListener;
Dianne Hackborn8d374262009-09-14 21:21:52 -070029import android.util.Log;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -070030import android.util.SparseIntArray;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.view.KeyCharacterMap.KeyData;
32
33/**
Jeff Browndc1ab4b2010-09-14 18:03:38 -070034 * Object used to report key and button events.
35 * <p>
36 * Each key press is described by a sequence of key events. A key press
37 * starts with a key event with {@link #ACTION_DOWN}. If the key is held
38 * sufficiently long that it repeats, then the initial down is followed
39 * additional key events with {@link #ACTION_DOWN} and a non-zero value for
40 * {@link #getRepeatCount()}. The last key event is a {@link #ACTION_UP}
41 * for the key up. If the key press is canceled, the key up event will have the
42 * {@link #FLAG_CANCELED} flag set.
43 * </p><p>
44 * Key events are generally accompanied by a key code ({@link #getKeyCode()}),
45 * scan code ({@link #getScanCode()}) and meta state ({@link #getMetaState()}).
46 * Key code constants are defined in this class. Scan code constants are raw
47 * device-specific codes obtained from the OS and so are not generally meaningful
48 * to applications unless interpreted using the {@link KeyCharacterMap}.
49 * Meta states describe the pressed state of key modifiers
50 * such as {@link #META_SHIFT_ON} or {@link #META_ALT_ON}.
51 * </p><p>
Jeff Brown497a92c2010-09-12 17:55:08 -070052 * Key codes typically correspond one-to-one with individual keys on an input device.
53 * Many keys and key combinations serve quite different functions on different
54 * input devices so care must be taken when interpreting them. Always use the
55 * {@link KeyCharacterMap} associated with the input device when mapping keys
56 * to characters. Be aware that there may be multiple key input devices active
57 * at the same time and each will have its own key character map.
58 * </p><p>
Jean Chalard405bc512012-05-29 19:12:34 +090059 * As soft input methods can use multiple and inventive ways of inputting text,
60 * there is no guarantee that any key press on a soft keyboard will generate a key
61 * event: this is left to the IME's discretion, and in fact sending such events is
62 * discouraged. You should never rely on receiving KeyEvents for any key on a soft
63 * input method. In particular, the default software keyboard will never send any
64 * key event to any application targetting Jelly Bean or later, and will only send
65 * events for some presses of the delete and return keys to applications targetting
66 * Ice Cream Sandwich or earlier. Be aware that other software input methods may
67 * never send key events regardless of the version. Consider using editor actions
68 * like {@link android.view.inputmethod.EditorInfo#IME_ACTION_DONE} if you need
69 * specific interaction with the software keyboard, as it gives more visibility to
70 * the user as to how your application will react to key presses.
71 * </p><p>
Jeff Browndc1ab4b2010-09-14 18:03:38 -070072 * When interacting with an IME, the framework may deliver key events
73 * with the special action {@link #ACTION_MULTIPLE} that either specifies
74 * that single repeated key code or a sequence of characters to insert.
75 * </p><p>
Jeff Brownb6997262010-10-08 22:31:17 -070076 * In general, the framework cannot guarantee that the key events it delivers
77 * to a view always constitute complete key sequences since some events may be dropped
78 * or modified by containing views before they are delivered. The view implementation
79 * should be prepared to handle {@link #FLAG_CANCELED} and should tolerate anomalous
80 * situations such as receiving a new {@link #ACTION_DOWN} without first having
81 * received an {@link #ACTION_UP} for the prior key press.
Jeff Browndc1ab4b2010-09-14 18:03:38 -070082 * </p><p>
83 * Refer to {@link InputDevice} for more information about how different kinds of
84 * input devices and sources represent keys and buttons.
85 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 */
Jeff Brownc5ed5912010-07-14 18:48:53 -070087public class KeyEvent extends InputEvent implements Parcelable {
Jeff Browndc1ab4b2010-09-14 18:03:38 -070088 /** Key code constant: Unknown key code. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 public static final int KEYCODE_UNKNOWN = 0;
Jeff Browndc1ab4b2010-09-14 18:03:38 -070090 /** Key code constant: Soft Left 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 left
93 * of the display. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 public static final int KEYCODE_SOFT_LEFT = 1;
Jeff Browndc1ab4b2010-09-14 18:03:38 -070095 /** Key code constant: Soft Right key.
96 * Usually situated below the display on phones and used as a multi-function
97 * feature key for selecting a software defined function shown on the bottom right
98 * of the display. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 public static final int KEYCODE_SOFT_RIGHT = 2;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700100 /** Key code constant: Home key.
101 * This key is handled by the framework and is never delivered to applications. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 public static final int KEYCODE_HOME = 3;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700103 /** Key code constant: Back key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 public static final int KEYCODE_BACK = 4;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700105 /** Key code constant: Call key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 public static final int KEYCODE_CALL = 5;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700107 /** Key code constant: End Call key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 public static final int KEYCODE_ENDCALL = 6;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700109 /** Key code constant: '0' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 public static final int KEYCODE_0 = 7;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700111 /** Key code constant: '1' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 public static final int KEYCODE_1 = 8;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700113 /** Key code constant: '2' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 public static final int KEYCODE_2 = 9;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700115 /** Key code constant: '3' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 public static final int KEYCODE_3 = 10;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700117 /** Key code constant: '4' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 public static final int KEYCODE_4 = 11;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700119 /** Key code constant: '5' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 public static final int KEYCODE_5 = 12;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700121 /** Key code constant: '6' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 public static final int KEYCODE_6 = 13;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700123 /** Key code constant: '7' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 public static final int KEYCODE_7 = 14;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700125 /** Key code constant: '8' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 public static final int KEYCODE_8 = 15;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700127 /** Key code constant: '9' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 public static final int KEYCODE_9 = 16;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700129 /** Key code constant: '*' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 public static final int KEYCODE_STAR = 17;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700131 /** Key code constant: '#' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 public static final int KEYCODE_POUND = 18;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700133 /** Key code constant: Directional Pad Up key.
134 * May also be synthesized from trackball motions. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 public static final int KEYCODE_DPAD_UP = 19;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700136 /** Key code constant: Directional Pad Down key.
137 * May also be synthesized from trackball motions. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 public static final int KEYCODE_DPAD_DOWN = 20;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700139 /** Key code constant: Directional Pad Left key.
140 * May also be synthesized from trackball motions. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 public static final int KEYCODE_DPAD_LEFT = 21;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700142 /** Key code constant: Directional Pad Right key.
143 * May also be synthesized from trackball motions. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 public static final int KEYCODE_DPAD_RIGHT = 22;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700145 /** Key code constant: Directional Pad Center key.
146 * May also be synthesized from trackball motions. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 public static final int KEYCODE_DPAD_CENTER = 23;
Jeff Brownb0418da2010-11-01 15:24:01 -0700148 /** Key code constant: Volume Up key.
149 * Adjusts the speaker volume up. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 public static final int KEYCODE_VOLUME_UP = 24;
Jeff Brownb0418da2010-11-01 15:24:01 -0700151 /** Key code constant: Volume Down key.
152 * Adjusts the speaker volume down. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 public static final int KEYCODE_VOLUME_DOWN = 25;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700154 /** Key code constant: Power key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 public static final int KEYCODE_POWER = 26;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700156 /** Key code constant: Camera key.
157 * Used to launch a camera application or take pictures. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 public static final int KEYCODE_CAMERA = 27;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700159 /** Key code constant: Clear key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 public static final int KEYCODE_CLEAR = 28;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700161 /** Key code constant: 'A' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 public static final int KEYCODE_A = 29;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700163 /** Key code constant: 'B' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 public static final int KEYCODE_B = 30;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700165 /** Key code constant: 'C' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 public static final int KEYCODE_C = 31;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700167 /** Key code constant: 'D' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 public static final int KEYCODE_D = 32;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700169 /** Key code constant: 'E' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 public static final int KEYCODE_E = 33;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700171 /** Key code constant: 'F' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 public static final int KEYCODE_F = 34;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700173 /** Key code constant: 'G' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 public static final int KEYCODE_G = 35;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700175 /** Key code constant: 'H' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 public static final int KEYCODE_H = 36;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700177 /** Key code constant: 'I' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 public static final int KEYCODE_I = 37;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700179 /** Key code constant: 'J' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 public static final int KEYCODE_J = 38;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700181 /** Key code constant: 'K' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 public static final int KEYCODE_K = 39;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700183 /** Key code constant: 'L' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 public static final int KEYCODE_L = 40;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700185 /** Key code constant: 'M' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 public static final int KEYCODE_M = 41;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700187 /** Key code constant: 'N' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 public static final int KEYCODE_N = 42;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700189 /** Key code constant: 'O' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 public static final int KEYCODE_O = 43;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700191 /** Key code constant: 'P' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 public static final int KEYCODE_P = 44;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700193 /** Key code constant: 'Q' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 public static final int KEYCODE_Q = 45;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700195 /** Key code constant: 'R' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 public static final int KEYCODE_R = 46;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700197 /** Key code constant: 'S' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 public static final int KEYCODE_S = 47;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700199 /** Key code constant: 'T' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 public static final int KEYCODE_T = 48;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700201 /** Key code constant: 'U' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 public static final int KEYCODE_U = 49;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700203 /** Key code constant: 'V' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 public static final int KEYCODE_V = 50;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700205 /** Key code constant: 'W' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 public static final int KEYCODE_W = 51;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700207 /** Key code constant: 'X' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 public static final int KEYCODE_X = 52;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700209 /** Key code constant: 'Y' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 public static final int KEYCODE_Y = 53;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700211 /** Key code constant: 'Z' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 public static final int KEYCODE_Z = 54;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700213 /** Key code constant: ',' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 public static final int KEYCODE_COMMA = 55;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700215 /** Key code constant: '.' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 public static final int KEYCODE_PERIOD = 56;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700217 /** Key code constant: Left Alt modifier key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 public static final int KEYCODE_ALT_LEFT = 57;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700219 /** Key code constant: Right Alt modifier key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 public static final int KEYCODE_ALT_RIGHT = 58;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700221 /** Key code constant: Left Shift modifier key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 public static final int KEYCODE_SHIFT_LEFT = 59;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700223 /** Key code constant: Right Shift modifier key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 public static final int KEYCODE_SHIFT_RIGHT = 60;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700225 /** Key code constant: Tab key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 public static final int KEYCODE_TAB = 61;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700227 /** Key code constant: Space key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 public static final int KEYCODE_SPACE = 62;
Jeff Brown224d4a12010-10-07 20:28:53 -0700229 /** Key code constant: Symbol modifier key.
230 * Used to enter alternate symbols. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 public static final int KEYCODE_SYM = 63;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700232 /** Key code constant: Explorer special function key.
233 * Used to launch a browser application. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234 public static final int KEYCODE_EXPLORER = 64;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700235 /** Key code constant: Envelope special function key.
236 * Used to launch a mail application. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 public static final int KEYCODE_ENVELOPE = 65;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700238 /** Key code constant: Enter key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 public static final int KEYCODE_ENTER = 66;
Jeff Brown224d4a12010-10-07 20:28:53 -0700240 /** Key code constant: Backspace key.
Jeff Brown497a92c2010-09-12 17:55:08 -0700241 * Deletes characters before the insertion point, unlike {@link #KEYCODE_FORWARD_DEL}. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 public static final int KEYCODE_DEL = 67;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700243 /** Key code constant: '`' (backtick) key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 public static final int KEYCODE_GRAVE = 68;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700245 /** Key code constant: '-'. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 public static final int KEYCODE_MINUS = 69;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700247 /** Key code constant: '=' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 public static final int KEYCODE_EQUALS = 70;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700249 /** Key code constant: '[' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 public static final int KEYCODE_LEFT_BRACKET = 71;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700251 /** Key code constant: ']' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 public static final int KEYCODE_RIGHT_BRACKET = 72;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700253 /** Key code constant: '\' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 public static final int KEYCODE_BACKSLASH = 73;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700255 /** Key code constant: ';' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 public static final int KEYCODE_SEMICOLON = 74;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700257 /** Key code constant: ''' (apostrophe) key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 public static final int KEYCODE_APOSTROPHE = 75;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700259 /** Key code constant: '/' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 public static final int KEYCODE_SLASH = 76;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700261 /** Key code constant: '@' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 public static final int KEYCODE_AT = 77;
Jeff Brown224d4a12010-10-07 20:28:53 -0700263 /** Key code constant: Number modifier key.
264 * Used to enter numeric symbols.
265 * This key is not Num Lock; it is more like {@link #KEYCODE_ALT_LEFT} and is
266 * interpreted as an ALT key by {@link android.text.method.MetaKeyKeyListener}. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 public static final int KEYCODE_NUM = 78;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700268 /** Key code constant: Headset Hook key.
269 * Used to hang up calls and stop media. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 public static final int KEYCODE_HEADSETHOOK = 79;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700271 /** Key code constant: Camera Focus key.
272 * Used to focus the camera. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 public static final int KEYCODE_FOCUS = 80; // *Camera* focus
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700274 /** Key code constant: '+' key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 public static final int KEYCODE_PLUS = 81;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700276 /** Key code constant: Menu key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 public static final int KEYCODE_MENU = 82;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700278 /** Key code constant: Notification key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 public static final int KEYCODE_NOTIFICATION = 83;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700280 /** Key code constant: Search key. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 public static final int KEYCODE_SEARCH = 84;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700282 /** Key code constant: Play/Pause media key. */
Dianne Hackborn935ae462009-04-13 16:11:55 -0700283 public static final int KEYCODE_MEDIA_PLAY_PAUSE= 85;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700284 /** Key code constant: Stop media key. */
Dianne Hackborn935ae462009-04-13 16:11:55 -0700285 public static final int KEYCODE_MEDIA_STOP = 86;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700286 /** Key code constant: Play Next media key. */
Dianne Hackborn935ae462009-04-13 16:11:55 -0700287 public static final int KEYCODE_MEDIA_NEXT = 87;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700288 /** Key code constant: Play Previous media key. */
Dianne Hackborn935ae462009-04-13 16:11:55 -0700289 public static final int KEYCODE_MEDIA_PREVIOUS = 88;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700290 /** Key code constant: Rewind media key. */
Dianne Hackborn935ae462009-04-13 16:11:55 -0700291 public static final int KEYCODE_MEDIA_REWIND = 89;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700292 /** Key code constant: Fast Forward media key. */
Dianne Hackborn935ae462009-04-13 16:11:55 -0700293 public static final int KEYCODE_MEDIA_FAST_FORWARD = 90;
Jeff Brownb0418da2010-11-01 15:24:01 -0700294 /** Key code constant: Mute key.
295 * Mutes the microphone, unlike {@link #KEYCODE_VOLUME_MUTE}. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 public static final int KEYCODE_MUTE = 91;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700297 /** Key code constant: Page Up key. */
Chih-Wei Huang4fedd802009-05-27 15:52:50 +0800298 public static final int KEYCODE_PAGE_UP = 92;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700299 /** Key code constant: Page Down key. */
Chih-Wei Huang4fedd802009-05-27 15:52:50 +0800300 public static final int KEYCODE_PAGE_DOWN = 93;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700301 /** Key code constant: Picture Symbols modifier key.
302 * Used to switch symbol sets (Emoji, Kao-moji). */
mogimob032bc02009-10-03 03:13:56 +0900303 public static final int KEYCODE_PICTSYMBOLS = 94; // switch symbol-sets (Emoji,Kao-moji)
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700304 /** Key code constant: Switch Charset modifier key.
305 * Used to switch character sets (Kanji, Katakana). */
mogimob032bc02009-10-03 03:13:56 +0900306 public static final int KEYCODE_SWITCH_CHARSET = 95; // switch char-sets (Kanji,Katakana)
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700307 /** Key code constant: A Button key.
308 * On a game controller, the A button should be either the button labeled A
Michael Wright6b57bde2013-01-28 20:35:58 -0800309 * or the first button on the bottom row of controller buttons. */
Jeff Brownfd035822010-06-30 16:10:35 -0700310 public static final int KEYCODE_BUTTON_A = 96;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700311 /** Key code constant: B Button key.
312 * On a game controller, the B button should be either the button labeled B
Michael Wright6b57bde2013-01-28 20:35:58 -0800313 * or the second button on the bottom row of controller buttons. */
Jeff Brownfd035822010-06-30 16:10:35 -0700314 public static final int KEYCODE_BUTTON_B = 97;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700315 /** Key code constant: C Button key.
316 * On a game controller, the C button should be either the button labeled C
Michael Wright6b57bde2013-01-28 20:35:58 -0800317 * or the third button on the bottom row of controller buttons. */
Jeff Brownfd035822010-06-30 16:10:35 -0700318 public static final int KEYCODE_BUTTON_C = 98;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700319 /** Key code constant: X Button key.
320 * On a game controller, the X button should be either the button labeled X
Michael Wright6b57bde2013-01-28 20:35:58 -0800321 * or the first button on the upper row of controller buttons. */
Jeff Brownfd035822010-06-30 16:10:35 -0700322 public static final int KEYCODE_BUTTON_X = 99;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700323 /** Key code constant: Y Button key.
324 * On a game controller, the Y button should be either the button labeled Y
Michael Wright6b57bde2013-01-28 20:35:58 -0800325 * or the second button on the upper row of controller buttons. */
Jeff Brownfd035822010-06-30 16:10:35 -0700326 public static final int KEYCODE_BUTTON_Y = 100;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700327 /** Key code constant: Z Button key.
328 * On a game controller, the Z button should be either the button labeled Z
Michael Wright6b57bde2013-01-28 20:35:58 -0800329 * or the third button on the upper row of controller buttons. */
Jeff Brownfd035822010-06-30 16:10:35 -0700330 public static final int KEYCODE_BUTTON_Z = 101;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700331 /** Key code constant: L1 Button key.
332 * On a game controller, the L1 button should be either the button labeled L1 (or L)
333 * or the top left trigger button. */
Jeff Brownfd035822010-06-30 16:10:35 -0700334 public static final int KEYCODE_BUTTON_L1 = 102;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700335 /** Key code constant: R1 Button key.
336 * On a game controller, the R1 button should be either the button labeled R1 (or R)
337 * or the top right trigger button. */
Jeff Brownfd035822010-06-30 16:10:35 -0700338 public static final int KEYCODE_BUTTON_R1 = 103;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700339 /** Key code constant: L2 Button key.
340 * On a game controller, the L2 button should be either the button labeled L2
341 * or the bottom left trigger button. */
Jeff Brownfd035822010-06-30 16:10:35 -0700342 public static final int KEYCODE_BUTTON_L2 = 104;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700343 /** Key code constant: R2 Button key.
344 * On a game controller, the R2 button should be either the button labeled R2
345 * or the bottom right trigger button. */
Jeff Brownfd035822010-06-30 16:10:35 -0700346 public static final int KEYCODE_BUTTON_R2 = 105;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700347 /** Key code constant: Left Thumb Button key.
348 * On a game controller, the left thumb button indicates that the left (or only)
349 * joystick is pressed. */
Jeff Brownfd035822010-06-30 16:10:35 -0700350 public static final int KEYCODE_BUTTON_THUMBL = 106;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700351 /** Key code constant: Right Thumb Button key.
352 * On a game controller, the right thumb button indicates that the right
353 * joystick is pressed. */
Jeff Brownfd035822010-06-30 16:10:35 -0700354 public static final int KEYCODE_BUTTON_THUMBR = 107;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700355 /** Key code constant: Start Button key.
356 * On a game controller, the button labeled Start. */
Jeff Brownfd035822010-06-30 16:10:35 -0700357 public static final int KEYCODE_BUTTON_START = 108;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700358 /** Key code constant: Select Button key.
359 * On a game controller, the button labeled Select. */
Jeff Brownfd035822010-06-30 16:10:35 -0700360 public static final int KEYCODE_BUTTON_SELECT = 109;
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700361 /** Key code constant: Mode Button key.
362 * On a game controller, the button labeled Mode. */
Jeff Brownfd035822010-06-30 16:10:35 -0700363 public static final int KEYCODE_BUTTON_MODE = 110;
Jeff Brown497a92c2010-09-12 17:55:08 -0700364 /** Key code constant: Escape key. */
365 public static final int KEYCODE_ESCAPE = 111;
366 /** Key code constant: Forward Delete key.
367 * Deletes characters ahead of the insertion point, unlike {@link #KEYCODE_DEL}. */
368 public static final int KEYCODE_FORWARD_DEL = 112;
369 /** Key code constant: Left Control modifier key. */
370 public static final int KEYCODE_CTRL_LEFT = 113;
371 /** Key code constant: Right Control modifier key. */
372 public static final int KEYCODE_CTRL_RIGHT = 114;
Jeff Brown28cbf4b2010-12-13 10:33:20 -0800373 /** Key code constant: Caps Lock key. */
Jeff Brown497a92c2010-09-12 17:55:08 -0700374 public static final int KEYCODE_CAPS_LOCK = 115;
375 /** Key code constant: Scroll Lock key. */
376 public static final int KEYCODE_SCROLL_LOCK = 116;
377 /** Key code constant: Left Meta modifier key. */
378 public static final int KEYCODE_META_LEFT = 117;
379 /** Key code constant: Right Meta modifier key. */
380 public static final int KEYCODE_META_RIGHT = 118;
381 /** Key code constant: Function modifier key. */
382 public static final int KEYCODE_FUNCTION = 119;
383 /** Key code constant: System Request / Print Screen key. */
384 public static final int KEYCODE_SYSRQ = 120;
385 /** Key code constant: Break / Pause key. */
386 public static final int KEYCODE_BREAK = 121;
387 /** Key code constant: Home Movement key.
388 * Used for scrolling or moving the cursor around to the start of a line
389 * or to the top of a list. */
390 public static final int KEYCODE_MOVE_HOME = 122;
391 /** Key code constant: End Movement key.
392 * Used for scrolling or moving the cursor around to the end of a line
393 * or to the bottom of a list. */
394 public static final int KEYCODE_MOVE_END = 123;
395 /** Key code constant: Insert key.
396 * Toggles insert / overwrite edit mode. */
397 public static final int KEYCODE_INSERT = 124;
398 /** Key code constant: Forward key.
399 * Navigates forward in the history stack. Complement of {@link #KEYCODE_BACK}. */
400 public static final int KEYCODE_FORWARD = 125;
401 /** Key code constant: Play media key. */
402 public static final int KEYCODE_MEDIA_PLAY = 126;
403 /** Key code constant: Pause media key. */
404 public static final int KEYCODE_MEDIA_PAUSE = 127;
405 /** Key code constant: Close media key.
406 * May be used to close a CD tray, for example. */
407 public static final int KEYCODE_MEDIA_CLOSE = 128;
408 /** Key code constant: Eject media key.
409 * May be used to eject a CD tray, for example. */
410 public static final int KEYCODE_MEDIA_EJECT = 129;
411 /** Key code constant: Record media key. */
412 public static final int KEYCODE_MEDIA_RECORD = 130;
413 /** Key code constant: F1 key. */
414 public static final int KEYCODE_F1 = 131;
415 /** Key code constant: F2 key. */
416 public static final int KEYCODE_F2 = 132;
417 /** Key code constant: F3 key. */
418 public static final int KEYCODE_F3 = 133;
419 /** Key code constant: F4 key. */
420 public static final int KEYCODE_F4 = 134;
421 /** Key code constant: F5 key. */
422 public static final int KEYCODE_F5 = 135;
423 /** Key code constant: F6 key. */
424 public static final int KEYCODE_F6 = 136;
425 /** Key code constant: F7 key. */
426 public static final int KEYCODE_F7 = 137;
427 /** Key code constant: F8 key. */
428 public static final int KEYCODE_F8 = 138;
429 /** Key code constant: F9 key. */
430 public static final int KEYCODE_F9 = 139;
431 /** Key code constant: F10 key. */
432 public static final int KEYCODE_F10 = 140;
433 /** Key code constant: F11 key. */
434 public static final int KEYCODE_F11 = 141;
435 /** Key code constant: F12 key. */
436 public static final int KEYCODE_F12 = 142;
Jeff Brown28cbf4b2010-12-13 10:33:20 -0800437 /** Key code constant: Num Lock key.
Jeff Brown497a92c2010-09-12 17:55:08 -0700438 * This is the Num Lock key; it is different from {@link #KEYCODE_NUM}.
Jeff Brown28cbf4b2010-12-13 10:33:20 -0800439 * This key alters the behavior of other keys on the numeric keypad. */
Jeff Brown497a92c2010-09-12 17:55:08 -0700440 public static final int KEYCODE_NUM_LOCK = 143;
441 /** Key code constant: Numeric keypad '0' key. */
442 public static final int KEYCODE_NUMPAD_0 = 144;
443 /** Key code constant: Numeric keypad '1' key. */
444 public static final int KEYCODE_NUMPAD_1 = 145;
445 /** Key code constant: Numeric keypad '2' key. */
446 public static final int KEYCODE_NUMPAD_2 = 146;
447 /** Key code constant: Numeric keypad '3' key. */
448 public static final int KEYCODE_NUMPAD_3 = 147;
449 /** Key code constant: Numeric keypad '4' key. */
450 public static final int KEYCODE_NUMPAD_4 = 148;
451 /** Key code constant: Numeric keypad '5' key. */
452 public static final int KEYCODE_NUMPAD_5 = 149;
453 /** Key code constant: Numeric keypad '6' key. */
454 public static final int KEYCODE_NUMPAD_6 = 150;
455 /** Key code constant: Numeric keypad '7' key. */
456 public static final int KEYCODE_NUMPAD_7 = 151;
457 /** Key code constant: Numeric keypad '8' key. */
458 public static final int KEYCODE_NUMPAD_8 = 152;
459 /** Key code constant: Numeric keypad '9' key. */
460 public static final int KEYCODE_NUMPAD_9 = 153;
461 /** Key code constant: Numeric keypad '/' key (for division). */
462 public static final int KEYCODE_NUMPAD_DIVIDE = 154;
463 /** Key code constant: Numeric keypad '*' key (for multiplication). */
464 public static final int KEYCODE_NUMPAD_MULTIPLY = 155;
465 /** Key code constant: Numeric keypad '-' key (for subtraction). */
466 public static final int KEYCODE_NUMPAD_SUBTRACT = 156;
467 /** Key code constant: Numeric keypad '+' key (for addition). */
468 public static final int KEYCODE_NUMPAD_ADD = 157;
469 /** Key code constant: Numeric keypad '.' key (for decimals or digit grouping). */
470 public static final int KEYCODE_NUMPAD_DOT = 158;
471 /** Key code constant: Numeric keypad ',' key (for decimals or digit grouping). */
472 public static final int KEYCODE_NUMPAD_COMMA = 159;
473 /** Key code constant: Numeric keypad Enter key. */
474 public static final int KEYCODE_NUMPAD_ENTER = 160;
475 /** Key code constant: Numeric keypad '=' key. */
476 public static final int KEYCODE_NUMPAD_EQUALS = 161;
477 /** Key code constant: Numeric keypad '(' key. */
478 public static final int KEYCODE_NUMPAD_LEFT_PAREN = 162;
479 /** Key code constant: Numeric keypad ')' key. */
480 public static final int KEYCODE_NUMPAD_RIGHT_PAREN = 163;
Jeff Brownb0418da2010-11-01 15:24:01 -0700481 /** Key code constant: Volume Mute key.
482 * Mutes the speaker, unlike {@link #KEYCODE_MUTE}.
483 * This key should normally be implemented as a toggle such that the first press
484 * mutes the speaker and the second press restores the original volume. */
485 public static final int KEYCODE_VOLUME_MUTE = 164;
Jason Bayer3adf4902010-11-09 14:54:55 -0800486 /** Key code constant: Info key.
487 * Common on TV remotes to show additional information related to what is
488 * currently being viewed. */
489 public static final int KEYCODE_INFO = 165;
490 /** Key code constant: Channel up key.
491 * On TV remotes, increments the television channel. */
492 public static final int KEYCODE_CHANNEL_UP = 166;
493 /** Key code constant: Channel down key.
494 * On TV remotes, decrements the television channel. */
495 public static final int KEYCODE_CHANNEL_DOWN = 167;
496 /** Key code constant: Zoom in key. */
497 public static final int KEYCODE_ZOOM_IN = 168;
498 /** Key code constant: Zoom out key. */
499 public static final int KEYCODE_ZOOM_OUT = 169;
500 /** Key code constant: TV key.
501 * On TV remotes, switches to viewing live TV. */
502 public static final int KEYCODE_TV = 170;
503 /** Key code constant: Window key.
Julius D'souza03d4a652017-04-03 10:16:51 -0700504 * On TV remotes, toggles picture-in-picture mode or other windowing functions.
505 * On Android Wear devices, triggers a display offset. */
Jason Bayer3adf4902010-11-09 14:54:55 -0800506 public static final int KEYCODE_WINDOW = 171;
507 /** Key code constant: Guide key.
508 * On TV remotes, shows a programming guide. */
509 public static final int KEYCODE_GUIDE = 172;
510 /** Key code constant: DVR key.
511 * On some TV remotes, switches to a DVR mode for recorded shows. */
512 public static final int KEYCODE_DVR = 173;
513 /** Key code constant: Bookmark key.
514 * On some TV remotes, bookmarks content or web pages. */
515 public static final int KEYCODE_BOOKMARK = 174;
516 /** Key code constant: Toggle captions key.
517 * Switches the mode for closed-captioning text, for example during television shows. */
518 public static final int KEYCODE_CAPTIONS = 175;
519 /** Key code constant: Settings key.
520 * Starts the system settings activity. */
521 public static final int KEYCODE_SETTINGS = 176;
522 /** Key code constant: TV power key.
523 * On TV remotes, toggles the power on a television screen. */
524 public static final int KEYCODE_TV_POWER = 177;
525 /** Key code constant: TV input key.
526 * On TV remotes, switches the input on a television screen. */
527 public static final int KEYCODE_TV_INPUT = 178;
528 /** Key code constant: Set-top-box power key.
529 * On TV remotes, toggles the power on an external Set-top-box. */
530 public static final int KEYCODE_STB_POWER = 179;
531 /** Key code constant: Set-top-box input key.
532 * On TV remotes, switches the input mode on an external Set-top-box. */
533 public static final int KEYCODE_STB_INPUT = 180;
534 /** Key code constant: A/V Receiver power key.
535 * On TV remotes, toggles the power on an external A/V Receiver. */
536 public static final int KEYCODE_AVR_POWER = 181;
537 /** Key code constant: A/V Receiver input key.
538 * On TV remotes, switches the input mode on an external A/V Receiver. */
539 public static final int KEYCODE_AVR_INPUT = 182;
540 /** Key code constant: Red "programmable" key.
541 * On TV remotes, acts as a contextual/programmable key. */
542 public static final int KEYCODE_PROG_RED = 183;
543 /** Key code constant: Green "programmable" key.
544 * On TV remotes, actsas a contextual/programmable key. */
545 public static final int KEYCODE_PROG_GREEN = 184;
546 /** Key code constant: Yellow "programmable" key.
547 * On TV remotes, acts as a contextual/programmable key. */
548 public static final int KEYCODE_PROG_YELLOW = 185;
549 /** Key code constant: Blue "programmable" key.
550 * On TV remotes, acts as a contextual/programmable key. */
551 public static final int KEYCODE_PROG_BLUE = 186;
Jeff Brown49ed71d2010-12-06 17:13:33 -0800552 /** Key code constant: App switch key.
553 * Should bring up the application switcher dialog. */
554 public static final int KEYCODE_APP_SWITCH = 187;
Jeff Browncb1404e2011-01-15 18:14:15 -0800555 /** Key code constant: Generic Game Pad Button #1.*/
556 public static final int KEYCODE_BUTTON_1 = 188;
557 /** Key code constant: Generic Game Pad Button #2.*/
558 public static final int KEYCODE_BUTTON_2 = 189;
559 /** Key code constant: Generic Game Pad Button #3.*/
560 public static final int KEYCODE_BUTTON_3 = 190;
561 /** Key code constant: Generic Game Pad Button #4.*/
562 public static final int KEYCODE_BUTTON_4 = 191;
563 /** Key code constant: Generic Game Pad Button #5.*/
564 public static final int KEYCODE_BUTTON_5 = 192;
565 /** Key code constant: Generic Game Pad Button #6.*/
566 public static final int KEYCODE_BUTTON_6 = 193;
567 /** Key code constant: Generic Game Pad Button #7.*/
568 public static final int KEYCODE_BUTTON_7 = 194;
569 /** Key code constant: Generic Game Pad Button #8.*/
570 public static final int KEYCODE_BUTTON_8 = 195;
571 /** Key code constant: Generic Game Pad Button #9.*/
572 public static final int KEYCODE_BUTTON_9 = 196;
573 /** Key code constant: Generic Game Pad Button #10.*/
574 public static final int KEYCODE_BUTTON_10 = 197;
575 /** Key code constant: Generic Game Pad Button #11.*/
576 public static final int KEYCODE_BUTTON_11 = 198;
577 /** Key code constant: Generic Game Pad Button #12.*/
578 public static final int KEYCODE_BUTTON_12 = 199;
579 /** Key code constant: Generic Game Pad Button #13.*/
580 public static final int KEYCODE_BUTTON_13 = 200;
581 /** Key code constant: Generic Game Pad Button #14.*/
582 public static final int KEYCODE_BUTTON_14 = 201;
583 /** Key code constant: Generic Game Pad Button #15.*/
584 public static final int KEYCODE_BUTTON_15 = 202;
585 /** Key code constant: Generic Game Pad Button #16.*/
586 public static final int KEYCODE_BUTTON_16 = 203;
Jeff Brown9812aed2011-03-07 17:09:51 -0800587 /** Key code constant: Language Switch key.
588 * Toggles the current input language such as switching between English and Japanese on
589 * a QWERTY keyboard. On some devices, the same function may be performed by
590 * pressing Shift+Spacebar. */
591 public static final int KEYCODE_LANGUAGE_SWITCH = 204;
592 /** Key code constant: Manner Mode key.
593 * Toggles silent or vibrate mode on and off to make the device behave more politely
594 * in certain settings such as on a crowded train. On some devices, the key may only
595 * operate when long-pressed. */
596 public static final int KEYCODE_MANNER_MODE = 205;
597 /** Key code constant: 3D Mode key.
598 * Toggles the display between 2D and 3D mode. */
599 public static final int KEYCODE_3D_MODE = 206;
Jeff Brown6651a632011-11-28 12:59:11 -0800600 /** Key code constant: Contacts special function key.
601 * Used to launch an address book application. */
602 public static final int KEYCODE_CONTACTS = 207;
603 /** Key code constant: Calendar special function key.
604 * Used to launch a calendar application. */
605 public static final int KEYCODE_CALENDAR = 208;
606 /** Key code constant: Music special function key.
607 * Used to launch a music player application. */
608 public static final int KEYCODE_MUSIC = 209;
609 /** Key code constant: Calculator special function key.
610 * Used to launch a calculator application. */
611 public static final int KEYCODE_CALCULATOR = 210;
Yang Chuang7511f9c2012-02-10 15:18:26 +0800612 /** Key code constant: Japanese full-width / half-width key. */
613 public static final int KEYCODE_ZENKAKU_HANKAKU = 211;
614 /** Key code constant: Japanese alphanumeric key. */
615 public static final int KEYCODE_EISU = 212;
616 /** Key code constant: Japanese non-conversion key. */
617 public static final int KEYCODE_MUHENKAN = 213;
618 /** Key code constant: Japanese conversion key. */
619 public static final int KEYCODE_HENKAN = 214;
620 /** Key code constant: Japanese katakana / hiragana key. */
621 public static final int KEYCODE_KATAKANA_HIRAGANA = 215;
622 /** Key code constant: Japanese Yen key. */
623 public static final int KEYCODE_YEN = 216;
624 /** Key code constant: Japanese Ro key. */
625 public static final int KEYCODE_RO = 217;
626 /** Key code constant: Japanese kana key. */
627 public static final int KEYCODE_KANA = 218;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700628 /** Key code constant: Assist key.
629 * Launches the global assist activity. Not delivered to applications. */
630 public static final int KEYCODE_ASSIST = 219;
Michael Wright1df477a2013-01-31 16:19:18 -0800631 /** Key code constant: Brightness Down key.
632 * Adjusts the screen brightness down. */
633 public static final int KEYCODE_BRIGHTNESS_DOWN = 220;
634 /** Key code constant: Brightness Up key.
635 * Adjusts the screen brightness up. */
636 public static final int KEYCODE_BRIGHTNESS_UP = 221;
Jeff Brown6212a492014-03-07 13:58:47 -0800637 /** Key code constant: Audio Track key.
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +0900638 * Switches the audio tracks. */
639 public static final int KEYCODE_MEDIA_AUDIO_TRACK = 222;
Jeff Brown6212a492014-03-07 13:58:47 -0800640 /** Key code constant: Sleep key.
641 * Puts the device to sleep. Behaves somewhat like {@link #KEYCODE_POWER} but it
642 * has no effect if the device is already asleep. */
643 public static final int KEYCODE_SLEEP = 223;
644 /** Key code constant: Wakeup key.
645 * Wakes up the device. Behaves somewhat like {@link #KEYCODE_POWER} but it
646 * has no effect if the device is already awake. */
647 public static final int KEYCODE_WAKEUP = 224;
Tim Kilbourn87cd0dc2014-04-14 15:37:51 -0700648 /** Key code constant: Pairing key.
649 * Initiates peripheral pairing mode. Useful for pairing remote control
650 * devices or game controllers, especially if no other input mode is
651 * available. */
652 public static final int KEYCODE_PAIRING = 225;
Jinsuk Kim96658f72014-05-14 15:33:43 +0900653 /** Key code constant: Media Top Menu key.
654 * Goes to the top of media menu. */
655 public static final int KEYCODE_MEDIA_TOP_MENU = 226;
656 /** Key code constant: '11' key. */
657 public static final int KEYCODE_11 = 227;
658 /** Key code constant: '12' key. */
659 public static final int KEYCODE_12 = 228;
660 /** Key code constant: Last Channel key.
661 * Goes to the last viewed channel. */
662 public static final int KEYCODE_LAST_CHANNEL = 229;
663 /** Key code constant: TV data service key.
664 * Displays data services like weather, sports. */
665 public static final int KEYCODE_TV_DATA_SERVICE = 230;
Michael Wrightdc63f7b2014-08-21 19:05:21 -0700666 /** Key code constant: Voice Assist key.
667 * Launches the global voice assist activity. Not delivered to applications. */
668 public static final int KEYCODE_VOICE_ASSIST = 231;
ASAZU, Hidekidbd6aba2014-08-27 18:03:30 +0900669 /** Key code constant: Radio key.
670 * Toggles TV service / Radio service. */
671 public static final int KEYCODE_TV_RADIO_SERVICE = 232;
672 /** Key code constant: Teletext key.
673 * Displays Teletext service. */
674 public static final int KEYCODE_TV_TELETEXT = 233;
675 /** Key code constant: Number entry key.
676 * Initiates to enter multi-digit channel nubmber when each digit key is assigned
677 * for selecting separate channel. Corresponds to Number Entry Mode (0x1D) of CEC
678 * User Control Code. */
679 public static final int KEYCODE_TV_NUMBER_ENTRY = 234;
680 /** Key code constant: Analog Terrestrial key.
681 * Switches to analog terrestrial broadcast service. */
682 public static final int KEYCODE_TV_TERRESTRIAL_ANALOG = 235;
683 /** Key code constant: Digital Terrestrial key.
684 * Switches to digital terrestrial broadcast service. */
685 public static final int KEYCODE_TV_TERRESTRIAL_DIGITAL = 236;
686 /** Key code constant: Satellite key.
687 * Switches to digital satellite broadcast service. */
688 public static final int KEYCODE_TV_SATELLITE = 237;
689 /** Key code constant: BS key.
690 * Switches to BS digital satellite broadcasting service available in Japan. */
691 public static final int KEYCODE_TV_SATELLITE_BS = 238;
692 /** Key code constant: CS key.
693 * Switches to CS digital satellite broadcasting service available in Japan. */
694 public static final int KEYCODE_TV_SATELLITE_CS = 239;
695 /** Key code constant: BS/CS key.
696 * Toggles between BS and CS digital satellite services. */
697 public static final int KEYCODE_TV_SATELLITE_SERVICE = 240;
698 /** Key code constant: Toggle Network key.
699 * Toggles selecting broacast services. */
700 public static final int KEYCODE_TV_NETWORK = 241;
701 /** Key code constant: Antenna/Cable key.
702 * Toggles broadcast input source between antenna and cable. */
703 public static final int KEYCODE_TV_ANTENNA_CABLE = 242;
704 /** Key code constant: HDMI #1 key.
705 * Switches to HDMI input #1. */
706 public static final int KEYCODE_TV_INPUT_HDMI_1 = 243;
707 /** Key code constant: HDMI #2 key.
708 * Switches to HDMI input #2. */
709 public static final int KEYCODE_TV_INPUT_HDMI_2 = 244;
710 /** Key code constant: HDMI #3 key.
711 * Switches to HDMI input #3. */
712 public static final int KEYCODE_TV_INPUT_HDMI_3 = 245;
713 /** Key code constant: HDMI #4 key.
714 * Switches to HDMI input #4. */
715 public static final int KEYCODE_TV_INPUT_HDMI_4 = 246;
716 /** Key code constant: Composite #1 key.
717 * Switches to composite video input #1. */
718 public static final int KEYCODE_TV_INPUT_COMPOSITE_1 = 247;
719 /** Key code constant: Composite #2 key.
720 * Switches to composite video input #2. */
721 public static final int KEYCODE_TV_INPUT_COMPOSITE_2 = 248;
722 /** Key code constant: Component #1 key.
723 * Switches to component video input #1. */
724 public static final int KEYCODE_TV_INPUT_COMPONENT_1 = 249;
725 /** Key code constant: Component #2 key.
726 * Switches to component video input #2. */
727 public static final int KEYCODE_TV_INPUT_COMPONENT_2 = 250;
728 /** Key code constant: VGA #1 key.
729 * Switches to VGA (analog RGB) input #1. */
730 public static final int KEYCODE_TV_INPUT_VGA_1 = 251;
731 /** Key code constant: Audio description key.
732 * Toggles audio description off / on. */
733 public static final int KEYCODE_TV_AUDIO_DESCRIPTION = 252;
734 /** Key code constant: Audio description mixing volume up key.
735 * Louden audio description volume as compared with normal audio volume. */
736 public static final int KEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP = 253;
737 /** Key code constant: Audio description mixing volume down key.
738 * Lessen audio description volume as compared with normal audio volume. */
739 public static final int KEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN = 254;
740 /** Key code constant: Zoom mode key.
741 * Changes Zoom mode (Normal, Full, Zoom, Wide-zoom, etc.) */
742 public static final int KEYCODE_TV_ZOOM_MODE = 255;
743 /** Key code constant: Contents menu key.
744 * Goes to the title list. Corresponds to Contents Menu (0x0B) of CEC User Control
745 * Code */
746 public static final int KEYCODE_TV_CONTENTS_MENU = 256;
747 /** Key code constant: Media context menu key.
748 * Goes to the context menu of media contents. Corresponds to Media Context-sensitive
749 * Menu (0x11) of CEC User Control Code. */
750 public static final int KEYCODE_TV_MEDIA_CONTEXT_MENU = 257;
751 /** Key code constant: Timer programming key.
752 * Goes to the timer recording menu. Corresponds to Timer Programming (0x54) of
753 * CEC User Control Code. */
754 public static final int KEYCODE_TV_TIMER_PROGRAMMING = 258;
755 /** Key code constant: Help key. */
756 public static final int KEYCODE_HELP = 259;
Michael Wright962c9532015-08-06 15:16:22 +0100757 /** Key code constant: Navigate to previous key.
Joseph Cooper55b9ed42015-04-15 16:21:58 -0700758 * Goes backward by one item in an ordered collection of items. */
759 public static final int KEYCODE_NAVIGATE_PREVIOUS = 260;
Michael Wright962c9532015-08-06 15:16:22 +0100760 /** Key code constant: Navigate to next key.
Joseph Cooper55b9ed42015-04-15 16:21:58 -0700761 * Advances to the next item in an ordered collection of items. */
762 public static final int KEYCODE_NAVIGATE_NEXT = 261;
763 /** Key code constant: Navigate in key.
Michael Wright962c9532015-08-06 15:16:22 +0100764 * Activates the item that currently has focus or expands to the next level of a navigation
Joseph Cooper55b9ed42015-04-15 16:21:58 -0700765 * hierarchy. */
766 public static final int KEYCODE_NAVIGATE_IN = 262;
767 /** Key code constant: Navigate out key.
Michael Wright962c9532015-08-06 15:16:22 +0100768 * Backs out one level of a navigation hierarchy or collapses the item that currently has
Joseph Cooper55b9ed42015-04-15 16:21:58 -0700769 * focus. */
770 public static final int KEYCODE_NAVIGATE_OUT = 263;
Anthony Hugh9d826682015-06-23 10:44:17 -0700771 /** Key code constant: Primary stem key for Wear
772 * Main power/reset button on watch. */
773 public static final int KEYCODE_STEM_PRIMARY = 264;
774 /** Key code constant: Generic stem key 1 for Wear */
775 public static final int KEYCODE_STEM_1 = 265;
776 /** Key code constant: Generic stem key 2 for Wear */
777 public static final int KEYCODE_STEM_2 = 266;
778 /** Key code constant: Generic stem key 3 for Wear */
779 public static final int KEYCODE_STEM_3 = 267;
David Stevensa487f0c2015-07-31 11:00:50 -0700780 /** Key code constant: Directional Pad Up-Left */
781 public static final int KEYCODE_DPAD_UP_LEFT = 268;
782 /** Key code constant: Directional Pad Down-Left */
783 public static final int KEYCODE_DPAD_DOWN_LEFT = 269;
784 /** Key code constant: Directional Pad Up-Right */
785 public static final int KEYCODE_DPAD_UP_RIGHT = 270;
786 /** Key code constant: Directional Pad Down-Right */
787 public static final int KEYCODE_DPAD_DOWN_RIGHT = 271;
Michael Wright962c9532015-08-06 15:16:22 +0100788 /** Key code constant: Skip forward media key. */
789 public static final int KEYCODE_MEDIA_SKIP_FORWARD = 272;
790 /** Key code constant: Skip backward media key. */
791 public static final int KEYCODE_MEDIA_SKIP_BACKWARD = 273;
792 /** Key code constant: Step forward media key.
793 * Steps media forward, one frame at a time. */
794 public static final int KEYCODE_MEDIA_STEP_FORWARD = 274;
795 /** Key code constant: Step backward media key.
796 * Steps media backward, one frame at a time. */
797 public static final int KEYCODE_MEDIA_STEP_BACKWARD = 275;
Nick Armstrong-Crews3a5a8c72015-09-09 09:25:03 -0700798 /** Key code constant: put device to sleep unless a wakelock is held. */
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -0700799 public static final int KEYCODE_SOFT_SLEEP = 276;
Michael Wrightea84cff2015-10-21 18:08:30 +0100800 /** Key code constant: Cut key. */
801 public static final int KEYCODE_CUT = 277;
802 /** Key code constant: Copy key. */
803 public static final int KEYCODE_COPY = 278;
804 /** Key code constant: Paste key. */
805 public static final int KEYCODE_PASTE = 279;
Jim Miller07e03842016-06-22 15:18:13 -0700806 /** Key code constant: Consumed by the system for navigation up */
807 public static final int KEYCODE_SYSTEM_NAVIGATION_UP = 280;
808 /** Key code constant: Consumed by the system for navigation down */
809 public static final int KEYCODE_SYSTEM_NAVIGATION_DOWN = 281;
810 /** Key code constant: Consumed by the system for navigation left*/
811 public static final int KEYCODE_SYSTEM_NAVIGATION_LEFT = 282;
812 /** Key code constant: Consumed by the system for navigation right */
813 public static final int KEYCODE_SYSTEM_NAVIGATION_RIGHT = 283;
Sujith Ramakrishnand2c9bc82017-11-02 09:54:16 -0700814 /** Key code constant: Show all apps */
Sujith Ramakrishnanf8942c02017-07-18 18:35:14 -0700815 public static final int KEYCODE_ALL_APPS = 284;
Yuichiro Hanadac1415f32018-01-15 22:36:00 +0900816 /** Key code constant: Refresh key. */
817 public static final int KEYCODE_REFRESH = 285;
Oleg Kibirevcdd17b52018-11-07 12:02:21 -0800818 /** Key code constant: Thumbs up key. Apps can use this to let user upvote content. */
819 public static final int KEYCODE_THUMBS_UP = 286;
820 /** Key code constant: Thumbs down key. Apps can use this to let user downvote content. */
821 public static final int KEYCODE_THUMBS_DOWN = 287;
Oleg Kibirev6ad1ff12019-01-03 15:05:11 -0800822 /**
823 * Key code constant: Used to switch current {@link android.accounts.Account} that is
824 * consuming content. May be consumed by system to set account globally.
825 */
Oleg Kibirevcdd17b52018-11-07 12:02:21 -0800826 public static final int KEYCODE_PROFILE_SWITCH = 288;
Jeff Brown497a92c2010-09-12 17:55:08 -0700827
Siarhei Vishniakoude1f9042018-05-09 09:54:43 -0700828 /**
829 * Integer value of the last KEYCODE. Increases as new keycodes are added to KeyEvent.
830 * @hide
831 */
832 @TestApi
Oleg Kibirevcdd17b52018-11-07 12:02:21 -0800833 public static final int LAST_KEYCODE = KEYCODE_PROFILE_SWITCH;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834
835 // NOTE: If you add a new keycode here you must also add it to:
836 // isSystem()
Michael Wrightdc63f7b2014-08-21 19:05:21 -0700837 // isWakeKey()
Chirayu Desai61c37ae2013-04-15 20:11:37 +0530838 // frameworks/native/include/android/keycodes.h
Jinsuk Kim96658f72014-05-14 15:33:43 +0900839 // frameworks/native/include/input/InputEventLabels.h
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 // frameworks/base/core/res/res/values/attrs.xml
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 // emulator?
Jeff Brown6651a632011-11-28 12:59:11 -0800842 // LAST_KEYCODE
Dianne Hackborn935ae462009-04-13 16:11:55 -0700843 //
844 // Also Android currently does not reserve code ranges for vendor-
845 // specific key codes. If you have new key codes to have, you
846 // MUST contribute a patch to the open source project to define
847 // those new codes. This is intended to maintain a consistent
848 // set of key code definitions across all Android devices.
Jeff Brown497a92c2010-09-12 17:55:08 -0700849
Jeff Brown497a92c2010-09-12 17:55:08 -0700850 // Symbolic names of all metakeys in bit order from least significant to most significant.
851 // Accordingly there are exactly 32 values in this table.
Mathew Inwooda570dee2018-08-17 14:56:00 +0100852 @UnsupportedAppUsage
Jeff Brown497a92c2010-09-12 17:55:08 -0700853 private static final String[] META_SYMBOLIC_NAMES = new String[] {
854 "META_SHIFT_ON",
855 "META_ALT_ON",
856 "META_SYM_ON",
857 "META_FUNCTION_ON",
858 "META_ALT_LEFT_ON",
859 "META_ALT_RIGHT_ON",
860 "META_SHIFT_LEFT_ON",
861 "META_SHIFT_RIGHT_ON",
862 "META_CAP_LOCKED",
863 "META_ALT_LOCKED",
864 "META_SYM_LOCKED",
865 "0x00000800",
866 "META_CTRL_ON",
867 "META_CTRL_LEFT_ON",
868 "META_CTRL_RIGHT_ON",
869 "0x00008000",
870 "META_META_ON",
871 "META_META_LEFT_ON",
872 "META_META_RIGHT_ON",
873 "0x00080000",
Jeff Brown51e7fe72010-10-29 22:19:53 -0700874 "META_CAPS_LOCK_ON",
875 "META_NUM_LOCK_ON",
876 "META_SCROLL_LOCK_ON",
Jeff Brown497a92c2010-09-12 17:55:08 -0700877 "0x00800000",
878 "0x01000000",
879 "0x02000000",
880 "0x04000000",
881 "0x08000000",
882 "0x10000000",
883 "0x20000000",
884 "0x40000000",
885 "0x80000000",
886 };
887
Michael Wright337d9d22014-04-22 15:03:48 -0700888 private static final String LABEL_PREFIX = "KEYCODE_";
889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890 /**
891 * @deprecated There are now more than MAX_KEYCODE keycodes.
892 * Use {@link #getMaxKeyCode()} instead.
893 */
894 @Deprecated
895 public static final int MAX_KEYCODE = 84;
896
897 /**
898 * {@link #getAction} value: the key has been pressed down.
899 */
900 public static final int ACTION_DOWN = 0;
901 /**
902 * {@link #getAction} value: the key has been released.
903 */
904 public static final int ACTION_UP = 1;
905 /**
Siarhei Vishniakoue481d332018-07-18 14:46:00 +0100906 * @deprecated No longer used by the input system.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 * {@link #getAction} value: multiple duplicate key events have
908 * occurred in a row, or a complex string is being delivered. If the
Andrew Solovay5c05ded2018-10-02 14:14:42 -0700909 * key code is not {@link #KEYCODE_UNKNOWN} then the
910 * {@link #getRepeatCount()} method returns the number of times
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 * the given key code should be executed.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700912 * Otherwise, if the key code is {@link #KEYCODE_UNKNOWN}, then
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 * this is a sequence of characters as returned by {@link #getCharacters}.
914 */
Siarhei Vishniakoue481d332018-07-18 14:46:00 +0100915 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 public static final int ACTION_MULTIPLE = 2;
917
918 /**
Jeff Brown497a92c2010-09-12 17:55:08 -0700919 * SHIFT key locked in CAPS mode.
920 * Reserved for use by {@link MetaKeyKeyListener} for a published constant in its API.
921 * @hide
922 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100923 @UnsupportedAppUsage
Jeff Brown497a92c2010-09-12 17:55:08 -0700924 public static final int META_CAP_LOCKED = 0x100;
925
926 /**
927 * ALT key locked.
928 * Reserved for use by {@link MetaKeyKeyListener} for a published constant in its API.
929 * @hide
930 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100931 @UnsupportedAppUsage
Jeff Brown497a92c2010-09-12 17:55:08 -0700932 public static final int META_ALT_LOCKED = 0x200;
933
934 /**
935 * SYM key locked.
936 * Reserved for use by {@link MetaKeyKeyListener} for a published constant in its API.
937 * @hide
938 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100939 @UnsupportedAppUsage
Jeff Brown497a92c2010-09-12 17:55:08 -0700940 public static final int META_SYM_LOCKED = 0x400;
941
942 /**
943 * Text is in selection mode.
944 * Reserved for use by {@link MetaKeyKeyListener} for a private unpublished constant
945 * in its API that is currently being retained for legacy reasons.
946 * @hide
947 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100948 @UnsupportedAppUsage
Jeff Brown497a92c2010-09-12 17:55:08 -0700949 public static final int META_SELECTING = 0x800;
950
951 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 * <p>This mask is used to check whether one of the ALT meta keys is pressed.</p>
953 *
954 * @see #isAltPressed()
955 * @see #getMetaState()
956 * @see #KEYCODE_ALT_LEFT
957 * @see #KEYCODE_ALT_RIGHT
958 */
959 public static final int META_ALT_ON = 0x02;
960
961 /**
962 * <p>This mask is used to check whether the left ALT meta key is pressed.</p>
963 *
964 * @see #isAltPressed()
965 * @see #getMetaState()
966 * @see #KEYCODE_ALT_LEFT
967 */
968 public static final int META_ALT_LEFT_ON = 0x10;
969
970 /**
971 * <p>This mask is used to check whether the right the ALT meta key is pressed.</p>
972 *
973 * @see #isAltPressed()
974 * @see #getMetaState()
975 * @see #KEYCODE_ALT_RIGHT
976 */
977 public static final int META_ALT_RIGHT_ON = 0x20;
978
979 /**
980 * <p>This mask is used to check whether one of the SHIFT meta keys is pressed.</p>
981 *
982 * @see #isShiftPressed()
983 * @see #getMetaState()
984 * @see #KEYCODE_SHIFT_LEFT
985 * @see #KEYCODE_SHIFT_RIGHT
986 */
987 public static final int META_SHIFT_ON = 0x1;
988
989 /**
990 * <p>This mask is used to check whether the left SHIFT meta key is pressed.</p>
991 *
992 * @see #isShiftPressed()
993 * @see #getMetaState()
994 * @see #KEYCODE_SHIFT_LEFT
995 */
996 public static final int META_SHIFT_LEFT_ON = 0x40;
997
998 /**
999 * <p>This mask is used to check whether the right SHIFT meta key is pressed.</p>
1000 *
1001 * @see #isShiftPressed()
1002 * @see #getMetaState()
1003 * @see #KEYCODE_SHIFT_RIGHT
1004 */
1005 public static final int META_SHIFT_RIGHT_ON = 0x80;
1006
1007 /**
1008 * <p>This mask is used to check whether the SYM meta key is pressed.</p>
1009 *
1010 * @see #isSymPressed()
1011 * @see #getMetaState()
1012 */
1013 public static final int META_SYM_ON = 0x4;
1014
1015 /**
Jeff Brown497a92c2010-09-12 17:55:08 -07001016 * <p>This mask is used to check whether the FUNCTION meta key is pressed.</p>
1017 *
1018 * @see #isFunctionPressed()
1019 * @see #getMetaState()
1020 */
1021 public static final int META_FUNCTION_ON = 0x8;
1022
1023 /**
1024 * <p>This mask is used to check whether one of the CTRL meta keys is pressed.</p>
1025 *
1026 * @see #isCtrlPressed()
1027 * @see #getMetaState()
1028 * @see #KEYCODE_CTRL_LEFT
1029 * @see #KEYCODE_CTRL_RIGHT
1030 */
1031 public static final int META_CTRL_ON = 0x1000;
1032
1033 /**
1034 * <p>This mask is used to check whether the left CTRL meta key is pressed.</p>
1035 *
1036 * @see #isCtrlPressed()
1037 * @see #getMetaState()
1038 * @see #KEYCODE_CTRL_LEFT
1039 */
1040 public static final int META_CTRL_LEFT_ON = 0x2000;
1041
1042 /**
1043 * <p>This mask is used to check whether the right CTRL meta key is pressed.</p>
1044 *
1045 * @see #isCtrlPressed()
1046 * @see #getMetaState()
1047 * @see #KEYCODE_CTRL_RIGHT
1048 */
1049 public static final int META_CTRL_RIGHT_ON = 0x4000;
1050
1051 /**
1052 * <p>This mask is used to check whether one of the META meta keys is pressed.</p>
1053 *
1054 * @see #isMetaPressed()
1055 * @see #getMetaState()
1056 * @see #KEYCODE_META_LEFT
1057 * @see #KEYCODE_META_RIGHT
1058 */
1059 public static final int META_META_ON = 0x10000;
1060
1061 /**
1062 * <p>This mask is used to check whether the left META meta key is pressed.</p>
1063 *
1064 * @see #isMetaPressed()
1065 * @see #getMetaState()
1066 * @see #KEYCODE_META_LEFT
1067 */
1068 public static final int META_META_LEFT_ON = 0x20000;
1069
1070 /**
1071 * <p>This mask is used to check whether the right META meta key is pressed.</p>
1072 *
1073 * @see #isMetaPressed()
1074 * @see #getMetaState()
1075 * @see #KEYCODE_META_RIGHT
1076 */
1077 public static final int META_META_RIGHT_ON = 0x40000;
1078
1079 /**
Jeff Brown51e7fe72010-10-29 22:19:53 -07001080 * <p>This mask is used to check whether the CAPS LOCK meta key is on.</p>
Jeff Brown497a92c2010-09-12 17:55:08 -07001081 *
Jeff Brown51e7fe72010-10-29 22:19:53 -07001082 * @see #isCapsLockOn()
Jeff Brown497a92c2010-09-12 17:55:08 -07001083 * @see #getMetaState()
1084 * @see #KEYCODE_CAPS_LOCK
1085 */
Jeff Brown51e7fe72010-10-29 22:19:53 -07001086 public static final int META_CAPS_LOCK_ON = 0x100000;
Jeff Brown497a92c2010-09-12 17:55:08 -07001087
1088 /**
Jeff Brown51e7fe72010-10-29 22:19:53 -07001089 * <p>This mask is used to check whether the NUM LOCK meta key is on.</p>
Jeff Brown497a92c2010-09-12 17:55:08 -07001090 *
Jeff Brown51e7fe72010-10-29 22:19:53 -07001091 * @see #isNumLockOn()
Jeff Brown497a92c2010-09-12 17:55:08 -07001092 * @see #getMetaState()
1093 * @see #KEYCODE_NUM_LOCK
1094 */
Jeff Brown51e7fe72010-10-29 22:19:53 -07001095 public static final int META_NUM_LOCK_ON = 0x200000;
Jeff Brown497a92c2010-09-12 17:55:08 -07001096
1097 /**
Jeff Brown51e7fe72010-10-29 22:19:53 -07001098 * <p>This mask is used to check whether the SCROLL LOCK meta key is on.</p>
Jeff Brown497a92c2010-09-12 17:55:08 -07001099 *
Jeff Brown51e7fe72010-10-29 22:19:53 -07001100 * @see #isScrollLockOn()
Jeff Brown497a92c2010-09-12 17:55:08 -07001101 * @see #getMetaState()
1102 * @see #KEYCODE_SCROLL_LOCK
1103 */
Jeff Brown51e7fe72010-10-29 22:19:53 -07001104 public static final int META_SCROLL_LOCK_ON = 0x400000;
Jeff Brown497a92c2010-09-12 17:55:08 -07001105
Jeff Brown64da12a2011-01-04 19:57:47 -08001106 /**
1107 * This mask is a combination of {@link #META_SHIFT_ON}, {@link #META_SHIFT_LEFT_ON}
1108 * and {@link #META_SHIFT_RIGHT_ON}.
1109 */
Jeff Brownc1df9072010-12-21 16:38:50 -08001110 public static final int META_SHIFT_MASK = META_SHIFT_ON
1111 | META_SHIFT_LEFT_ON | META_SHIFT_RIGHT_ON;
1112
Jeff Brown64da12a2011-01-04 19:57:47 -08001113 /**
1114 * This mask is a combination of {@link #META_ALT_ON}, {@link #META_ALT_LEFT_ON}
1115 * and {@link #META_ALT_RIGHT_ON}.
1116 */
Jeff Brownc1df9072010-12-21 16:38:50 -08001117 public static final int META_ALT_MASK = META_ALT_ON
1118 | META_ALT_LEFT_ON | META_ALT_RIGHT_ON;
1119
Jeff Brown64da12a2011-01-04 19:57:47 -08001120 /**
1121 * This mask is a combination of {@link #META_CTRL_ON}, {@link #META_CTRL_LEFT_ON}
1122 * and {@link #META_CTRL_RIGHT_ON}.
1123 */
Jeff Brownc1df9072010-12-21 16:38:50 -08001124 public static final int META_CTRL_MASK = META_CTRL_ON
1125 | META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON;
1126
Jeff Brown64da12a2011-01-04 19:57:47 -08001127 /**
1128 * This mask is a combination of {@link #META_META_ON}, {@link #META_META_LEFT_ON}
1129 * and {@link #META_META_RIGHT_ON}.
1130 */
1131 public static final int META_META_MASK = META_META_ON
Jeff Brownc1df9072010-12-21 16:38:50 -08001132 | META_META_LEFT_ON | META_META_RIGHT_ON;
1133
Jeff Brown497a92c2010-09-12 17:55:08 -07001134 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 * This mask is set if the device woke because of this key event.
Jeff Brown037c33e2014-04-09 00:31:55 -07001136 *
1137 * @deprecated This flag will never be set by the system since the system
1138 * consumes all wake keys itself.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 */
Jeff Brown037c33e2014-04-09 00:31:55 -07001140 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 public static final int FLAG_WOKE_HERE = 0x1;
RoboErik01fe6612014-02-13 14:19:04 -08001142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 /**
1144 * This mask is set if the key event was generated by a software keyboard.
1145 */
1146 public static final int FLAG_SOFT_KEYBOARD = 0x2;
RoboErik01fe6612014-02-13 14:19:04 -08001147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 /**
1149 * This mask is set if we don't want the key event to cause us to leave
1150 * touch mode.
1151 */
1152 public static final int FLAG_KEEP_TOUCH_MODE = 0x4;
RoboErik01fe6612014-02-13 14:19:04 -08001153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 /**
The Android Open Source Project10592532009-03-18 17:39:46 -07001155 * This mask is set if an event was known to come from a trusted part
1156 * of the system. That is, the event is known to come from the user,
1157 * and could not have been spoofed by a third party component.
1158 */
1159 public static final int FLAG_FROM_SYSTEM = 0x8;
RoboErik01fe6612014-02-13 14:19:04 -08001160
The Android Open Source Project10592532009-03-18 17:39:46 -07001161 /**
1162 * This mask is used for compatibility, to identify enter keys that are
1163 * coming from an IME whose enter key has been auto-labelled "next" or
1164 * "done". This allows TextView to dispatch these as normal enter keys
1165 * for old applications, but still do the appropriate action when
1166 * receiving them.
1167 */
1168 public static final int FLAG_EDITOR_ACTION = 0x10;
RoboErik01fe6612014-02-13 14:19:04 -08001169
The Android Open Source Project10592532009-03-18 17:39:46 -07001170 /**
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07001171 * When associated with up key events, this indicates that the key press
1172 * has been canceled. Typically this is used with virtual touch screen
1173 * keys, where the user can slide from the virtual key area on to the
1174 * display: in that case, the application will receive a canceled up
1175 * event and should not perform the action normally associated with the
1176 * key. Note that for this to work, the application can not perform an
1177 * action for a key until it receives an up or the long press timeout has
RoboErik01fe6612014-02-13 14:19:04 -08001178 * expired.
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07001179 */
1180 public static final int FLAG_CANCELED = 0x20;
RoboErik01fe6612014-02-13 14:19:04 -08001181
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07001182 /**
1183 * This key event was generated by a virtual (on-screen) hard key area.
1184 * Typically this is an area of the touchscreen, outside of the regular
1185 * display, dedicated to "hardware" buttons.
1186 */
1187 public static final int FLAG_VIRTUAL_HARD_KEY = 0x40;
RoboErik01fe6612014-02-13 14:19:04 -08001188
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07001189 /**
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001190 * This flag is set for the first key repeat that occurs after the
1191 * long press timeout.
1192 */
1193 public static final int FLAG_LONG_PRESS = 0x80;
RoboErik01fe6612014-02-13 14:19:04 -08001194
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001195 /**
1196 * Set when a key event has {@link #FLAG_CANCELED} set because a long
RoboErik01fe6612014-02-13 14:19:04 -08001197 * press action was executed while it was down.
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001198 */
1199 public static final int FLAG_CANCELED_LONG_PRESS = 0x100;
RoboErik01fe6612014-02-13 14:19:04 -08001200
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001201 /**
1202 * Set for {@link #ACTION_UP} when this event's key code is still being
1203 * tracked from its initial down. That is, somebody requested that tracking
1204 * started on the key down and a long press has not caused
1205 * the tracking to be canceled.
1206 */
1207 public static final int FLAG_TRACKING = 0x200;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001208
1209 /**
1210 * Set when a key event has been synthesized to implement default behavior
1211 * for an event that the application did not handle.
1212 * Fallback key events are generated by unhandled trackball motions
1213 * (to emulate a directional keypad) and by certain unhandled key presses
1214 * that are declared in the key map (such as special function numeric keypad
1215 * keys when numlock is off).
1216 */
1217 public static final int FLAG_FALLBACK = 0x400;
1218
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001219 /**
Michael Wrighta44dd262013-04-10 21:12:00 -07001220 * Signifies that the key is being predispatched.
1221 * @hide
1222 */
1223 public static final int FLAG_PREDISPATCH = 0x20000000;
1224
1225 /**
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001226 * Private control to determine when an app is tracking a key sequence.
1227 * @hide
1228 */
1229 public static final int FLAG_START_TRACKING = 0x40000000;
Jeff Brown21bc5c92011-02-28 18:27:14 -08001230
1231 /**
1232 * Private flag that indicates when the system has detected that this key event
1233 * may be inconsistent with respect to the sequence of previously delivered key events,
1234 * such as when a key up event is sent but the key was not down.
1235 *
1236 * @hide
1237 * @see #isTainted
1238 * @see #setTainted
1239 */
1240 public static final int FLAG_TAINTED = 0x80000000;
1241
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001242 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 * Returns the maximum keycode.
1244 */
1245 public static int getMaxKeyCode() {
1246 return LAST_KEYCODE;
1247 }
1248
1249 /**
1250 * Get the character that is produced by putting accent on the character
1251 * c.
1252 * For example, getDeadChar('`', 'e') returns &egrave;.
1253 */
1254 public static int getDeadChar(int accent, int c) {
1255 return KeyCharacterMap.getDeadChar(accent, c);
1256 }
RoboErik01fe6612014-02-13 14:19:04 -08001257
Dianne Hackborn8d374262009-09-14 21:21:52 -07001258 static final boolean DEBUG = false;
1259 static final String TAG = "KeyEvent";
Jeff Brown1f245102010-11-18 20:53:46 -08001260
1261 private static final int MAX_RECYCLED = 10;
1262 private static final Object gRecyclerLock = new Object();
1263 private static int gRecyclerUsed;
1264 private static KeyEvent gRecyclerTop;
1265
1266 private KeyEvent mNext;
Jeff Brown1f245102010-11-18 20:53:46 -08001267
Garfield Tanc8362b22020-01-24 11:32:14 -08001268 private int mId;
Mathew Inwooda570dee2018-08-17 14:56:00 +01001269 @UnsupportedAppUsage
Jeff Brown91c69ab2011-02-14 17:03:18 -08001270 private int mDeviceId;
Mathew Inwood8c854f82018-09-14 12:35:36 +01001271 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Jeff Brown91c69ab2011-02-14 17:03:18 -08001272 private int mSource;
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01001273 private int mDisplayId;
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -06001274 private @Nullable byte[] mHmac;
Mathew Inwooda570dee2018-08-17 14:56:00 +01001275 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 private int mMetaState;
Mathew Inwooda570dee2018-08-17 14:56:00 +01001277 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 private int mAction;
Mathew Inwooda570dee2018-08-17 14:56:00 +01001279 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 private int mKeyCode;
Mathew Inwooda570dee2018-08-17 14:56:00 +01001281 @UnsupportedAppUsage
Jeff Brown46b9ac02010-04-22 18:58:52 -07001282 private int mScanCode;
Mathew Inwooda570dee2018-08-17 14:56:00 +01001283 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001284 private int mRepeatCount;
Mathew Inwooda570dee2018-08-17 14:56:00 +01001285 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001286 private int mFlags;
Mathew Inwooda570dee2018-08-17 14:56:00 +01001287 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001288 private long mDownTime;
Mathew Inwooda570dee2018-08-17 14:56:00 +01001289 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001290 private long mEventTime;
Mathew Inwooda570dee2018-08-17 14:56:00 +01001291 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001292 private String mCharacters;
1293
1294 public interface Callback {
1295 /**
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001296 * Called when a key down event has occurred. If you return true,
1297 * you can first call {@link KeyEvent#startTracking()
1298 * KeyEvent.startTracking()} to have the framework track the event
1299 * through its {@link #onKeyUp(int, KeyEvent)} and also call your
1300 * {@link #onKeyLongPress(int, KeyEvent)} if it occurs.
RoboErik01fe6612014-02-13 14:19:04 -08001301 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001302 * @param keyCode The value in event.getKeyCode().
1303 * @param event Description of the key event.
RoboErik01fe6612014-02-13 14:19:04 -08001304 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 * @return If you handled the event, return true. If you want to allow
1306 * the event to be handled by the next receiver, return false.
1307 */
1308 boolean onKeyDown(int keyCode, KeyEvent event);
1309
1310 /**
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001311 * Called when a long press has occurred. If you return true,
1312 * the final key up will have {@link KeyEvent#FLAG_CANCELED} and
1313 * {@link KeyEvent#FLAG_CANCELED_LONG_PRESS} set. Note that in
1314 * order to receive this callback, someone in the event change
1315 * <em>must</em> return true from {@link #onKeyDown} <em>and</em>
1316 * call {@link KeyEvent#startTracking()} on the event.
RoboErik01fe6612014-02-13 14:19:04 -08001317 *
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001318 * @param keyCode The value in event.getKeyCode().
1319 * @param event Description of the key event.
RoboErik01fe6612014-02-13 14:19:04 -08001320 *
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001321 * @return If you handled the event, return true. If you want to allow
1322 * the event to be handled by the next receiver, return false.
1323 */
1324 boolean onKeyLongPress(int keyCode, KeyEvent event);
1325
1326 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327 * Called when a key up event has occurred.
RoboErik01fe6612014-02-13 14:19:04 -08001328 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 * @param keyCode The value in event.getKeyCode().
1330 * @param event Description of the key event.
RoboErik01fe6612014-02-13 14:19:04 -08001331 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001332 * @return If you handled the event, return true. If you want to allow
1333 * the event to be handled by the next receiver, return false.
1334 */
1335 boolean onKeyUp(int keyCode, KeyEvent event);
1336
1337 /**
Kevin Hufnagleb248b1f2016-09-13 19:36:20 -07001338 * Called when a user's interaction with an analog control, such as
1339 * flinging a trackball, generates simulated down/up events for the same
1340 * key multiple times in quick succession.
RoboErik01fe6612014-02-13 14:19:04 -08001341 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001342 * @param keyCode The value in event.getKeyCode().
1343 * @param count Number of pairs as returned by event.getRepeatCount().
1344 * @param event Description of the key event.
RoboErik01fe6612014-02-13 14:19:04 -08001345 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001346 * @return If you handled the event, return true. If you want to allow
1347 * the event to be handled by the next receiver, return false.
1348 */
1349 boolean onKeyMultiple(int keyCode, int count, KeyEvent event);
1350 }
1351
Michael Wright337d9d22014-04-22 15:03:48 -07001352 private static native String nativeKeyCodeToString(int keyCode);
1353 private static native int nativeKeyCodeFromString(String keyCode);
Garfield Tanc8362b22020-01-24 11:32:14 -08001354 private static native int nativeNextId();
Jeff Brown497a92c2010-09-12 17:55:08 -07001355
Garfield Tanc8362b22020-01-24 11:32:14 -08001356 private KeyEvent() {}
Jeff Brown1f245102010-11-18 20:53:46 -08001357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001358 /**
1359 * Create a new key event.
RoboErik01fe6612014-02-13 14:19:04 -08001360 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 * @param action Action code: either {@link #ACTION_DOWN},
1362 * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}.
1363 * @param code The key code.
1364 */
1365 public KeyEvent(int action, int code) {
Garfield Tanc8362b22020-01-24 11:32:14 -08001366 mId = nativeNextId();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001367 mAction = action;
1368 mKeyCode = code;
1369 mRepeatCount = 0;
Jeff Brown6b53e8d2010-11-10 16:03:06 -08001370 mDeviceId = KeyCharacterMap.VIRTUAL_KEYBOARD;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 }
1372
1373 /**
1374 * Create a new key event.
RoboErik01fe6612014-02-13 14:19:04 -08001375 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001376 * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis})
1377 * at which this key code originally went down.
1378 * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis})
1379 * at which this event happened.
1380 * @param action Action code: either {@link #ACTION_DOWN},
1381 * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}.
1382 * @param code The key code.
1383 * @param repeat A repeat count for down events (> 0 if this is after the
1384 * initial down) or event count for multiple events.
1385 */
1386 public KeyEvent(long downTime, long eventTime, int action,
1387 int code, int repeat) {
Garfield Tanc8362b22020-01-24 11:32:14 -08001388 mId = nativeNextId();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001389 mDownTime = downTime;
1390 mEventTime = eventTime;
1391 mAction = action;
1392 mKeyCode = code;
1393 mRepeatCount = repeat;
Jeff Brown6b53e8d2010-11-10 16:03:06 -08001394 mDeviceId = KeyCharacterMap.VIRTUAL_KEYBOARD;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001395 }
1396
1397 /**
1398 * Create a new key event.
RoboErik01fe6612014-02-13 14:19:04 -08001399 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001400 * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis})
1401 * at which this key code originally went down.
1402 * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis})
1403 * at which this event happened.
1404 * @param action Action code: either {@link #ACTION_DOWN},
1405 * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}.
1406 * @param code The key code.
1407 * @param repeat A repeat count for down events (> 0 if this is after the
1408 * initial down) or event count for multiple events.
1409 * @param metaState Flags indicating which meta keys are currently pressed.
1410 */
1411 public KeyEvent(long downTime, long eventTime, int action,
1412 int code, int repeat, int metaState) {
Garfield Tanc8362b22020-01-24 11:32:14 -08001413 mId = nativeNextId();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 mDownTime = downTime;
1415 mEventTime = eventTime;
1416 mAction = action;
1417 mKeyCode = code;
1418 mRepeatCount = repeat;
1419 mMetaState = metaState;
Jeff Brown6b53e8d2010-11-10 16:03:06 -08001420 mDeviceId = KeyCharacterMap.VIRTUAL_KEYBOARD;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001421 }
1422
1423 /**
1424 * Create a new key event.
RoboErik01fe6612014-02-13 14:19:04 -08001425 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis})
1427 * at which this key code originally went down.
1428 * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis})
1429 * at which this event happened.
1430 * @param action Action code: either {@link #ACTION_DOWN},
1431 * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}.
1432 * @param code The key code.
1433 * @param repeat A repeat count for down events (> 0 if this is after the
1434 * initial down) or event count for multiple events.
1435 * @param metaState Flags indicating which meta keys are currently pressed.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001436 * @param deviceId The device ID that generated the key event.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 * @param scancode Raw device scan code of the event.
1438 */
1439 public KeyEvent(long downTime, long eventTime, int action,
1440 int code, int repeat, int metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07001441 int deviceId, int scancode) {
Garfield Tanc8362b22020-01-24 11:32:14 -08001442 mId = nativeNextId();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001443 mDownTime = downTime;
1444 mEventTime = eventTime;
1445 mAction = action;
1446 mKeyCode = code;
1447 mRepeatCount = repeat;
1448 mMetaState = metaState;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001449 mDeviceId = deviceId;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001450 mScanCode = scancode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 }
1452
1453 /**
1454 * Create a new key event.
RoboErik01fe6612014-02-13 14:19:04 -08001455 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis})
1457 * at which this key code originally went down.
1458 * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis})
1459 * at which this event happened.
1460 * @param action Action code: either {@link #ACTION_DOWN},
1461 * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}.
1462 * @param code The key code.
1463 * @param repeat A repeat count for down events (> 0 if this is after the
1464 * initial down) or event count for multiple events.
1465 * @param metaState Flags indicating which meta keys are currently pressed.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001466 * @param deviceId The device ID that generated the key event.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001467 * @param scancode Raw device scan code of the event.
1468 * @param flags The flags for this key event
1469 */
1470 public KeyEvent(long downTime, long eventTime, int action,
1471 int code, int repeat, int metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07001472 int deviceId, int scancode, int flags) {
Garfield Tanc8362b22020-01-24 11:32:14 -08001473 mId = nativeNextId();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001474 mDownTime = downTime;
1475 mEventTime = eventTime;
1476 mAction = action;
1477 mKeyCode = code;
1478 mRepeatCount = repeat;
1479 mMetaState = metaState;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001480 mDeviceId = deviceId;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001481 mScanCode = scancode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 mFlags = flags;
1483 }
1484
1485 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07001486 * Create a new key event.
RoboErik01fe6612014-02-13 14:19:04 -08001487 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07001488 * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis})
1489 * at which this key code originally went down.
1490 * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis})
1491 * at which this event happened.
1492 * @param action Action code: either {@link #ACTION_DOWN},
1493 * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}.
1494 * @param code The key code.
1495 * @param repeat A repeat count for down events (> 0 if this is after the
1496 * initial down) or event count for multiple events.
1497 * @param metaState Flags indicating which meta keys are currently pressed.
1498 * @param deviceId The device ID that generated the key event.
1499 * @param scancode Raw device scan code of the event.
1500 * @param flags The flags for this key event
1501 * @param source The input source such as {@link InputDevice#SOURCE_KEYBOARD}.
1502 */
1503 public KeyEvent(long downTime, long eventTime, int action,
1504 int code, int repeat, int metaState,
1505 int deviceId, int scancode, int flags, int source) {
Garfield Tanc8362b22020-01-24 11:32:14 -08001506 mId = nativeNextId();
Jeff Brownc5ed5912010-07-14 18:48:53 -07001507 mDownTime = downTime;
1508 mEventTime = eventTime;
1509 mAction = action;
1510 mKeyCode = code;
1511 mRepeatCount = repeat;
1512 mMetaState = metaState;
1513 mDeviceId = deviceId;
1514 mScanCode = scancode;
1515 mFlags = flags;
1516 mSource = source;
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01001517 mDisplayId = INVALID_DISPLAY;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001518 }
1519
1520 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 * Create a new key event for a string of characters. The key code,
Jeff Brownc5ed5912010-07-14 18:48:53 -07001522 * action, repeat count and source will automatically be set to
1523 * {@link #KEYCODE_UNKNOWN}, {@link #ACTION_MULTIPLE}, 0, and
1524 * {@link InputDevice#SOURCE_KEYBOARD} for you.
RoboErik01fe6612014-02-13 14:19:04 -08001525 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 * @param time The time (in {@link android.os.SystemClock#uptimeMillis})
1527 * at which this event occured.
1528 * @param characters The string of characters.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001529 * @param deviceId The device ID that generated the key event.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001530 * @param flags The flags for this key event
1531 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07001532 public KeyEvent(long time, String characters, int deviceId, int flags) {
Garfield Tanc8362b22020-01-24 11:32:14 -08001533 mId = nativeNextId();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 mDownTime = time;
1535 mEventTime = time;
1536 mCharacters = characters;
1537 mAction = ACTION_MULTIPLE;
1538 mKeyCode = KEYCODE_UNKNOWN;
1539 mRepeatCount = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001540 mDeviceId = deviceId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001541 mFlags = flags;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001542 mSource = InputDevice.SOURCE_KEYBOARD;
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01001543 mDisplayId = INVALID_DISPLAY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 }
1545
1546 /**
The Android Open Source Project10592532009-03-18 17:39:46 -07001547 * Make an exact copy of an existing key event.
1548 */
1549 public KeyEvent(KeyEvent origEvent) {
Garfield Tanc8362b22020-01-24 11:32:14 -08001550 mId = origEvent.mId;
The Android Open Source Project10592532009-03-18 17:39:46 -07001551 mDownTime = origEvent.mDownTime;
1552 mEventTime = origEvent.mEventTime;
1553 mAction = origEvent.mAction;
1554 mKeyCode = origEvent.mKeyCode;
1555 mRepeatCount = origEvent.mRepeatCount;
1556 mMetaState = origEvent.mMetaState;
1557 mDeviceId = origEvent.mDeviceId;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001558 mSource = origEvent.mSource;
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01001559 mDisplayId = origEvent.mDisplayId;
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -06001560 mHmac = origEvent.mHmac == null ? null : origEvent.mHmac.clone();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001561 mScanCode = origEvent.mScanCode;
The Android Open Source Project10592532009-03-18 17:39:46 -07001562 mFlags = origEvent.mFlags;
1563 mCharacters = origEvent.mCharacters;
1564 }
1565
1566 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 * Copy an existing key event, modifying its time and repeat count.
RoboErik01fe6612014-02-13 14:19:04 -08001568 *
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001569 * @deprecated Use {@link #changeTimeRepeat(KeyEvent, long, int)}
1570 * instead.
RoboErik01fe6612014-02-13 14:19:04 -08001571 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001572 * @param origEvent The existing event to be copied.
1573 * @param eventTime The new event time
1574 * (in {@link android.os.SystemClock#uptimeMillis}) of the event.
1575 * @param newRepeat The new repeat count of the event.
1576 */
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001577 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 public KeyEvent(KeyEvent origEvent, long eventTime, int newRepeat) {
Garfield Tanc8362b22020-01-24 11:32:14 -08001579 mId = nativeNextId(); // Not an exact copy so assign a new ID.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 mDownTime = origEvent.mDownTime;
1581 mEventTime = eventTime;
1582 mAction = origEvent.mAction;
1583 mKeyCode = origEvent.mKeyCode;
1584 mRepeatCount = newRepeat;
1585 mMetaState = origEvent.mMetaState;
1586 mDeviceId = origEvent.mDeviceId;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001587 mSource = origEvent.mSource;
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01001588 mDisplayId = origEvent.mDisplayId;
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -06001589 mHmac = null; // Don't copy HMAC, it will be invalid because eventTime is changing
Jeff Brown46b9ac02010-04-22 18:58:52 -07001590 mScanCode = origEvent.mScanCode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 mFlags = origEvent.mFlags;
1592 mCharacters = origEvent.mCharacters;
1593 }
1594
Jeff Brown1f245102010-11-18 20:53:46 -08001595 private static KeyEvent obtain() {
1596 final KeyEvent ev;
1597 synchronized (gRecyclerLock) {
1598 ev = gRecyclerTop;
1599 if (ev == null) {
1600 return new KeyEvent();
1601 }
1602 gRecyclerTop = ev.mNext;
1603 gRecyclerUsed -= 1;
1604 }
Jeff Brown1f245102010-11-18 20:53:46 -08001605 ev.mNext = null;
Jeff Brown32cbc38552011-12-01 14:01:49 -08001606 ev.prepareForReuse();
Jeff Brown1f245102010-11-18 20:53:46 -08001607 return ev;
1608 }
1609
1610 /**
Garfield Tanc8362b22020-01-24 11:32:14 -08001611 * Obtains a (potentially recycled) key event. Used by native code to create a Java object.
Jeff Brown1f245102010-11-18 20:53:46 -08001612 *
1613 * @hide
1614 */
Garfield Tanc8362b22020-01-24 11:32:14 -08001615 public static KeyEvent obtain(int id, long downTime, long eventTime, int action,
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001616 int code, int repeat, int metaState,
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -06001617 int deviceId, int scancode, int flags, int source, int displayId, @Nullable byte[] hmac,
1618 String characters) {
Jeff Brown1f245102010-11-18 20:53:46 -08001619 KeyEvent ev = obtain();
Garfield Tanc8362b22020-01-24 11:32:14 -08001620 ev.mId = id;
Jeff Brown1f245102010-11-18 20:53:46 -08001621 ev.mDownTime = downTime;
1622 ev.mEventTime = eventTime;
1623 ev.mAction = action;
1624 ev.mKeyCode = code;
1625 ev.mRepeatCount = repeat;
1626 ev.mMetaState = metaState;
1627 ev.mDeviceId = deviceId;
1628 ev.mScanCode = scancode;
1629 ev.mFlags = flags;
1630 ev.mSource = source;
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01001631 ev.mDisplayId = displayId;
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -06001632 ev.mHmac = hmac;
Jeff Brown1f245102010-11-18 20:53:46 -08001633 ev.mCharacters = characters;
1634 return ev;
1635 }
1636
1637 /**
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01001638 * Obtains a (potentially recycled) key event.
1639 *
1640 * @hide
1641 */
Garfield Tanc8362b22020-01-24 11:32:14 -08001642 public static KeyEvent obtain(long downTime, long eventTime, int action,
1643 int code, int repeat, int metaState,
1644 int deviceId, int scanCode, int flags, int source, int displayId, String characters) {
1645 return obtain(nativeNextId(), downTime, eventTime, action, code, repeat, metaState,
1646 deviceId, scanCode, flags, source, displayId, null /* hmac */, characters);
1647 }
1648
1649 /**
1650 * Obtains a (potentially recycled) key event.
1651 *
1652 * @hide
1653 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001654 @UnsupportedAppUsage
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01001655 public static KeyEvent obtain(long downTime, long eventTime, int action,
1656 int code, int repeat, int metaState,
1657 int deviceId, int scancode, int flags, int source, String characters) {
1658 return obtain(downTime, eventTime, action, code, repeat, metaState, deviceId, scancode,
Garfield Tanc8362b22020-01-24 11:32:14 -08001659 flags, source, INVALID_DISPLAY, characters);
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01001660 }
1661
1662 /**
1663
1664 /**
Jeff Brown21bc5c92011-02-28 18:27:14 -08001665 * Obtains a (potentially recycled) copy of another key event.
1666 *
1667 * @hide
1668 */
1669 public static KeyEvent obtain(KeyEvent other) {
1670 KeyEvent ev = obtain();
Garfield Tanc8362b22020-01-24 11:32:14 -08001671 ev.mId = other.mId;
Jeff Brown21bc5c92011-02-28 18:27:14 -08001672 ev.mDownTime = other.mDownTime;
1673 ev.mEventTime = other.mEventTime;
1674 ev.mAction = other.mAction;
1675 ev.mKeyCode = other.mKeyCode;
1676 ev.mRepeatCount = other.mRepeatCount;
1677 ev.mMetaState = other.mMetaState;
1678 ev.mDeviceId = other.mDeviceId;
1679 ev.mScanCode = other.mScanCode;
1680 ev.mFlags = other.mFlags;
1681 ev.mSource = other.mSource;
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01001682 ev.mDisplayId = other.mDisplayId;
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -06001683 ev.mHmac = other.mHmac == null ? null : other.mHmac.clone();
Jeff Brown21bc5c92011-02-28 18:27:14 -08001684 ev.mCharacters = other.mCharacters;
1685 return ev;
1686 }
1687
1688 /** @hide */
1689 @Override
1690 public KeyEvent copy() {
1691 return obtain(this);
1692 }
1693
1694 /**
Jeff Brown1f245102010-11-18 20:53:46 -08001695 * Recycles a key event.
1696 * Key events should only be recycled if they are owned by the system since user
1697 * code expects them to be essentially immutable, "tracking" notwithstanding.
1698 *
1699 * @hide
1700 */
Jeff Brown92cc2d82011-12-02 01:19:47 -08001701 @Override
Mathew Inwood8c854f82018-09-14 12:35:36 +01001702 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Jeff Brown1f245102010-11-18 20:53:46 -08001703 public final void recycle() {
Jeff Brown32cbc38552011-12-01 14:01:49 -08001704 super.recycle();
Jeff Brown1f245102010-11-18 20:53:46 -08001705 mCharacters = null;
1706
1707 synchronized (gRecyclerLock) {
1708 if (gRecyclerUsed < MAX_RECYCLED) {
1709 gRecyclerUsed++;
1710 mNext = gRecyclerTop;
1711 gRecyclerTop = this;
1712 }
1713 }
1714 }
1715
Jeff Brown92cc2d82011-12-02 01:19:47 -08001716 /** @hide */
1717 @Override
1718 public final void recycleIfNeededAfterDispatch() {
1719 // Do nothing.
1720 }
1721
Garfield Tanc8362b22020-01-24 11:32:14 -08001722 /** @hide */
1723 @Override
1724 public int getId() {
1725 return mId;
1726 }
1727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001728 /**
The Android Open Source Project10592532009-03-18 17:39:46 -07001729 * Create a new key event that is the same as the given one, but whose
1730 * event time and repeat count are replaced with the given value.
RoboErik01fe6612014-02-13 14:19:04 -08001731 *
The Android Open Source Project10592532009-03-18 17:39:46 -07001732 * @param event The existing event to be copied. This is not modified.
1733 * @param eventTime The new event time
1734 * (in {@link android.os.SystemClock#uptimeMillis}) of the event.
1735 * @param newRepeat The new repeat count of the event.
1736 */
1737 public static KeyEvent changeTimeRepeat(KeyEvent event, long eventTime,
1738 int newRepeat) {
1739 return new KeyEvent(event, eventTime, newRepeat);
1740 }
RoboErik01fe6612014-02-13 14:19:04 -08001741
The Android Open Source Project10592532009-03-18 17:39:46 -07001742 /**
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001743 * Create a new key event that is the same as the given one, but whose
1744 * event time and repeat count are replaced with the given value.
RoboErik01fe6612014-02-13 14:19:04 -08001745 *
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001746 * @param event The existing event to be copied. This is not modified.
1747 * @param eventTime The new event time
1748 * (in {@link android.os.SystemClock#uptimeMillis}) of the event.
1749 * @param newRepeat The new repeat count of the event.
1750 * @param newFlags New flags for the event, replacing the entire value
1751 * in the original event.
1752 */
1753 public static KeyEvent changeTimeRepeat(KeyEvent event, long eventTime,
1754 int newRepeat, int newFlags) {
1755 KeyEvent ret = new KeyEvent(event);
Garfield Tanc8362b22020-01-24 11:32:14 -08001756 ret.mId = nativeNextId(); // Not an exact copy so assign a new ID.
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001757 ret.mEventTime = eventTime;
1758 ret.mRepeatCount = newRepeat;
1759 ret.mFlags = newFlags;
1760 return ret;
1761 }
RoboErik01fe6612014-02-13 14:19:04 -08001762
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001763 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001764 * Copy an existing key event, modifying its action.
RoboErik01fe6612014-02-13 14:19:04 -08001765 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001766 * @param origEvent The existing event to be copied.
1767 * @param action The new action code of the event.
1768 */
The Android Open Source Project10592532009-03-18 17:39:46 -07001769 private KeyEvent(KeyEvent origEvent, int action) {
Garfield Tanc8362b22020-01-24 11:32:14 -08001770 mId = nativeNextId(); // Not an exact copy so assign a new ID.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001771 mDownTime = origEvent.mDownTime;
1772 mEventTime = origEvent.mEventTime;
1773 mAction = action;
1774 mKeyCode = origEvent.mKeyCode;
1775 mRepeatCount = origEvent.mRepeatCount;
1776 mMetaState = origEvent.mMetaState;
1777 mDeviceId = origEvent.mDeviceId;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001778 mSource = origEvent.mSource;
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01001779 mDisplayId = origEvent.mDisplayId;
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -06001780 mHmac = null; // Don't copy the hmac, it will be invalid since action is changing
Jeff Brown46b9ac02010-04-22 18:58:52 -07001781 mScanCode = origEvent.mScanCode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001782 mFlags = origEvent.mFlags;
1783 // Don't copy mCharacters, since one way or the other we'll lose it
1784 // when changing the action.
1785 }
1786
1787 /**
The Android Open Source Project10592532009-03-18 17:39:46 -07001788 * Create a new key event that is the same as the given one, but whose
1789 * action is replaced with the given value.
RoboErik01fe6612014-02-13 14:19:04 -08001790 *
The Android Open Source Project10592532009-03-18 17:39:46 -07001791 * @param event The existing event to be copied. This is not modified.
1792 * @param action The new action code of the event.
1793 */
1794 public static KeyEvent changeAction(KeyEvent event, int action) {
1795 return new KeyEvent(event, action);
1796 }
RoboErik01fe6612014-02-13 14:19:04 -08001797
The Android Open Source Project10592532009-03-18 17:39:46 -07001798 /**
1799 * Create a new key event that is the same as the given one, but whose
1800 * flags are replaced with the given value.
RoboErik01fe6612014-02-13 14:19:04 -08001801 *
The Android Open Source Project10592532009-03-18 17:39:46 -07001802 * @param event The existing event to be copied. This is not modified.
1803 * @param flags The new flags constant.
1804 */
1805 public static KeyEvent changeFlags(KeyEvent event, int flags) {
1806 event = new KeyEvent(event);
Garfield Tanc8362b22020-01-24 11:32:14 -08001807 event.mId = nativeNextId(); // Not an exact copy so assign a new ID.
The Android Open Source Project10592532009-03-18 17:39:46 -07001808 event.mFlags = flags;
1809 return event;
1810 }
Jeff Brown21bc5c92011-02-28 18:27:14 -08001811
1812 /** @hide */
1813 @Override
1814 public final boolean isTainted() {
1815 return (mFlags & FLAG_TAINTED) != 0;
1816 }
1817
1818 /** @hide */
1819 @Override
1820 public final void setTainted(boolean tainted) {
1821 mFlags = tainted ? mFlags | FLAG_TAINTED : mFlags & ~FLAG_TAINTED;
1822 }
1823
The Android Open Source Project10592532009-03-18 17:39:46 -07001824 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001825 * Don't use in new code, instead explicitly check
1826 * {@link #getAction()}.
RoboErik01fe6612014-02-13 14:19:04 -08001827 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001828 * @return If the action is ACTION_DOWN, returns true; else false.
1829 *
1830 * @deprecated
1831 * @hide
1832 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001833 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001834 @Deprecated public final boolean isDown() {
1835 return mAction == ACTION_DOWN;
1836 }
1837
Michael Wright337d9d22014-04-22 15:03:48 -07001838 /** Is this a system key? System keys can not be used for menu shortcuts.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 */
1840 public final boolean isSystem() {
Michael Wright337d9d22014-04-22 15:03:48 -07001841 return isSystemKey(mKeyCode);
Dianne Hackborn3c80a4a2010-06-29 19:20:40 -07001842 }
1843
1844 /** @hide */
Michael Wright337d9d22014-04-22 15:03:48 -07001845 public final boolean isWakeKey() {
1846 return isWakeKey(mKeyCode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001847 }
1848
Jeff Brown6f2fba42011-02-19 01:08:02 -08001849 /**
1850 * Returns true if the specified keycode is a gamepad button.
1851 * @return True if the keycode is a gamepad button, such as {@link #KEYCODE_BUTTON_A}.
1852 */
1853 public static final boolean isGamepadButton(int keyCode) {
1854 switch (keyCode) {
1855 case KeyEvent.KEYCODE_BUTTON_A:
1856 case KeyEvent.KEYCODE_BUTTON_B:
1857 case KeyEvent.KEYCODE_BUTTON_C:
1858 case KeyEvent.KEYCODE_BUTTON_X:
1859 case KeyEvent.KEYCODE_BUTTON_Y:
1860 case KeyEvent.KEYCODE_BUTTON_Z:
1861 case KeyEvent.KEYCODE_BUTTON_L1:
1862 case KeyEvent.KEYCODE_BUTTON_R1:
1863 case KeyEvent.KEYCODE_BUTTON_L2:
1864 case KeyEvent.KEYCODE_BUTTON_R2:
1865 case KeyEvent.KEYCODE_BUTTON_THUMBL:
1866 case KeyEvent.KEYCODE_BUTTON_THUMBR:
1867 case KeyEvent.KEYCODE_BUTTON_START:
1868 case KeyEvent.KEYCODE_BUTTON_SELECT:
1869 case KeyEvent.KEYCODE_BUTTON_MODE:
1870 case KeyEvent.KEYCODE_BUTTON_1:
1871 case KeyEvent.KEYCODE_BUTTON_2:
1872 case KeyEvent.KEYCODE_BUTTON_3:
1873 case KeyEvent.KEYCODE_BUTTON_4:
1874 case KeyEvent.KEYCODE_BUTTON_5:
1875 case KeyEvent.KEYCODE_BUTTON_6:
1876 case KeyEvent.KEYCODE_BUTTON_7:
1877 case KeyEvent.KEYCODE_BUTTON_8:
1878 case KeyEvent.KEYCODE_BUTTON_9:
1879 case KeyEvent.KEYCODE_BUTTON_10:
1880 case KeyEvent.KEYCODE_BUTTON_11:
1881 case KeyEvent.KEYCODE_BUTTON_12:
1882 case KeyEvent.KEYCODE_BUTTON_13:
1883 case KeyEvent.KEYCODE_BUTTON_14:
1884 case KeyEvent.KEYCODE_BUTTON_15:
1885 case KeyEvent.KEYCODE_BUTTON_16:
1886 return true;
1887 default:
1888 return false;
1889 }
1890 }
1891
Michael Wright25b0c302013-07-10 12:54:06 -07001892 /** Whether key will, by default, trigger a click on the focused view.
1893 * @hide
1894 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001895 @UnsupportedAppUsage
Michael Wright25b0c302013-07-10 12:54:06 -07001896 public static final boolean isConfirmKey(int keyCode) {
1897 switch (keyCode) {
1898 case KeyEvent.KEYCODE_DPAD_CENTER:
1899 case KeyEvent.KEYCODE_ENTER:
Michael Wrightaa1a94d2015-11-26 16:04:54 +00001900 case KeyEvent.KEYCODE_SPACE:
Selim Cinekce2bd0f2016-02-19 16:16:54 -08001901 case KeyEvent.KEYCODE_NUMPAD_ENTER:
Michael Wright25b0c302013-07-10 12:54:06 -07001902 return true;
1903 default:
1904 return false;
1905 }
1906 }
1907
Hyundo Moonc3ce09e2019-03-11 20:00:00 +09001908 /**
1909 * Returns whether this key will be sent to the
1910 * {@link android.media.session.MediaSession.Callback} if not handled.
1911 *
1912 * @hide
1913 */
1914 public static final boolean isMediaSessionKey(int keyCode) {
1915 switch (keyCode) {
1916 case KeyEvent.KEYCODE_MEDIA_PLAY:
1917 case KeyEvent.KEYCODE_MEDIA_PAUSE:
1918 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
1919 case KeyEvent.KEYCODE_MUTE:
1920 case KeyEvent.KEYCODE_HEADSETHOOK:
1921 case KeyEvent.KEYCODE_MEDIA_STOP:
1922 case KeyEvent.KEYCODE_MEDIA_NEXT:
1923 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
1924 case KeyEvent.KEYCODE_MEDIA_REWIND:
1925 case KeyEvent.KEYCODE_MEDIA_RECORD:
1926 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
1927 return true;
1928 }
1929 return false;
1930 }
1931
Michael Wright337d9d22014-04-22 15:03:48 -07001932 /** Is this a system key? System keys can not be used for menu shortcuts.
1933 * @hide
1934 */
1935 public static final boolean isSystemKey(int keyCode) {
1936 switch (keyCode) {
1937 case KeyEvent.KEYCODE_MENU:
1938 case KeyEvent.KEYCODE_SOFT_RIGHT:
1939 case KeyEvent.KEYCODE_HOME:
1940 case KeyEvent.KEYCODE_BACK:
1941 case KeyEvent.KEYCODE_CALL:
1942 case KeyEvent.KEYCODE_ENDCALL:
1943 case KeyEvent.KEYCODE_VOLUME_UP:
1944 case KeyEvent.KEYCODE_VOLUME_DOWN:
1945 case KeyEvent.KEYCODE_VOLUME_MUTE:
1946 case KeyEvent.KEYCODE_MUTE:
1947 case KeyEvent.KEYCODE_POWER:
1948 case KeyEvent.KEYCODE_HEADSETHOOK:
1949 case KeyEvent.KEYCODE_MEDIA_PLAY:
1950 case KeyEvent.KEYCODE_MEDIA_PAUSE:
1951 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
1952 case KeyEvent.KEYCODE_MEDIA_STOP:
1953 case KeyEvent.KEYCODE_MEDIA_NEXT:
1954 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
1955 case KeyEvent.KEYCODE_MEDIA_REWIND:
1956 case KeyEvent.KEYCODE_MEDIA_RECORD:
1957 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
1958 case KeyEvent.KEYCODE_CAMERA:
1959 case KeyEvent.KEYCODE_FOCUS:
1960 case KeyEvent.KEYCODE_SEARCH:
1961 case KeyEvent.KEYCODE_BRIGHTNESS_DOWN:
1962 case KeyEvent.KEYCODE_BRIGHTNESS_UP:
1963 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jim Miller07e03842016-06-22 15:18:13 -07001964 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP:
1965 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN:
1966 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_LEFT:
1967 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_RIGHT:
Michael Wright337d9d22014-04-22 15:03:48 -07001968 return true;
1969 }
1970
1971 return false;
1972 }
1973
1974 /** @hide */
1975 public static final boolean isWakeKey(int keyCode) {
1976 switch (keyCode) {
Felix2deb9b52019-06-25 06:34:39 +02001977 case KeyEvent.KEYCODE_CAMERA:
Michael Wright337d9d22014-04-22 15:03:48 -07001978 case KeyEvent.KEYCODE_MENU:
Michael Wright8ac485a2014-06-04 12:38:18 -07001979 case KeyEvent.KEYCODE_PAIRING:
Chenjie Luobad498f2016-01-13 11:01:59 -08001980 case KeyEvent.KEYCODE_STEM_1:
1981 case KeyEvent.KEYCODE_STEM_2:
1982 case KeyEvent.KEYCODE_STEM_3:
Felix2deb9b52019-06-25 06:34:39 +02001983 case KeyEvent.KEYCODE_WAKEUP:
Michael Wright337d9d22014-04-22 15:03:48 -07001984 return true;
1985 }
1986 return false;
1987 }
1988
Michael Wrightce0c13a2014-07-30 10:49:21 -07001989 /** @hide */
1990 public static final boolean isMetaKey(int keyCode) {
1991 return keyCode == KeyEvent.KEYCODE_META_LEFT || keyCode == KeyEvent.KEYCODE_META_RIGHT;
1992 }
1993
Andrii Kulian112d0562016-03-08 10:44:22 -08001994 /** @hide */
1995 public static final boolean isAltKey(int keyCode) {
1996 return keyCode == KeyEvent.KEYCODE_ALT_LEFT || keyCode == KeyEvent.KEYCODE_ALT_RIGHT;
1997 }
1998
Jeff Brown91c69ab2011-02-14 17:03:18 -08001999 /** {@inheritDoc} */
2000 @Override
2001 public final int getDeviceId() {
2002 return mDeviceId;
2003 }
2004
2005 /** {@inheritDoc} */
2006 @Override
2007 public final int getSource() {
2008 return mSource;
2009 }
2010
2011 /** {@inheritDoc} */
2012 @Override
2013 public final void setSource(int source) {
2014 mSource = source;
2015 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002016
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01002017 /** @hide */
2018 @Override
2019 public final int getDisplayId() {
2020 return mDisplayId;
2021 }
2022
2023 /** @hide */
Tiger Huangfc218452018-09-27 00:38:50 +08002024 @TestApi
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01002025 @Override
2026 public final void setDisplayId(int displayId) {
2027 mDisplayId = displayId;
2028 }
2029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002030 /**
2031 * <p>Returns the state of the meta keys.</p>
2032 *
2033 * @return an integer in which each bit set to 1 represents a pressed
2034 * meta key
2035 *
2036 * @see #isAltPressed()
2037 * @see #isShiftPressed()
2038 * @see #isSymPressed()
Jeff Brown497a92c2010-09-12 17:55:08 -07002039 * @see #isCtrlPressed()
2040 * @see #isMetaPressed()
2041 * @see #isFunctionPressed()
Jeff Brown51e7fe72010-10-29 22:19:53 -07002042 * @see #isCapsLockOn()
2043 * @see #isNumLockOn()
2044 * @see #isScrollLockOn()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002045 * @see #META_ALT_ON
Jeff Brown497a92c2010-09-12 17:55:08 -07002046 * @see #META_ALT_LEFT_ON
2047 * @see #META_ALT_RIGHT_ON
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002048 * @see #META_SHIFT_ON
Jeff Brown497a92c2010-09-12 17:55:08 -07002049 * @see #META_SHIFT_LEFT_ON
2050 * @see #META_SHIFT_RIGHT_ON
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002051 * @see #META_SYM_ON
Jeff Brown497a92c2010-09-12 17:55:08 -07002052 * @see #META_FUNCTION_ON
2053 * @see #META_CTRL_ON
2054 * @see #META_CTRL_LEFT_ON
2055 * @see #META_CTRL_RIGHT_ON
2056 * @see #META_META_ON
2057 * @see #META_META_LEFT_ON
2058 * @see #META_META_RIGHT_ON
Jeff Brown51e7fe72010-10-29 22:19:53 -07002059 * @see #META_CAPS_LOCK_ON
2060 * @see #META_NUM_LOCK_ON
2061 * @see #META_SCROLL_LOCK_ON
Jeff Brown54875002011-04-06 15:33:01 -07002062 * @see #getModifiers
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002063 */
2064 public final int getMetaState() {
2065 return mMetaState;
2066 }
2067
2068 /**
Jeff Brown54875002011-04-06 15:33:01 -07002069 * Returns the state of the modifier keys.
2070 * <p>
2071 * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK},
2072 * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are
2073 * not considered modifier keys. Consequently, this function specifically masks out
2074 * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}.
2075 * </p><p>
2076 * The value returned consists of the meta state (from {@link #getMetaState})
2077 * normalized using {@link #normalizeMetaState(int)} and then masked with
2078 * {@link #getModifierMetaStateMask} so that only valid modifier bits are retained.
2079 * </p>
2080 *
2081 * @return An integer in which each bit set to 1 represents a pressed modifier key.
2082 * @see #getMetaState
2083 */
2084 public final int getModifiers() {
2085 return normalizeMetaState(mMetaState) & META_MODIFIER_MASK;
2086 }
2087
2088 /**
Tiger Huangfc218452018-09-27 00:38:50 +08002089 * Modifies the flags of the event.
2090 *
2091 * @param newFlags New flags for the event, replacing the entire value.
2092 * @hide
2093 */
2094 public final void setFlags(int newFlags) {
2095 mFlags = newFlags;
2096 }
2097
2098 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002099 * Returns the flags for this key event.
2100 *
2101 * @see #FLAG_WOKE_HERE
2102 */
2103 public final int getFlags() {
2104 return mFlags;
2105 }
2106
Jeff Brown28cbf4b2010-12-13 10:33:20 -08002107 // Mask of all modifier key meta states. Specifically excludes locked keys like caps lock.
Mathew Inwooda570dee2018-08-17 14:56:00 +01002108 @UnsupportedAppUsage
Jeff Brown28cbf4b2010-12-13 10:33:20 -08002109 private static final int META_MODIFIER_MASK =
2110 META_SHIFT_ON | META_SHIFT_LEFT_ON | META_SHIFT_RIGHT_ON
2111 | META_ALT_ON | META_ALT_LEFT_ON | META_ALT_RIGHT_ON
2112 | META_CTRL_ON | META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON
2113 | META_META_ON | META_META_LEFT_ON | META_META_RIGHT_ON
2114 | META_SYM_ON | META_FUNCTION_ON;
2115
2116 // Mask of all lock key meta states.
Mathew Inwooda570dee2018-08-17 14:56:00 +01002117 @UnsupportedAppUsage
Jeff Brown28cbf4b2010-12-13 10:33:20 -08002118 private static final int META_LOCK_MASK =
2119 META_CAPS_LOCK_ON | META_NUM_LOCK_ON | META_SCROLL_LOCK_ON;
2120
2121 // Mask of all valid meta states.
Mathew Inwooda570dee2018-08-17 14:56:00 +01002122 @UnsupportedAppUsage
Jeff Brown28cbf4b2010-12-13 10:33:20 -08002123 private static final int META_ALL_MASK = META_MODIFIER_MASK | META_LOCK_MASK;
2124
2125 // Mask of all synthetic meta states that are reserved for API compatibility with
2126 // historical uses in MetaKeyKeyListener.
Mathew Inwooda570dee2018-08-17 14:56:00 +01002127 @UnsupportedAppUsage
Jeff Brown28cbf4b2010-12-13 10:33:20 -08002128 private static final int META_SYNTHETIC_MASK =
2129 META_CAP_LOCKED | META_ALT_LOCKED | META_SYM_LOCKED | META_SELECTING;
2130
2131 // Mask of all meta states that are not valid use in specifying a modifier key.
2132 // These bits are known to be used for purposes other than specifying modifiers.
Mathew Inwooda570dee2018-08-17 14:56:00 +01002133 @UnsupportedAppUsage
Jeff Brown28cbf4b2010-12-13 10:33:20 -08002134 private static final int META_INVALID_MODIFIER_MASK =
2135 META_LOCK_MASK | META_SYNTHETIC_MASK;
2136
2137 /**
2138 * Gets a mask that includes all valid modifier key meta state bits.
2139 * <p>
2140 * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK},
2141 * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are
2142 * not considered modifier keys. Consequently, the mask specifically excludes
2143 * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}.
2144 * </p>
2145 *
2146 * @return The modifier meta state mask which is a combination of
2147 * {@link #META_SHIFT_ON}, {@link #META_SHIFT_LEFT_ON}, {@link #META_SHIFT_RIGHT_ON},
2148 * {@link #META_ALT_ON}, {@link #META_ALT_LEFT_ON}, {@link #META_ALT_RIGHT_ON},
2149 * {@link #META_CTRL_ON}, {@link #META_CTRL_LEFT_ON}, {@link #META_CTRL_RIGHT_ON},
2150 * {@link #META_META_ON}, {@link #META_META_LEFT_ON}, {@link #META_META_RIGHT_ON},
2151 * {@link #META_SYM_ON}, {@link #META_FUNCTION_ON}.
2152 */
2153 public static int getModifierMetaStateMask() {
2154 return META_MODIFIER_MASK;
2155 }
2156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002157 /**
2158 * Returns true if this key code is a modifier key.
Jeff Brown28cbf4b2010-12-13 10:33:20 -08002159 * <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 return false
2163 * for those keys.
2164 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002165 *
Jeff Brown28cbf4b2010-12-13 10:33:20 -08002166 * @return True if the key code is one of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002167 * {@link #KEYCODE_SHIFT_LEFT} {@link #KEYCODE_SHIFT_RIGHT},
Jeff Brown497a92c2010-09-12 17:55:08 -07002168 * {@link #KEYCODE_ALT_LEFT}, {@link #KEYCODE_ALT_RIGHT},
Jeff Brown497a92c2010-09-12 17:55:08 -07002169 * {@link #KEYCODE_CTRL_LEFT}, {@link #KEYCODE_CTRL_RIGHT},
Jeff Brown28cbf4b2010-12-13 10:33:20 -08002170 * {@link #KEYCODE_META_LEFT}, or {@link #KEYCODE_META_RIGHT},
2171 * {@link #KEYCODE_SYM}, {@link #KEYCODE_NUM}, {@link #KEYCODE_FUNCTION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002172 */
2173 public static boolean isModifierKey(int keyCode) {
Jeff Brown497a92c2010-09-12 17:55:08 -07002174 switch (keyCode) {
2175 case KEYCODE_SHIFT_LEFT:
2176 case KEYCODE_SHIFT_RIGHT:
2177 case KEYCODE_ALT_LEFT:
2178 case KEYCODE_ALT_RIGHT:
Jeff Brown497a92c2010-09-12 17:55:08 -07002179 case KEYCODE_CTRL_LEFT:
2180 case KEYCODE_CTRL_RIGHT:
2181 case KEYCODE_META_LEFT:
2182 case KEYCODE_META_RIGHT:
Jeff Brown28cbf4b2010-12-13 10:33:20 -08002183 case KEYCODE_SYM:
2184 case KEYCODE_NUM:
2185 case KEYCODE_FUNCTION:
Jeff Brown497a92c2010-09-12 17:55:08 -07002186 return true;
2187 default:
2188 return false;
2189 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 }
2191
2192 /**
Jeff Brown28cbf4b2010-12-13 10:33:20 -08002193 * Normalizes the specified meta state.
2194 * <p>
2195 * The meta state is normalized such that if either the left or right modifier meta state
2196 * bits are set then the result will also include the universal bit for that modifier.
2197 * </p><p>
2198 * If the specified meta state contains {@link #META_ALT_LEFT_ON} then
2199 * the result will also contain {@link #META_ALT_ON} in addition to {@link #META_ALT_LEFT_ON}
2200 * and the other bits that were specified in the input. The same is process is
2201 * performed for shift, control and meta.
2202 * </p><p>
2203 * If the specified meta state contains synthetic meta states defined by
2204 * {@link MetaKeyKeyListener}, then those states are translated here and the original
2205 * synthetic meta states are removed from the result.
2206 * {@link MetaKeyKeyListener#META_CAP_LOCKED} is translated to {@link #META_CAPS_LOCK_ON}.
2207 * {@link MetaKeyKeyListener#META_ALT_LOCKED} is translated to {@link #META_ALT_ON}.
2208 * {@link MetaKeyKeyListener#META_SYM_LOCKED} is translated to {@link #META_SYM_ON}.
2209 * </p><p>
2210 * Undefined meta state bits are removed.
2211 * </p>
2212 *
2213 * @param metaState The meta state.
2214 * @return The normalized meta state.
2215 */
2216 public static int normalizeMetaState(int metaState) {
2217 if ((metaState & (META_SHIFT_LEFT_ON | META_SHIFT_RIGHT_ON)) != 0) {
2218 metaState |= META_SHIFT_ON;
2219 }
2220 if ((metaState & (META_ALT_LEFT_ON | META_ALT_RIGHT_ON)) != 0) {
2221 metaState |= META_ALT_ON;
2222 }
2223 if ((metaState & (META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON)) != 0) {
2224 metaState |= META_CTRL_ON;
2225 }
2226 if ((metaState & (META_META_LEFT_ON | META_META_RIGHT_ON)) != 0) {
2227 metaState |= META_META_ON;
2228 }
2229 if ((metaState & MetaKeyKeyListener.META_CAP_LOCKED) != 0) {
2230 metaState |= META_CAPS_LOCK_ON;
2231 }
2232 if ((metaState & MetaKeyKeyListener.META_ALT_LOCKED) != 0) {
2233 metaState |= META_ALT_ON;
2234 }
2235 if ((metaState & MetaKeyKeyListener.META_SYM_LOCKED) != 0) {
2236 metaState |= META_SYM_ON;
2237 }
2238 return metaState & META_ALL_MASK;
2239 }
2240
2241 /**
2242 * Returns true if no modifiers keys are pressed according to the specified meta state.
2243 * <p>
2244 * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK},
2245 * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are
2246 * not considered modifier keys. Consequently, this function ignores
2247 * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}.
2248 * </p><p>
2249 * The meta state is normalized prior to comparison using {@link #normalizeMetaState(int)}.
2250 * </p>
2251 *
2252 * @param metaState The meta state to consider.
2253 * @return True if no modifier keys are pressed.
2254 * @see #hasNoModifiers()
2255 */
2256 public static boolean metaStateHasNoModifiers(int metaState) {
2257 return (normalizeMetaState(metaState) & META_MODIFIER_MASK) == 0;
2258 }
2259
2260 /**
2261 * Returns true if only the specified modifier keys are pressed according to
2262 * the specified meta state. Returns false if a different combination of modifier
2263 * keys are pressed.
2264 * <p>
2265 * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK},
2266 * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are
2267 * not considered modifier keys. Consequently, this function ignores
2268 * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}.
2269 * </p><p>
2270 * If the specified modifier mask includes directional modifiers, such as
2271 * {@link #META_SHIFT_LEFT_ON}, then this method ensures that the
2272 * modifier is pressed on that side.
2273 * If the specified modifier mask includes non-directional modifiers, such as
2274 * {@link #META_SHIFT_ON}, then this method ensures that the modifier
2275 * is pressed on either side.
2276 * If the specified modifier mask includes both directional and non-directional modifiers
2277 * for the same type of key, such as {@link #META_SHIFT_ON} and {@link #META_SHIFT_LEFT_ON},
2278 * then this method throws an illegal argument exception.
2279 * </p>
2280 *
2281 * @param metaState The meta state to consider.
2282 * @param modifiers The meta state of the modifier keys to check. May be a combination
2283 * of modifier meta states as defined by {@link #getModifierMetaStateMask()}. May be 0 to
2284 * ensure that no modifier keys are pressed.
2285 * @return True if only the specified modifier keys are pressed.
2286 * @throws IllegalArgumentException if the modifiers parameter contains invalid modifiers
2287 * @see #hasModifiers
2288 */
2289 public static boolean metaStateHasModifiers(int metaState, int modifiers) {
2290 // Note: For forward compatibility, we allow the parameter to contain meta states
2291 // that we do not recognize but we explicitly disallow meta states that
2292 // are not valid modifiers.
2293 if ((modifiers & META_INVALID_MODIFIER_MASK) != 0) {
2294 throw new IllegalArgumentException("modifiers must not contain "
2295 + "META_CAPS_LOCK_ON, META_NUM_LOCK_ON, META_SCROLL_LOCK_ON, "
2296 + "META_CAP_LOCKED, META_ALT_LOCKED, META_SYM_LOCKED, "
2297 + "or META_SELECTING");
2298 }
2299
2300 metaState = normalizeMetaState(metaState) & META_MODIFIER_MASK;
2301 metaState = metaStateFilterDirectionalModifiers(metaState, modifiers,
2302 META_SHIFT_ON, META_SHIFT_LEFT_ON, META_SHIFT_RIGHT_ON);
2303 metaState = metaStateFilterDirectionalModifiers(metaState, modifiers,
2304 META_ALT_ON, META_ALT_LEFT_ON, META_ALT_RIGHT_ON);
2305 metaState = metaStateFilterDirectionalModifiers(metaState, modifiers,
2306 META_CTRL_ON, META_CTRL_LEFT_ON, META_CTRL_RIGHT_ON);
2307 metaState = metaStateFilterDirectionalModifiers(metaState, modifiers,
2308 META_META_ON, META_META_LEFT_ON, META_META_RIGHT_ON);
2309 return metaState == modifiers;
2310 }
2311
2312 private static int metaStateFilterDirectionalModifiers(int metaState,
2313 int modifiers, int basic, int left, int right) {
2314 final boolean wantBasic = (modifiers & basic) != 0;
2315 final int directional = left | right;
2316 final boolean wantLeftOrRight = (modifiers & directional) != 0;
2317
2318 if (wantBasic) {
2319 if (wantLeftOrRight) {
2320 throw new IllegalArgumentException("modifiers must not contain "
2321 + metaStateToString(basic) + " combined with "
2322 + metaStateToString(left) + " or " + metaStateToString(right));
2323 }
2324 return metaState & ~directional;
2325 } else if (wantLeftOrRight) {
2326 return metaState & ~basic;
2327 } else {
2328 return metaState;
2329 }
2330 }
2331
2332 /**
2333 * Returns true if no modifier keys are pressed.
2334 * <p>
2335 * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK},
2336 * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are
2337 * not considered modifier keys. Consequently, this function ignores
2338 * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}.
2339 * </p><p>
2340 * The meta state is normalized prior to comparison using {@link #normalizeMetaState(int)}.
2341 * </p>
2342 *
2343 * @return True if no modifier keys are pressed.
2344 * @see #metaStateHasNoModifiers
2345 */
2346 public final boolean hasNoModifiers() {
2347 return metaStateHasNoModifiers(mMetaState);
2348 }
2349
2350 /**
2351 * Returns true if only the specified modifiers keys are pressed.
2352 * Returns false if a different combination of modifier keys are pressed.
2353 * <p>
2354 * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK},
2355 * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are
2356 * not considered modifier keys. Consequently, this function ignores
2357 * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}.
2358 * </p><p>
2359 * If the specified modifier mask includes directional modifiers, such as
2360 * {@link #META_SHIFT_LEFT_ON}, then this method ensures that the
2361 * modifier is pressed on that side.
2362 * If the specified modifier mask includes non-directional modifiers, such as
2363 * {@link #META_SHIFT_ON}, then this method ensures that the modifier
2364 * is pressed on either side.
2365 * If the specified modifier mask includes both directional and non-directional modifiers
2366 * for the same type of key, such as {@link #META_SHIFT_ON} and {@link #META_SHIFT_LEFT_ON},
2367 * then this method throws an illegal argument exception.
2368 * </p>
2369 *
2370 * @param modifiers The meta state of the modifier keys to check. May be a combination
2371 * of modifier meta states as defined by {@link #getModifierMetaStateMask()}. May be 0 to
2372 * ensure that no modifier keys are pressed.
2373 * @return True if only the specified modifier keys are pressed.
2374 * @throws IllegalArgumentException if the modifiers parameter contains invalid modifiers
2375 * @see #metaStateHasModifiers
2376 */
2377 public final boolean hasModifiers(int modifiers) {
2378 return metaStateHasModifiers(mMetaState, modifiers);
2379 }
2380
2381 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002382 * <p>Returns the pressed state of the ALT meta key.</p>
2383 *
2384 * @return true if the ALT key is pressed, false otherwise
2385 *
2386 * @see #KEYCODE_ALT_LEFT
2387 * @see #KEYCODE_ALT_RIGHT
2388 * @see #META_ALT_ON
2389 */
2390 public final boolean isAltPressed() {
2391 return (mMetaState & META_ALT_ON) != 0;
2392 }
2393
2394 /**
2395 * <p>Returns the pressed state of the SHIFT meta key.</p>
2396 *
2397 * @return true if the SHIFT key is pressed, false otherwise
2398 *
2399 * @see #KEYCODE_SHIFT_LEFT
2400 * @see #KEYCODE_SHIFT_RIGHT
2401 * @see #META_SHIFT_ON
2402 */
2403 public final boolean isShiftPressed() {
2404 return (mMetaState & META_SHIFT_ON) != 0;
2405 }
2406
2407 /**
2408 * <p>Returns the pressed state of the SYM meta key.</p>
2409 *
2410 * @return true if the SYM key is pressed, false otherwise
2411 *
2412 * @see #KEYCODE_SYM
2413 * @see #META_SYM_ON
2414 */
2415 public final boolean isSymPressed() {
2416 return (mMetaState & META_SYM_ON) != 0;
2417 }
2418
2419 /**
Jeff Brown497a92c2010-09-12 17:55:08 -07002420 * <p>Returns the pressed state of the CTRL meta key.</p>
2421 *
2422 * @return true if the CTRL key is pressed, false otherwise
2423 *
2424 * @see #KEYCODE_CTRL_LEFT
2425 * @see #KEYCODE_CTRL_RIGHT
2426 * @see #META_CTRL_ON
2427 */
2428 public final boolean isCtrlPressed() {
2429 return (mMetaState & META_CTRL_ON) != 0;
2430 }
2431
2432 /**
2433 * <p>Returns the pressed state of the META meta key.</p>
2434 *
2435 * @return true if the META key is pressed, false otherwise
2436 *
2437 * @see #KEYCODE_META_LEFT
2438 * @see #KEYCODE_META_RIGHT
2439 * @see #META_META_ON
2440 */
2441 public final boolean isMetaPressed() {
2442 return (mMetaState & META_META_ON) != 0;
2443 }
2444
2445 /**
2446 * <p>Returns the pressed state of the FUNCTION meta key.</p>
2447 *
2448 * @return true if the FUNCTION key is pressed, false otherwise
2449 *
2450 * @see #KEYCODE_FUNCTION
2451 * @see #META_FUNCTION_ON
2452 */
2453 public final boolean isFunctionPressed() {
2454 return (mMetaState & META_FUNCTION_ON) != 0;
2455 }
2456
2457 /**
Jeff Brown51e7fe72010-10-29 22:19:53 -07002458 * <p>Returns the locked state of the CAPS LOCK meta key.</p>
Jeff Brown497a92c2010-09-12 17:55:08 -07002459 *
Jeff Brown51e7fe72010-10-29 22:19:53 -07002460 * @return true if the CAPS LOCK key is on, false otherwise
Jeff Brown497a92c2010-09-12 17:55:08 -07002461 *
2462 * @see #KEYCODE_CAPS_LOCK
Jeff Brown51e7fe72010-10-29 22:19:53 -07002463 * @see #META_CAPS_LOCK_ON
Jeff Brown497a92c2010-09-12 17:55:08 -07002464 */
Jeff Brown51e7fe72010-10-29 22:19:53 -07002465 public final boolean isCapsLockOn() {
2466 return (mMetaState & META_CAPS_LOCK_ON) != 0;
Jeff Brown497a92c2010-09-12 17:55:08 -07002467 }
2468
2469 /**
Jeff Brown51e7fe72010-10-29 22:19:53 -07002470 * <p>Returns the locked state of the NUM LOCK meta key.</p>
Jeff Brown497a92c2010-09-12 17:55:08 -07002471 *
Jeff Brown51e7fe72010-10-29 22:19:53 -07002472 * @return true if the NUM LOCK key is on, false otherwise
Jeff Brown497a92c2010-09-12 17:55:08 -07002473 *
2474 * @see #KEYCODE_NUM_LOCK
Jeff Brown51e7fe72010-10-29 22:19:53 -07002475 * @see #META_NUM_LOCK_ON
Jeff Brown497a92c2010-09-12 17:55:08 -07002476 */
Jeff Brown51e7fe72010-10-29 22:19:53 -07002477 public final boolean isNumLockOn() {
2478 return (mMetaState & META_NUM_LOCK_ON) != 0;
Jeff Brown497a92c2010-09-12 17:55:08 -07002479 }
2480
2481 /**
Jeff Brown51e7fe72010-10-29 22:19:53 -07002482 * <p>Returns the locked state of the SCROLL LOCK meta key.</p>
Jeff Brown497a92c2010-09-12 17:55:08 -07002483 *
Jeff Brown51e7fe72010-10-29 22:19:53 -07002484 * @return true if the SCROLL LOCK key is on, false otherwise
Jeff Brown497a92c2010-09-12 17:55:08 -07002485 *
2486 * @see #KEYCODE_SCROLL_LOCK
Jeff Brown51e7fe72010-10-29 22:19:53 -07002487 * @see #META_SCROLL_LOCK_ON
Jeff Brown497a92c2010-09-12 17:55:08 -07002488 */
Jeff Brown51e7fe72010-10-29 22:19:53 -07002489 public final boolean isScrollLockOn() {
2490 return (mMetaState & META_SCROLL_LOCK_ON) != 0;
Jeff Brown497a92c2010-09-12 17:55:08 -07002491 }
2492
2493 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 * Retrieve the action of this key event. May be either
2495 * {@link #ACTION_DOWN}, {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}.
RoboErik01fe6612014-02-13 14:19:04 -08002496 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002497 * @return The event action: ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.
2498 */
2499 public final int getAction() {
2500 return mAction;
2501 }
2502
2503 /**
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07002504 * For {@link #ACTION_UP} events, indicates that the event has been
2505 * canceled as per {@link #FLAG_CANCELED}.
2506 */
2507 public final boolean isCanceled() {
2508 return (mFlags&FLAG_CANCELED) != 0;
2509 }
RoboErik01fe6612014-02-13 14:19:04 -08002510
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07002511 /**
Wale Ogunwalec3672cd2014-11-05 15:17:35 -08002512 * Set {@link #FLAG_CANCELED} flag for the key event.
2513 *
2514 * @hide
2515 */
2516 @Override
2517 public final void cancel() {
2518 mFlags |= FLAG_CANCELED;
2519 }
2520
2521 /**
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002522 * Call this during {@link Callback#onKeyDown} to have the system track
2523 * the key through its final up (possibly including a long press). Note
2524 * that only one key can be tracked at a time -- if another key down
2525 * event is received while a previous one is being tracked, tracking is
2526 * stopped on the previous event.
2527 */
2528 public final void startTracking() {
2529 mFlags |= FLAG_START_TRACKING;
2530 }
RoboErik01fe6612014-02-13 14:19:04 -08002531
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002532 /**
2533 * For {@link #ACTION_UP} events, indicates that the event is still being
2534 * tracked from its initial down event as per
2535 * {@link #FLAG_TRACKING}.
2536 */
2537 public final boolean isTracking() {
2538 return (mFlags&FLAG_TRACKING) != 0;
2539 }
RoboErik01fe6612014-02-13 14:19:04 -08002540
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002541 /**
2542 * For {@link #ACTION_DOWN} events, indicates that the event has been
2543 * canceled as per {@link #FLAG_LONG_PRESS}.
2544 */
2545 public final boolean isLongPress() {
2546 return (mFlags&FLAG_LONG_PRESS) != 0;
2547 }
RoboErik01fe6612014-02-13 14:19:04 -08002548
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002549 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 * Retrieve the key code of the key event. This is the physical key that
2551 * was pressed, <em>not</em> the Unicode character.
RoboErik01fe6612014-02-13 14:19:04 -08002552 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 * @return The key code of the event.
2554 */
2555 public final int getKeyCode() {
2556 return mKeyCode;
2557 }
2558
2559 /**
2560 * For the special case of a {@link #ACTION_MULTIPLE} event with key
2561 * code of {@link #KEYCODE_UNKNOWN}, this is a raw string of characters
2562 * associated with the event. In all other cases it is null.
RoboErik01fe6612014-02-13 14:19:04 -08002563 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 * @return Returns a String of 1 or more characters associated with
2565 * the event.
Siarhei Vishniakoue481d332018-07-18 14:46:00 +01002566 *
2567 * @deprecated no longer used by the input system.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 */
Siarhei Vishniakoue481d332018-07-18 14:46:00 +01002569 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002570 public final String getCharacters() {
2571 return mCharacters;
2572 }
RoboErik01fe6612014-02-13 14:19:04 -08002573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002574 /**
2575 * Retrieve the hardware key id of this key event. These values are not
2576 * reliable and vary from device to device.
2577 *
2578 * {@more}
2579 * Mostly this is here for debugging purposes.
2580 */
2581 public final int getScanCode() {
Jeff Brown46b9ac02010-04-22 18:58:52 -07002582 return mScanCode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002583 }
2584
2585 /**
Siarhei Vishniakou4fddffc2018-11-07 17:02:29 -08002586 * Retrieve the repeat count of the event. For key down events,
2587 * this is the number of times the key has repeated with the first
2588 * down starting at 0 and counting up from there. For key up events,
2589 * this is always equal to zero. For multiple key events,
2590 * this is the number of down/up pairs that have occurred.
RoboErik01fe6612014-02-13 14:19:04 -08002591 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002592 * @return The number of times the key has repeated.
2593 */
2594 public final int getRepeatCount() {
2595 return mRepeatCount;
2596 }
2597
2598 /**
Tiger Huangfc218452018-09-27 00:38:50 +08002599 * Modifies the down time and the event time of the event.
2600 *
2601 * @param downTime The new down time (in {@link android.os.SystemClock#uptimeMillis}) of the
2602 * event.
2603 * @param eventTime The new event time (in {@link android.os.SystemClock#uptimeMillis}) of the
2604 * event.
2605 * @hide
2606 */
2607 public final void setTime(long downTime, long eventTime) {
2608 mDownTime = downTime;
2609 mEventTime = eventTime;
2610 }
2611
2612 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002613 * Retrieve the time of the most recent key down event,
2614 * in the {@link android.os.SystemClock#uptimeMillis} time base. If this
2615 * is a down event, this will be the same as {@link #getEventTime()}.
2616 * Note that when chording keys, this value is the down time of the
2617 * most recently pressed key, which may <em>not</em> be the same physical
2618 * key of this event.
RoboErik01fe6612014-02-13 14:19:04 -08002619 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002620 * @return Returns the most recent key down time, in the
2621 * {@link android.os.SystemClock#uptimeMillis} time base
2622 */
2623 public final long getDownTime() {
2624 return mDownTime;
2625 }
2626
2627 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07002628 * Retrieve the time this event occurred,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 * in the {@link android.os.SystemClock#uptimeMillis} time base.
Jeff Brownb11499d2012-04-20 19:54:22 -07002630 *
RoboErik01fe6612014-02-13 14:19:04 -08002631 * @return Returns the time this event occurred,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002632 * in the {@link android.os.SystemClock#uptimeMillis} time base.
2633 */
Jeff Brownb11499d2012-04-20 19:54:22 -07002634 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002635 public final long getEventTime() {
2636 return mEventTime;
2637 }
2638
Jeff Brownb11499d2012-04-20 19:54:22 -07002639 /**
2640 * Retrieve the time this event occurred,
2641 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2642 * nanosecond (instead of millisecond) precision.
2643 * <p>
2644 * The value is in nanosecond precision but it may not have nanosecond accuracy.
2645 * </p>
2646 *
2647 * @return Returns the time this event occurred,
2648 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2649 * nanosecond (instead of millisecond) precision.
2650 *
2651 * @hide
2652 */
Jeff Brown4e91a182011-04-07 11:38:09 -07002653 @Override
2654 public final long getEventTimeNano() {
2655 return mEventTime * 1000000L;
2656 }
2657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002658 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002659 * Renamed to {@link #getDeviceId}.
RoboErik01fe6612014-02-13 14:19:04 -08002660 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002661 * @hide
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002662 * @deprecated use {@link #getDeviceId()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002663 */
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002664 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002665 public final int getKeyboardDevice() {
2666 return mDeviceId;
2667 }
2668
2669 /**
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002670 * Gets the {@link KeyCharacterMap} associated with the keyboard device.
2671 *
2672 * @return The associated key character map.
Andrew Sapperstein8ab3dc72011-06-23 18:56:44 -07002673 * @throws {@link KeyCharacterMap.UnavailableException} if the key character map
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002674 * could not be loaded because it was malformed or the default key character map
2675 * is missing from the system.
2676 *
Andrew Sapperstein8ab3dc72011-06-23 18:56:44 -07002677 * @see KeyCharacterMap#load
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002678 */
2679 public final KeyCharacterMap getKeyCharacterMap() {
2680 return KeyCharacterMap.load(mDeviceId);
2681 }
2682
2683 /**
2684 * Gets the primary character for this key.
2685 * In other words, the label that is physically printed on it.
2686 *
2687 * @return The display label character, or 0 if none (eg. for non-printing keys).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 */
2689 public char getDisplayLabel() {
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002690 return getKeyCharacterMap().getDisplayLabel(mKeyCode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002691 }
RoboErik01fe6612014-02-13 14:19:04 -08002692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002693 /**
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002694 * Gets the Unicode character generated by the specified key and meta
2695 * key state combination.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002696 * <p>
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002697 * Returns the Unicode character that the specified key would produce
2698 * when the specified meta bits (see {@link MetaKeyKeyListener})
2699 * were active.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002700 * </p><p>
2701 * Returns 0 if the key is not one that is used to type Unicode
2702 * characters.
2703 * </p><p>
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002704 * If the return value has bit {@link KeyCharacterMap#COMBINING_ACCENT} set, the
2705 * key is a "dead key" that should be combined with another to
2706 * actually produce a character -- see {@link KeyCharacterMap#getDeadChar} --
2707 * after masking with {@link KeyCharacterMap#COMBINING_ACCENT_MASK}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002708 * </p>
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002709 *
2710 * @return The associated character or combining accent, or 0 if none.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002711 */
2712 public int getUnicodeChar() {
2713 return getUnicodeChar(mMetaState);
2714 }
RoboErik01fe6612014-02-13 14:19:04 -08002715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002716 /**
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002717 * Gets the Unicode character generated by the specified key and meta
2718 * key state combination.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002719 * <p>
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002720 * Returns the Unicode character that the specified key would produce
2721 * when the specified meta bits (see {@link MetaKeyKeyListener})
2722 * were active.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002723 * </p><p>
2724 * Returns 0 if the key is not one that is used to type Unicode
2725 * characters.
2726 * </p><p>
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002727 * If the return value has bit {@link KeyCharacterMap#COMBINING_ACCENT} set, the
2728 * key is a "dead key" that should be combined with another to
2729 * actually produce a character -- see {@link KeyCharacterMap#getDeadChar} --
2730 * after masking with {@link KeyCharacterMap#COMBINING_ACCENT_MASK}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002731 * </p>
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002732 *
2733 * @param metaState The meta key modifier state.
2734 * @return The associated character or combining accent, or 0 if none.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002735 */
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002736 public int getUnicodeChar(int metaState) {
2737 return getKeyCharacterMap().get(mKeyCode, metaState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 }
RoboErik01fe6612014-02-13 14:19:04 -08002739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002740 /**
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002741 * Get the character conversion data for a given key code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002742 *
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002743 * @param results A {@link KeyCharacterMap.KeyData} instance that will be
2744 * filled with the results.
2745 * @return True if the key was mapped. If the key was not mapped, results is not modified.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002746 *
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002747 * @deprecated instead use {@link #getDisplayLabel()},
2748 * {@link #getNumber()} or {@link #getUnicodeChar(int)}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002749 */
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002750 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002751 public boolean getKeyData(KeyData results) {
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002752 return getKeyCharacterMap().getKeyData(mKeyCode, results);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002753 }
RoboErik01fe6612014-02-13 14:19:04 -08002754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002755 /**
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002756 * Gets the first character in the character array that can be generated
2757 * by the specified key code.
2758 * <p>
2759 * This is a convenience function that returns the same value as
2760 * {@link #getMatch(char[],int) getMatch(chars, 0)}.
2761 * </p>
2762 *
2763 * @param chars The array of matching characters to consider.
2764 * @return The matching associated character, or 0 if none.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002765 */
2766 public char getMatch(char[] chars) {
2767 return getMatch(chars, 0);
2768 }
RoboErik01fe6612014-02-13 14:19:04 -08002769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002770 /**
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002771 * Gets the first character in the character array that can be generated
2772 * by the specified key code. If there are multiple choices, prefers
2773 * the one that would be generated with the specified meta key modifier state.
2774 *
2775 * @param chars The array of matching characters to consider.
2776 * @param metaState The preferred meta key modifier state.
2777 * @return The matching associated character, or 0 if none.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002778 */
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002779 public char getMatch(char[] chars, int metaState) {
2780 return getKeyCharacterMap().getMatch(mKeyCode, chars, metaState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002781 }
RoboErik01fe6612014-02-13 14:19:04 -08002782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 /**
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002784 * Gets the number or symbol associated with the key.
2785 * <p>
2786 * The character value is returned, not the numeric value.
2787 * If the key is not a number, but is a symbol, the symbol is retuned.
2788 * </p><p>
2789 * This method is intended to to support dial pads and other numeric or
2790 * symbolic entry on keyboards where certain keys serve dual function
2791 * as alphabetic and symbolic keys. This method returns the number
2792 * or symbol associated with the key independent of whether the user
2793 * has pressed the required modifier.
2794 * </p><p>
2795 * For example, on one particular keyboard the keys on the top QWERTY row generate
2796 * numbers when ALT is pressed such that ALT-Q maps to '1'. So for that keyboard
2797 * when {@link #getNumber} is called with {@link KeyEvent#KEYCODE_Q} it returns '1'
2798 * so that the user can type numbers without pressing ALT when it makes sense.
2799 * </p>
2800 *
2801 * @return The associated numeric or symbolic character, or 0 if none.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002802 */
2803 public char getNumber() {
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002804 return getKeyCharacterMap().getNumber(mKeyCode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002805 }
RoboErik01fe6612014-02-13 14:19:04 -08002806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002807 /**
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002808 * Returns true if this key produces a glyph.
2809 *
2810 * @return True if the key is a printing key.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002811 */
2812 public boolean isPrintingKey() {
Jeff Brown6b53e8d2010-11-10 16:03:06 -08002813 return getKeyCharacterMap().isPrintingKey(mKeyCode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002814 }
RoboErik01fe6612014-02-13 14:19:04 -08002815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816 /**
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002817 * @deprecated Use {@link #dispatch(Callback, DispatcherState, Object)} instead.
2818 */
2819 @Deprecated
2820 public final boolean dispatch(Callback receiver) {
2821 return dispatch(receiver, null, null);
2822 }
RoboErik01fe6612014-02-13 14:19:04 -08002823
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002824 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002825 * Deliver this key event to a {@link Callback} interface. If this is
2826 * an ACTION_MULTIPLE event and it is not handled, then an attempt will
2827 * be made to deliver a single normal event.
RoboErik01fe6612014-02-13 14:19:04 -08002828 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002829 * @param receiver The Callback that will be given the event.
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002830 * @param state State information retained across events.
2831 * @param target The target of the dispatch, for use in tracking.
RoboErik01fe6612014-02-13 14:19:04 -08002832 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 * @return The return value from the Callback method that was called.
2834 */
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002835 public final boolean dispatch(Callback receiver, DispatcherState state,
2836 Object target) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 switch (mAction) {
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002838 case ACTION_DOWN: {
2839 mFlags &= ~FLAG_START_TRACKING;
Dianne Hackborn8d374262009-09-14 21:21:52 -07002840 if (DEBUG) Log.v(TAG, "Key down to " + target + " in " + state
2841 + ": " + this);
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002842 boolean res = receiver.onKeyDown(mKeyCode, this);
2843 if (state != null) {
2844 if (res && mRepeatCount == 0 && (mFlags&FLAG_START_TRACKING) != 0) {
Dianne Hackborn8d374262009-09-14 21:21:52 -07002845 if (DEBUG) Log.v(TAG, " Start tracking!");
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002846 state.startTracking(this, target);
2847 } else if (isLongPress() && state.isTracking(this)) {
2848 try {
2849 if (receiver.onKeyLongPress(mKeyCode, this)) {
Dianne Hackborn8d374262009-09-14 21:21:52 -07002850 if (DEBUG) Log.v(TAG, " Clear from long press!");
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002851 state.performedLongPress(this);
2852 res = true;
2853 }
2854 } catch (AbstractMethodError e) {
2855 }
2856 }
2857 }
2858 return res;
2859 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 case ACTION_UP:
Dianne Hackborn8d374262009-09-14 21:21:52 -07002861 if (DEBUG) Log.v(TAG, "Key up to " + target + " in " + state
2862 + ": " + this);
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002863 if (state != null) {
2864 state.handleUpEvent(this);
2865 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866 return receiver.onKeyUp(mKeyCode, this);
2867 case ACTION_MULTIPLE:
2868 final int count = mRepeatCount;
2869 final int code = mKeyCode;
2870 if (receiver.onKeyMultiple(code, count, this)) {
2871 return true;
2872 }
2873 if (code != KeyEvent.KEYCODE_UNKNOWN) {
2874 mAction = ACTION_DOWN;
2875 mRepeatCount = 0;
2876 boolean handled = receiver.onKeyDown(code, this);
2877 if (handled) {
2878 mAction = ACTION_UP;
2879 receiver.onKeyUp(code, this);
2880 }
2881 mAction = ACTION_MULTIPLE;
2882 mRepeatCount = count;
2883 return handled;
2884 }
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002885 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002886 }
2887 return false;
2888 }
2889
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002890 /**
2891 * Use with {@link KeyEvent#dispatch(Callback, DispatcherState, Object)}
2892 * for more advanced key dispatching, such as long presses.
2893 */
2894 public static class DispatcherState {
2895 int mDownKeyCode;
2896 Object mDownTarget;
2897 SparseIntArray mActiveLongPresses = new SparseIntArray();
RoboErik01fe6612014-02-13 14:19:04 -08002898
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002899 /**
2900 * Reset back to initial state.
2901 */
2902 public void reset() {
Dianne Hackborn8d374262009-09-14 21:21:52 -07002903 if (DEBUG) Log.v(TAG, "Reset: " + this);
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002904 mDownKeyCode = 0;
2905 mDownTarget = null;
2906 mActiveLongPresses.clear();
2907 }
RoboErik01fe6612014-02-13 14:19:04 -08002908
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002909 /**
2910 * Stop any tracking associated with this target.
2911 */
2912 public void reset(Object target) {
2913 if (mDownTarget == target) {
Dianne Hackborn8d374262009-09-14 21:21:52 -07002914 if (DEBUG) Log.v(TAG, "Reset in " + target + ": " + this);
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002915 mDownKeyCode = 0;
2916 mDownTarget = null;
2917 }
2918 }
RoboErik01fe6612014-02-13 14:19:04 -08002919
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002920 /**
2921 * Start tracking the key code associated with the given event. This
2922 * can only be called on a key down. It will allow you to see any
2923 * long press associated with the key, and will result in
2924 * {@link KeyEvent#isTracking} return true on the long press and up
2925 * events.
RoboErik01fe6612014-02-13 14:19:04 -08002926 *
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002927 * <p>This is only needed if you are directly dispatching events, rather
2928 * than handling them in {@link Callback#onKeyDown}.
2929 */
2930 public void startTracking(KeyEvent event, Object target) {
2931 if (event.getAction() != ACTION_DOWN) {
2932 throw new IllegalArgumentException(
2933 "Can only start tracking on a down event");
2934 }
Dianne Hackborn8d374262009-09-14 21:21:52 -07002935 if (DEBUG) Log.v(TAG, "Start trackingt in " + target + ": " + this);
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002936 mDownKeyCode = event.getKeyCode();
2937 mDownTarget = target;
2938 }
RoboErik01fe6612014-02-13 14:19:04 -08002939
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002940 /**
2941 * Return true if the key event is for a key code that is currently
2942 * being tracked by the dispatcher.
2943 */
2944 public boolean isTracking(KeyEvent event) {
2945 return mDownKeyCode == event.getKeyCode();
2946 }
RoboErik01fe6612014-02-13 14:19:04 -08002947
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002948 /**
2949 * Keep track of the given event's key code as having performed an
2950 * action with a long press, so no action should occur on the up.
2951 * <p>This is only needed if you are directly dispatching events, rather
2952 * than handling them in {@link Callback#onKeyLongPress}.
2953 */
2954 public void performedLongPress(KeyEvent event) {
2955 mActiveLongPresses.put(event.getKeyCode(), 1);
2956 }
RoboErik01fe6612014-02-13 14:19:04 -08002957
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002958 /**
2959 * Handle key up event to stop tracking. This resets the dispatcher state,
2960 * and updates the key event state based on it.
2961 * <p>This is only needed if you are directly dispatching events, rather
2962 * than handling them in {@link Callback#onKeyUp}.
2963 */
2964 public void handleUpEvent(KeyEvent event) {
2965 final int keyCode = event.getKeyCode();
Dianne Hackborn8d374262009-09-14 21:21:52 -07002966 if (DEBUG) Log.v(TAG, "Handle key up " + event + ": " + this);
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002967 int index = mActiveLongPresses.indexOfKey(keyCode);
2968 if (index >= 0) {
Dianne Hackborn8d374262009-09-14 21:21:52 -07002969 if (DEBUG) Log.v(TAG, " Index: " + index);
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002970 event.mFlags |= FLAG_CANCELED | FLAG_CANCELED_LONG_PRESS;
2971 mActiveLongPresses.removeAt(index);
2972 }
2973 if (mDownKeyCode == keyCode) {
Dianne Hackborn8d374262009-09-14 21:21:52 -07002974 if (DEBUG) Log.v(TAG, " Tracking!");
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07002975 event.mFlags |= FLAG_TRACKING;
2976 mDownKeyCode = 0;
2977 mDownTarget = null;
2978 }
2979 }
2980 }
Jeff Brown497a92c2010-09-12 17:55:08 -07002981
2982 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 public String toString() {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002984 StringBuilder msg = new StringBuilder();
2985 msg.append("KeyEvent { action=").append(actionToString(mAction));
2986 msg.append(", keyCode=").append(keyCodeToString(mKeyCode));
2987 msg.append(", scanCode=").append(mScanCode);
2988 if (mCharacters != null) {
2989 msg.append(", characters=\"").append(mCharacters).append("\"");
2990 }
2991 msg.append(", metaState=").append(metaStateToString(mMetaState));
2992 msg.append(", flags=0x").append(Integer.toHexString(mFlags));
2993 msg.append(", repeatCount=").append(mRepeatCount);
2994 msg.append(", eventTime=").append(mEventTime);
2995 msg.append(", downTime=").append(mDownTime);
2996 msg.append(", deviceId=").append(mDeviceId);
2997 msg.append(", source=0x").append(Integer.toHexString(mSource));
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01002998 msg.append(", displayId=").append(mDisplayId);
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002999 msg.append(" }");
3000 return msg.toString();
Jeff Brown497a92c2010-09-12 17:55:08 -07003001 }
3002
3003 /**
3004 * Returns a string that represents the symbolic name of the specified action
Jeff Brown6f2fba42011-02-19 01:08:02 -08003005 * such as "ACTION_DOWN", or an equivalent numeric constant such as "35" if unknown.
Jeff Brown497a92c2010-09-12 17:55:08 -07003006 *
3007 * @param action The action.
3008 * @return The symbolic name of the specified action.
3009 * @hide
3010 */
Siarhei Vishniakou4c96a5e2018-04-24 17:57:44 -07003011 @TestApi
Jeff Brown497a92c2010-09-12 17:55:08 -07003012 public static String actionToString(int action) {
3013 switch (action) {
3014 case ACTION_DOWN:
3015 return "ACTION_DOWN";
3016 case ACTION_UP:
3017 return "ACTION_UP";
3018 case ACTION_MULTIPLE:
3019 return "ACTION_MULTIPLE";
3020 default:
3021 return Integer.toString(action);
3022 }
3023 }
3024
3025 /**
3026 * Returns a string that represents the symbolic name of the specified keycode
Jeff Brown6f2fba42011-02-19 01:08:02 -08003027 * such as "KEYCODE_A", "KEYCODE_DPAD_UP", or an equivalent numeric constant
3028 * such as "1001" if unknown.
Jeff Brown497a92c2010-09-12 17:55:08 -07003029 *
Siarhei Vishniakou6ace3f22018-07-17 17:10:00 +01003030 * This function is intended to be used mostly for debugging, logging, and testing. It is not
3031 * locale-specific and is not intended to be used in a user-facing manner.
3032 *
Jeff Brown497a92c2010-09-12 17:55:08 -07003033 * @param keyCode The key code.
3034 * @return The symbolic name of the specified keycode.
3035 *
3036 * @see KeyCharacterMap#getDisplayLabel
Jeff Brown497a92c2010-09-12 17:55:08 -07003037 */
3038 public static String keyCodeToString(int keyCode) {
Michael Wright337d9d22014-04-22 15:03:48 -07003039 String symbolicName = nativeKeyCodeToString(keyCode);
3040 return symbolicName != null ? LABEL_PREFIX + symbolicName : Integer.toString(keyCode);
Jeff Brown497a92c2010-09-12 17:55:08 -07003041 }
3042
3043 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08003044 * Gets a keycode by its symbolic name such as "KEYCODE_A" or an equivalent
Siarhei Vishniakoude1f9042018-05-09 09:54:43 -07003045 * numeric constant such as "29". For symbolic names,
3046 * starting in {@link android.os.Build.VERSION_CODES#Q} the prefix "KEYCODE_" is optional.
Jeff Brown497a92c2010-09-12 17:55:08 -07003047 *
3048 * @param symbolicName The symbolic name of the keycode.
Jeff Brown6f2fba42011-02-19 01:08:02 -08003049 * @return The keycode or {@link #KEYCODE_UNKNOWN} if not found.
Aurimas Liutikase701dc12018-06-01 16:04:37 -07003050 * @see #keyCodeToString(int)
Jeff Brown497a92c2010-09-12 17:55:08 -07003051 */
Siarhei Vishniakoude1f9042018-05-09 09:54:43 -07003052 public static int keyCodeFromString(@NonNull String symbolicName) {
3053 try {
3054 int keyCode = Integer.parseInt(symbolicName);
3055 if (keyCodeIsValid(keyCode)) {
Michael Wright973efa02014-05-13 15:38:56 -07003056 return keyCode;
3057 }
Jeff Brown497a92c2010-09-12 17:55:08 -07003058 } catch (NumberFormatException ex) {
Jeff Brown497a92c2010-09-12 17:55:08 -07003059 }
Siarhei Vishniakoude1f9042018-05-09 09:54:43 -07003060
3061 if (symbolicName.startsWith(LABEL_PREFIX)) {
3062 symbolicName = symbolicName.substring(LABEL_PREFIX.length());
3063 }
3064 int keyCode = nativeKeyCodeFromString(symbolicName);
3065 if (keyCodeIsValid(keyCode)) {
3066 return keyCode;
3067 }
3068 return KEYCODE_UNKNOWN;
3069 }
3070
3071 private static boolean keyCodeIsValid(int keyCode) {
3072 return keyCode >= KEYCODE_UNKNOWN && keyCode <= LAST_KEYCODE;
Jeff Brown497a92c2010-09-12 17:55:08 -07003073 }
3074
3075 /**
3076 * Returns a string that represents the symbolic name of the specified combined meta
3077 * key modifier state flags such as "0", "META_SHIFT_ON",
Jeff Brown6f2fba42011-02-19 01:08:02 -08003078 * "META_ALT_ON|META_SHIFT_ON" or an equivalent numeric constant such as "0x10000000"
3079 * if unknown.
Jeff Brown497a92c2010-09-12 17:55:08 -07003080 *
3081 * @param metaState The meta state.
3082 * @return The symbolic name of the specified combined meta state flags.
3083 * @hide
3084 */
3085 public static String metaStateToString(int metaState) {
3086 if (metaState == 0) {
3087 return "0";
3088 }
3089 StringBuilder result = null;
3090 int i = 0;
3091 while (metaState != 0) {
3092 final boolean isSet = (metaState & 1) != 0;
3093 metaState >>>= 1; // unsigned shift!
3094 if (isSet) {
3095 final String name = META_SYMBOLIC_NAMES[i];
3096 if (result == null) {
3097 if (metaState == 0) {
3098 return name;
3099 }
3100 result = new StringBuilder(name);
3101 } else {
3102 result.append('|');
3103 result.append(name);
3104 }
3105 }
3106 i += 1;
3107 }
3108 return result.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003109 }
3110
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07003111 public static final @android.annotation.NonNull Parcelable.Creator<KeyEvent> CREATOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003112 = new Parcelable.Creator<KeyEvent>() {
Jim Miller07e03842016-06-22 15:18:13 -07003113 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003114 public KeyEvent createFromParcel(Parcel in) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07003115 in.readInt(); // skip token, we already know this is a KeyEvent
3116 return KeyEvent.createFromParcelBody(in);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003117 }
3118
Jim Miller07e03842016-06-22 15:18:13 -07003119 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003120 public KeyEvent[] newArray(int size) {
3121 return new KeyEvent[size];
3122 }
3123 };
RoboErik01fe6612014-02-13 14:19:04 -08003124
Jeff Brown6ec402b2010-07-28 15:48:59 -07003125 /** @hide */
3126 public static KeyEvent createFromParcelBody(Parcel in) {
3127 return new KeyEvent(in);
3128 }
RoboErik01fe6612014-02-13 14:19:04 -08003129
Jeff Brown6ec402b2010-07-28 15:48:59 -07003130 private KeyEvent(Parcel in) {
Garfield Tanc8362b22020-01-24 11:32:14 -08003131 mId = in.readInt();
Jeff Brown91c69ab2011-02-14 17:03:18 -08003132 mDeviceId = in.readInt();
3133 mSource = in.readInt();
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01003134 mDisplayId = in.readInt();
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -06003135 mHmac = in.createByteArray();
Jeff Brown6ec402b2010-07-28 15:48:59 -07003136 mAction = in.readInt();
3137 mKeyCode = in.readInt();
3138 mRepeatCount = in.readInt();
3139 mMetaState = in.readInt();
3140 mScanCode = in.readInt();
3141 mFlags = in.readInt();
3142 mDownTime = in.readLong();
3143 mEventTime = in.readLong();
Siarhei Vishniakoue481d332018-07-18 14:46:00 +01003144 mCharacters = in.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003145 }
3146
Jim Miller07e03842016-06-22 15:18:13 -07003147 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003148 public void writeToParcel(Parcel out, int flags) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07003149 out.writeInt(PARCEL_TOKEN_KEY_EVENT);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003150
Garfield Tanc8362b22020-01-24 11:32:14 -08003151 out.writeInt(mId);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003152 out.writeInt(mDeviceId);
3153 out.writeInt(mSource);
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01003154 out.writeInt(mDisplayId);
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -06003155 out.writeByteArray(mHmac);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003156 out.writeInt(mAction);
3157 out.writeInt(mKeyCode);
3158 out.writeInt(mRepeatCount);
3159 out.writeInt(mMetaState);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003160 out.writeInt(mScanCode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003161 out.writeInt(mFlags);
3162 out.writeLong(mDownTime);
3163 out.writeLong(mEventTime);
Siarhei Vishniakoue481d332018-07-18 14:46:00 +01003164 out.writeString(mCharacters);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003166}