• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "key_event.h"
17 
18 #include "mmi_log.h"
19 
20 
21 using namespace OHOS::HiviewDFX;
22 namespace OHOS {
23 namespace MMI {
24 namespace {
25 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "KeyEvent"};
26 } // namespace
27 const int32_t KeyEvent::UNKOWN_FUNCTION_KEY = -1;
28 const int32_t KeyEvent::NUM_LOCK_FUNCTION_KEY = 0;
29 const int32_t KeyEvent::CAPS_LOCK_FUNCTION_KEY = 1;
30 const int32_t KeyEvent::SCROLL_LOCK_FUNCTION_KEY = 2;
31 const int32_t KeyEvent::KEYCODE_FN = 0;
32 const int32_t KeyEvent::KEYCODE_UNKNOWN = -1;
33 const int32_t KeyEvent::KEYCODE_HOME = 1;
34 const int32_t KeyEvent::KEYCODE_BACK = 2;
35 const int32_t KeyEvent::KEYCODE_CALL = 3;
36 const int32_t KeyEvent::KEYCODE_ENDCALL = 4;
37 const int32_t KeyEvent::KEYCODE_CLEAR = 5;
38 const int32_t KeyEvent::KEYCODE_HEADSETHOOK = 6;
39 const int32_t KeyEvent::KEYCODE_FOCUS = 7;
40 const int32_t KeyEvent::KEYCODE_NOTIFICATION = 8;
41 const int32_t KeyEvent::KEYCODE_SEARCH = 9;
42 const int32_t KeyEvent::KEYCODE_MEDIA_PLAY_PAUSE = 10;
43 const int32_t KeyEvent::KEYCODE_MEDIA_STOP = 11;
44 const int32_t KeyEvent::KEYCODE_MEDIA_NEXT = 12;
45 const int32_t KeyEvent::KEYCODE_MEDIA_PREVIOUS = 13;
46 const int32_t KeyEvent::KEYCODE_MEDIA_REWIND = 14;
47 const int32_t KeyEvent::KEYCODE_MEDIA_FAST_FORWARD = 15;
48 const int32_t KeyEvent::KEYCODE_VOLUME_UP = 16;
49 const int32_t KeyEvent::KEYCODE_VOLUME_DOWN = 17;
50 const int32_t KeyEvent::KEYCODE_POWER = 18;
51 const int32_t KeyEvent::KEYCODE_CAMERA = 19;
52 const int32_t KeyEvent::KEYCODE_VOICE_ASSISTANT = 20;
53 const int32_t KeyEvent::KEYCODE_CUSTOM1 = 21;
54 const int32_t KeyEvent::KEYCODE_VOLUME_MUTE = 22;
55 const int32_t KeyEvent::KEYCODE_MUTE = 23;
56 const int32_t KeyEvent::KEYCODE_BRIGHTNESS_UP = 40;
57 const int32_t KeyEvent::KEYCODE_BRIGHTNESS_DOWN = 41;
58 const int32_t KeyEvent::KEYCODE_WEAR_1 = 1001;
59 const int32_t KeyEvent::KEYCODE_0 = 2000;
60 const int32_t KeyEvent::KEYCODE_1 = 2001;
61 const int32_t KeyEvent::KEYCODE_2 = 2002;
62 const int32_t KeyEvent::KEYCODE_3 = 2003;
63 const int32_t KeyEvent::KEYCODE_4 = 2004;
64 const int32_t KeyEvent::KEYCODE_5 = 2005;
65 const int32_t KeyEvent::KEYCODE_6 = 2006;
66 const int32_t KeyEvent::KEYCODE_7 = 2007;
67 const int32_t KeyEvent::KEYCODE_8 = 2008;
68 const int32_t KeyEvent::KEYCODE_9 = 2009;
69 const int32_t KeyEvent::KEYCODE_STAR = 2010;
70 const int32_t KeyEvent::KEYCODE_POUND = 2011;
71 const int32_t KeyEvent::KEYCODE_DPAD_UP = 2012;
72 const int32_t KeyEvent::KEYCODE_DPAD_DOWN = 2013;
73 const int32_t KeyEvent::KEYCODE_DPAD_LEFT = 2014;
74 const int32_t KeyEvent::KEYCODE_DPAD_RIGHT = 2015;
75 const int32_t KeyEvent::KEYCODE_DPAD_CENTER = 2016;
76 const int32_t KeyEvent::KEYCODE_A = 2017;
77 const int32_t KeyEvent::KEYCODE_B = 2018;
78 const int32_t KeyEvent::KEYCODE_C = 2019;
79 const int32_t KeyEvent::KEYCODE_D = 2020;
80 const int32_t KeyEvent::KEYCODE_E = 2021;
81 const int32_t KeyEvent::KEYCODE_F = 2022;
82 const int32_t KeyEvent::KEYCODE_G = 2023;
83 const int32_t KeyEvent::KEYCODE_H = 2024;
84 const int32_t KeyEvent::KEYCODE_I = 2025;
85 const int32_t KeyEvent::KEYCODE_J = 2026;
86 const int32_t KeyEvent::KEYCODE_K = 2027;
87 const int32_t KeyEvent::KEYCODE_L = 2028;
88 const int32_t KeyEvent::KEYCODE_M = 2029;
89 const int32_t KeyEvent::KEYCODE_N = 2030;
90 const int32_t KeyEvent::KEYCODE_O = 2031;
91 const int32_t KeyEvent::KEYCODE_P = 2032;
92 const int32_t KeyEvent::KEYCODE_Q = 2033;
93 const int32_t KeyEvent::KEYCODE_R = 2034;
94 const int32_t KeyEvent::KEYCODE_S = 2035;
95 const int32_t KeyEvent::KEYCODE_T = 2036;
96 const int32_t KeyEvent::KEYCODE_U = 2037;
97 const int32_t KeyEvent::KEYCODE_V = 2038;
98 const int32_t KeyEvent::KEYCODE_W = 2039;
99 const int32_t KeyEvent::KEYCODE_X = 2040;
100 const int32_t KeyEvent::KEYCODE_Y = 2041;
101 const int32_t KeyEvent::KEYCODE_Z = 2042;
102 const int32_t KeyEvent::KEYCODE_COMMA = 2043;
103 const int32_t KeyEvent::KEYCODE_PERIOD = 2044;
104 const int32_t KeyEvent::KEYCODE_ALT_LEFT = 2045;
105 const int32_t KeyEvent::KEYCODE_ALT_RIGHT = 2046;
106 const int32_t KeyEvent::KEYCODE_SHIFT_LEFT = 2047;
107 const int32_t KeyEvent::KEYCODE_SHIFT_RIGHT = 2048;
108 const int32_t KeyEvent::KEYCODE_TAB = 2049;
109 const int32_t KeyEvent::KEYCODE_SPACE = 2050;
110 const int32_t KeyEvent::KEYCODE_SYM = 2051;
111 const int32_t KeyEvent::KEYCODE_EXPLORER = 2052;
112 const int32_t KeyEvent::KEYCODE_ENVELOPE = 2053;
113 const int32_t KeyEvent::KEYCODE_ENTER = 2054;
114 const int32_t KeyEvent::KEYCODE_DEL = 2055;
115 const int32_t KeyEvent::KEYCODE_GRAVE = 2056;
116 const int32_t KeyEvent::KEYCODE_MINUS = 2057;
117 const int32_t KeyEvent::KEYCODE_EQUALS = 2058;
118 const int32_t KeyEvent::KEYCODE_LEFT_BRACKET = 2059;
119 const int32_t KeyEvent::KEYCODE_RIGHT_BRACKET = 2060;
120 const int32_t KeyEvent::KEYCODE_BACKSLASH = 2061;
121 const int32_t KeyEvent::KEYCODE_SEMICOLON = 2062;
122 const int32_t KeyEvent::KEYCODE_APOSTROPHE = 2063;
123 const int32_t KeyEvent::KEYCODE_SLASH = 2064;
124 const int32_t KeyEvent::KEYCODE_AT = 2065;
125 const int32_t KeyEvent::KEYCODE_PLUS = 2066;
126 const int32_t KeyEvent::KEYCODE_MENU = 2067;
127 const int32_t KeyEvent::KEYCODE_PAGE_UP = 2068;
128 const int32_t KeyEvent::KEYCODE_PAGE_DOWN = 2069;
129 const int32_t KeyEvent::KEYCODE_ESCAPE = 2070;
130 const int32_t KeyEvent::KEYCODE_FORWARD_DEL = 2071;
131 const int32_t KeyEvent::KEYCODE_CTRL_LEFT = 2072;
132 const int32_t KeyEvent::KEYCODE_CTRL_RIGHT = 2073;
133 const int32_t KeyEvent::KEYCODE_CAPS_LOCK = 2074;
134 const int32_t KeyEvent::KEYCODE_SCROLL_LOCK = 2075;
135 const int32_t KeyEvent::KEYCODE_META_LEFT = 2076;
136 const int32_t KeyEvent::KEYCODE_META_RIGHT = 2077;
137 const int32_t KeyEvent::KEYCODE_FUNCTION = 2078;
138 const int32_t KeyEvent::KEYCODE_SYSRQ = 2079;
139 const int32_t KeyEvent::KEYCODE_BREAK = 2080;
140 const int32_t KeyEvent::KEYCODE_MOVE_HOME = 2081;
141 const int32_t KeyEvent::KEYCODE_MOVE_END = 2082;
142 const int32_t KeyEvent::KEYCODE_INSERT = 2083;
143 const int32_t KeyEvent::KEYCODE_FORWARD = 2084;
144 const int32_t KeyEvent::KEYCODE_MEDIA_PLAY = 2085;
145 const int32_t KeyEvent::KEYCODE_MEDIA_PAUSE = 2086;
146 const int32_t KeyEvent::KEYCODE_MEDIA_CLOSE = 2087;
147 const int32_t KeyEvent::KEYCODE_MEDIA_EJECT = 2088;
148 const int32_t KeyEvent::KEYCODE_MEDIA_RECORD = 2089;
149 const int32_t KeyEvent::KEYCODE_F1 = 2090;
150 const int32_t KeyEvent::KEYCODE_F2 = 2091;
151 const int32_t KeyEvent::KEYCODE_F3 = 2092;
152 const int32_t KeyEvent::KEYCODE_F4 = 2093;
153 const int32_t KeyEvent::KEYCODE_F5 = 2094;
154 const int32_t KeyEvent::KEYCODE_F6 = 2095;
155 const int32_t KeyEvent::KEYCODE_F7 = 2096;
156 const int32_t KeyEvent::KEYCODE_F8 = 2097;
157 const int32_t KeyEvent::KEYCODE_F9 = 2098;
158 const int32_t KeyEvent::KEYCODE_F10 = 2099;
159 const int32_t KeyEvent::KEYCODE_F11 = 2100;
160 const int32_t KeyEvent::KEYCODE_F12 = 2101;
161 const int32_t KeyEvent::KEYCODE_NUM_LOCK = 2102;
162 const int32_t KeyEvent::KEYCODE_NUMPAD_0 = 2103;
163 const int32_t KeyEvent::KEYCODE_NUMPAD_1 = 2104;
164 const int32_t KeyEvent::KEYCODE_NUMPAD_2 = 2105;
165 const int32_t KeyEvent::KEYCODE_NUMPAD_3 = 2106;
166 const int32_t KeyEvent::KEYCODE_NUMPAD_4 = 2107;
167 const int32_t KeyEvent::KEYCODE_NUMPAD_5 = 2108;
168 const int32_t KeyEvent::KEYCODE_NUMPAD_6 = 2109;
169 const int32_t KeyEvent::KEYCODE_NUMPAD_7 = 2110;
170 const int32_t KeyEvent::KEYCODE_NUMPAD_8 = 2111;
171 const int32_t KeyEvent::KEYCODE_NUMPAD_9 = 2112;
172 const int32_t KeyEvent::KEYCODE_NUMPAD_DIVIDE = 2113;
173 const int32_t KeyEvent::KEYCODE_NUMPAD_MULTIPLY = 2114;
174 const int32_t KeyEvent::KEYCODE_NUMPAD_SUBTRACT = 2115;
175 const int32_t KeyEvent::KEYCODE_NUMPAD_ADD = 2116;
176 const int32_t KeyEvent::KEYCODE_NUMPAD_DOT = 2117;
177 const int32_t KeyEvent::KEYCODE_NUMPAD_COMMA = 2118;
178 const int32_t KeyEvent::KEYCODE_NUMPAD_ENTER = 2119;
179 const int32_t KeyEvent::KEYCODE_NUMPAD_EQUALS = 2120;
180 const int32_t KeyEvent::KEYCODE_NUMPAD_LEFT_PAREN = 2121;
181 const int32_t KeyEvent::KEYCODE_NUMPAD_RIGHT_PAREN = 2122;
182 const int32_t KeyEvent::KEYCODE_VIRTUAL_MULTITASK = 2210;
183 const int32_t KeyEvent::KEYCODE_BUTTON_A = 2301;
184 const int32_t KeyEvent::KEYCODE_BUTTON_B = 2302;
185 const int32_t KeyEvent::KEYCODE_BUTTON_C = 2303;
186 const int32_t KeyEvent::KEYCODE_BUTTON_X = 2304;
187 const int32_t KeyEvent::KEYCODE_BUTTON_Y = 2305;
188 const int32_t KeyEvent::KEYCODE_BUTTON_Z = 2306;
189 const int32_t KeyEvent::KEYCODE_BUTTON_L1 = 2307;
190 const int32_t KeyEvent::KEYCODE_BUTTON_R1 = 2308;
191 const int32_t KeyEvent::KEYCODE_BUTTON_L2 = 2309;
192 const int32_t KeyEvent::KEYCODE_BUTTON_R2 = 2310;
193 const int32_t KeyEvent::KEYCODE_BUTTON_SELECT = 2311;
194 const int32_t KeyEvent::KEYCODE_BUTTON_START = 2312;
195 const int32_t KeyEvent::KEYCODE_BUTTON_MODE = 2313;
196 const int32_t KeyEvent::KEYCODE_BUTTON_THUMBL = 2314;
197 const int32_t KeyEvent::KEYCODE_BUTTON_THUMBR = 2315;
198 const int32_t KeyEvent::KEYCODE_BUTTON_TRIGGER = 2401;
199 const int32_t KeyEvent::KEYCODE_BUTTON_THUMB = 2402;
200 const int32_t KeyEvent::KEYCODE_BUTTON_THUMB2 = 2403;
201 const int32_t KeyEvent::KEYCODE_BUTTON_TOP = 2404;
202 const int32_t KeyEvent::KEYCODE_BUTTON_TOP2 = 2405;
203 const int32_t KeyEvent::KEYCODE_BUTTON_PINKIE = 2406;
204 const int32_t KeyEvent::KEYCODE_BUTTON_BASE1 = 2407;
205 const int32_t KeyEvent::KEYCODE_BUTTON_BASE2 = 2408;
206 const int32_t KeyEvent::KEYCODE_BUTTON_BASE3 = 2409;
207 const int32_t KeyEvent::KEYCODE_BUTTON_BASE4 = 2410;
208 const int32_t KeyEvent::KEYCODE_BUTTON_BASE5 = 2411;
209 const int32_t KeyEvent::KEYCODE_BUTTON_BASE6 = 2412;
210 const int32_t KeyEvent::KEYCODE_BUTTON_BASE7 = 2413;
211 const int32_t KeyEvent::KEYCODE_BUTTON_BASE8 = 2414;
212 const int32_t KeyEvent::KEYCODE_BUTTON_BASE9 = 2415;
213 const int32_t KeyEvent::KEYCODE_BUTTON_DEAD = 2416;
214 const int32_t KeyEvent::KEYCODE_SLEEP = 2600;
215 const int32_t KeyEvent::KEYCODE_ZENKAKU_HANKAKU = 2601;
216 const int32_t KeyEvent::KEYCODE_102ND = 2602;
217 const int32_t KeyEvent::KEYCODE_RO = 2603;
218 const int32_t KeyEvent::KEYCODE_KATAKANA = 2604;
219 const int32_t KeyEvent::KEYCODE_HIRAGANA = 2605;
220 const int32_t KeyEvent::KEYCODE_HENKAN = 2606;
221 const int32_t KeyEvent::KEYCODE_KATAKANA_HIRAGANA = 2607;
222 const int32_t KeyEvent::KEYCODE_MUHENKAN = 2608;
223 const int32_t KeyEvent::KEYCODE_LINEFEED = 2609;
224 const int32_t KeyEvent::KEYCODE_MACRO = 2610;
225 const int32_t KeyEvent::KEYCODE_NUMPAD_PLUSMINUS = 2611;
226 const int32_t KeyEvent::KEYCODE_SCALE = 2612;
227 const int32_t KeyEvent::KEYCODE_HANGUEL = 2613;
228 const int32_t KeyEvent::KEYCODE_HANJA = 2614;
229 const int32_t KeyEvent::KEYCODE_YEN = 2615;
230 const int32_t KeyEvent::KEYCODE_STOP = 2616;
231 const int32_t KeyEvent::KEYCODE_AGAIN = 2617;
232 const int32_t KeyEvent::KEYCODE_PROPS = 2618;
233 const int32_t KeyEvent::KEYCODE_UNDO = 2619;
234 const int32_t KeyEvent::KEYCODE_COPY = 2620;
235 const int32_t KeyEvent::KEYCODE_OPEN = 2621;
236 const int32_t KeyEvent::KEYCODE_PASTE = 2622;
237 const int32_t KeyEvent::KEYCODE_FIND = 2623;
238 const int32_t KeyEvent::KEYCODE_CUT = 2624;
239 const int32_t KeyEvent::KEYCODE_HELP = 2625;
240 const int32_t KeyEvent::KEYCODE_CALC = 2626;
241 const int32_t KeyEvent::KEYCODE_FILE = 2627;
242 const int32_t KeyEvent::KEYCODE_BOOKMARKS = 2628;
243 const int32_t KeyEvent::KEYCODE_NEXT = 2629;
244 const int32_t KeyEvent::KEYCODE_PLAYPAUSE = 2630;
245 const int32_t KeyEvent::KEYCODE_PREVIOUS = 2631;
246 const int32_t KeyEvent::KEYCODE_STOPCD = 2632;
247 const int32_t KeyEvent::KEYCODE_CONFIG = 2634;
248 const int32_t KeyEvent::KEYCODE_REFRESH = 2635;
249 const int32_t KeyEvent::KEYCODE_EXIT = 2636;
250 const int32_t KeyEvent::KEYCODE_EDIT = 2637;
251 const int32_t KeyEvent::KEYCODE_SCROLLUP = 2638;
252 const int32_t KeyEvent::KEYCODE_SCROLLDOWN = 2639;
253 const int32_t KeyEvent::KEYCODE_NEW = 2640;
254 const int32_t KeyEvent::KEYCODE_REDO = 2641;
255 const int32_t KeyEvent::KEYCODE_CLOSE = 2642;
256 const int32_t KeyEvent::KEYCODE_PLAY = 2643;
257 const int32_t KeyEvent::KEYCODE_BASSBOOST = 2644;
258 const int32_t KeyEvent::KEYCODE_PRINT = 2645;
259 const int32_t KeyEvent::KEYCODE_CHAT = 2646;
260 const int32_t KeyEvent::KEYCODE_FINANCE = 2647;
261 const int32_t KeyEvent::KEYCODE_CANCEL = 2648;
262 const int32_t KeyEvent::KEYCODE_KBDILLUM_TOGGLE = 2649;
263 const int32_t KeyEvent::KEYCODE_KBDILLUM_DOWN = 2650;
264 const int32_t KeyEvent::KEYCODE_KBDILLUM_UP = 2651;
265 const int32_t KeyEvent::KEYCODE_SEND = 2652;
266 const int32_t KeyEvent::KEYCODE_REPLY = 2653;
267 const int32_t KeyEvent::KEYCODE_FORWARDMAIL = 2654;
268 const int32_t KeyEvent::KEYCODE_SAVE = 2655;
269 const int32_t KeyEvent::KEYCODE_DOCUMENTS = 2656;
270 const int32_t KeyEvent::KEYCODE_VIDEO_NEXT = 2657;
271 const int32_t KeyEvent::KEYCODE_VIDEO_PREV = 2658;
272 const int32_t KeyEvent::KEYCODE_BRIGHTNESS_CYCLE = 2659;
273 const int32_t KeyEvent::KEYCODE_BRIGHTNESS_ZERO = 2660;
274 const int32_t KeyEvent::KEYCODE_DISPLAY_OFF = 2661;
275 const int32_t KeyEvent::KEYCODE_BTN_MISC = 2662;
276 const int32_t KeyEvent::KEYCODE_GOTO = 2663;
277 const int32_t KeyEvent::KEYCODE_INFO = 2664;
278 const int32_t KeyEvent::KEYCODE_PROGRAM = 2665;
279 const int32_t KeyEvent::KEYCODE_PVR = 2666;
280 const int32_t KeyEvent::KEYCODE_SUBTITLE = 2667;
281 const int32_t KeyEvent::KEYCODE_FULL_SCREEN = 2668;
282 const int32_t KeyEvent::KEYCODE_KEYBOARD = 2669;
283 const int32_t KeyEvent::KEYCODE_ASPECT_RATIO = 2670;
284 const int32_t KeyEvent::KEYCODE_PC = 2671;
285 const int32_t KeyEvent::KEYCODE_TV = 2672;
286 const int32_t KeyEvent::KEYCODE_TV2 = 2673;
287 const int32_t KeyEvent::KEYCODE_VCR = 2674;
288 const int32_t KeyEvent::KEYCODE_VCR2 = 2675;
289 const int32_t KeyEvent::KEYCODE_SAT = 2676;
290 const int32_t KeyEvent::KEYCODE_CD = 2677;
291 const int32_t KeyEvent::KEYCODE_TAPE = 2678;
292 const int32_t KeyEvent::KEYCODE_TUNER = 2679;
293 const int32_t KeyEvent::KEYCODE_PLAYER = 2680;
294 const int32_t KeyEvent::KEYCODE_DVD = 2681;
295 const int32_t KeyEvent::KEYCODE_AUDIO = 2682;
296 const int32_t KeyEvent::KEYCODE_VIDEO = 2683;
297 const int32_t KeyEvent::KEYCODE_MEMO = 2684;
298 const int32_t KeyEvent::KEYCODE_CALENDAR = 2685;
299 const int32_t KeyEvent::KEYCODE_RED = 2686;
300 const int32_t KeyEvent::KEYCODE_GREEN = 2687;
301 const int32_t KeyEvent::KEYCODE_YELLOW = 2688;
302 const int32_t KeyEvent::KEYCODE_BLUE = 2689;
303 const int32_t KeyEvent::KEYCODE_CHANNELUP = 2690;
304 const int32_t KeyEvent::KEYCODE_CHANNELDOWN = 2691;
305 const int32_t KeyEvent::KEYCODE_LAST = 2692;
306 const int32_t KeyEvent::KEYCODE_RESTART = 2693;
307 const int32_t KeyEvent::KEYCODE_SLOW = 2694;
308 const int32_t KeyEvent::KEYCODE_SHUFFLE = 2695;
309 const int32_t KeyEvent::KEYCODE_VIDEOPHONE = 2696;
310 const int32_t KeyEvent::KEYCODE_GAMES = 2697;
311 const int32_t KeyEvent::KEYCODE_ZOOMIN = 2698;
312 const int32_t KeyEvent::KEYCODE_ZOOMOUT = 2699;
313 const int32_t KeyEvent::KEYCODE_ZOOMRESET = 2700;
314 const int32_t KeyEvent::KEYCODE_WORDPROCESSOR = 2701;
315 const int32_t KeyEvent::KEYCODE_EDITOR = 2702;
316 const int32_t KeyEvent::KEYCODE_SPREADSHEET = 2703;
317 const int32_t KeyEvent::KEYCODE_GRAPHICSEDITOR = 2704;
318 const int32_t KeyEvent::KEYCODE_PRESENTATION = 2705;
319 const int32_t KeyEvent::KEYCODE_DATABASE = 2706;
320 const int32_t KeyEvent::KEYCODE_NEWS = 2707;
321 const int32_t KeyEvent::KEYCODE_VOICEMAIL = 2708;
322 const int32_t KeyEvent::KEYCODE_ADDRESSBOOK = 2709;
323 const int32_t KeyEvent::KEYCODE_MESSENGER = 2710;
324 const int32_t KeyEvent::KEYCODE_BRIGHTNESS_TOGGLE = 2711;
325 const int32_t KeyEvent::KEYCODE_SPELLCHECK = 2712;
326 const int32_t KeyEvent::KEYCODE_COFFEE = 2713;
327 const int32_t KeyEvent::KEYCODE_MEDIA_REPEAT = 2714;
328 const int32_t KeyEvent::KEYCODE_IMAGES = 2715;
329 const int32_t KeyEvent::KEYCODE_BUTTONCONFIG = 2716;
330 const int32_t KeyEvent::KEYCODE_TASKMANAGER = 2717;
331 const int32_t KeyEvent::KEYCODE_JOURNAL = 2718;
332 const int32_t KeyEvent::KEYCODE_CONTROLPANEL = 2719;
333 const int32_t KeyEvent::KEYCODE_APPSELECT = 2720;
334 const int32_t KeyEvent::KEYCODE_SCREENSAVER = 2721;
335 const int32_t KeyEvent::KEYCODE_ASSISTANT = 2722;
336 const int32_t KeyEvent::KEYCODE_KBD_LAYOUT_NEXT = 2723;
337 const int32_t KeyEvent::KEYCODE_BRIGHTNESS_MIN = 2724;
338 const int32_t KeyEvent::KEYCODE_BRIGHTNESS_MAX = 2725;
339 const int32_t KeyEvent::KEYCODE_KBDINPUTASSIST_PREV = 2726;
340 const int32_t KeyEvent::KEYCODE_KBDINPUTASSIST_NEXT = 2727;
341 const int32_t KeyEvent::KEYCODE_KBDINPUTASSIST_PREVGROUP = 2728;
342 const int32_t KeyEvent::KEYCODE_KBDINPUTASSIST_NEXTGROUP = 2729;
343 const int32_t KeyEvent::KEYCODE_KBDINPUTASSIST_ACCEPT = 2730;
344 const int32_t KeyEvent::KEYCODE_KBDINPUTASSIST_CANCEL = 2731;
345 const int32_t KeyEvent::KEYCODE_FRONT = 2800;
346 const int32_t KeyEvent::KEYCODE_SETUP = 2801;
347 const int32_t KeyEvent::KEYCODE_WAKEUP = 2802;
348 const int32_t KeyEvent::KEYCODE_SENDFILE = 2803;
349 const int32_t KeyEvent::KEYCODE_DELETEFILE = 2804;
350 const int32_t KeyEvent::KEYCODE_XFER = 2805;
351 const int32_t KeyEvent::KEYCODE_PROG1 = 2806;
352 const int32_t KeyEvent::KEYCODE_PROG2 = 2807;
353 const int32_t KeyEvent::KEYCODE_MSDOS = 2808;
354 const int32_t KeyEvent::KEYCODE_SCREENLOCK = 2809;
355 const int32_t KeyEvent::KEYCODE_DIRECTION_ROTATE_DISPLAY = 2810;
356 const int32_t KeyEvent::KEYCODE_CYCLEWINDOWS = 2811;
357 const int32_t KeyEvent::KEYCODE_COMPUTER = 2812;
358 const int32_t KeyEvent::KEYCODE_EJECTCLOSECD = 2813;
359 const int32_t KeyEvent::KEYCODE_ISO = 2814;
360 const int32_t KeyEvent::KEYCODE_MOVE = 2815;
361 const int32_t KeyEvent::KEYCODE_F13 = 2816;
362 const int32_t KeyEvent::KEYCODE_F14 = 2817;
363 const int32_t KeyEvent::KEYCODE_F15 = 2818;
364 const int32_t KeyEvent::KEYCODE_F16 = 2819;
365 const int32_t KeyEvent::KEYCODE_F17 = 2820;
366 const int32_t KeyEvent::KEYCODE_F18 = 2821;
367 const int32_t KeyEvent::KEYCODE_F19 = 2822;
368 const int32_t KeyEvent::KEYCODE_F20 = 2823;
369 const int32_t KeyEvent::KEYCODE_F21 = 2824;
370 const int32_t KeyEvent::KEYCODE_F22 = 2825;
371 const int32_t KeyEvent::KEYCODE_F23 = 2826;
372 const int32_t KeyEvent::KEYCODE_F24 = 2827;
373 const int32_t KeyEvent::KEYCODE_PROG3 = 2828;
374 const int32_t KeyEvent::KEYCODE_PROG4 = 2829;
375 const int32_t KeyEvent::KEYCODE_DASHBOARD = 2830;
376 const int32_t KeyEvent::KEYCODE_SUSPEND = 2831;
377 const int32_t KeyEvent::KEYCODE_HP = 2832;
378 const int32_t KeyEvent::KEYCODE_SOUND = 2833;
379 const int32_t KeyEvent::KEYCODE_QUESTION = 2834;
380 const int32_t KeyEvent::KEYCODE_CONNECT = 2836;
381 const int32_t KeyEvent::KEYCODE_SPORT = 2837;
382 const int32_t KeyEvent::KEYCODE_SHOP = 2838;
383 const int32_t KeyEvent::KEYCODE_ALTERASE = 2839;
384 const int32_t KeyEvent::KEYCODE_SWITCHVIDEOMODE = 2841;
385 const int32_t KeyEvent::KEYCODE_BATTERY = 2842;
386 const int32_t KeyEvent::KEYCODE_BLUETOOTH = 2843;
387 const int32_t KeyEvent::KEYCODE_WLAN = 2844;
388 const int32_t KeyEvent::KEYCODE_UWB = 2845;
389 const int32_t KeyEvent::KEYCODE_WWAN_WIMAX = 2846;
390 const int32_t KeyEvent::KEYCODE_RFKILL = 2847;
391 const int32_t KeyEvent::KEYCODE_CHANNEL = 3001;
392 const int32_t KeyEvent::KEYCODE_BTN_0 = 3100;
393 const int32_t KeyEvent::KEYCODE_BTN_1 = 3101;
394 const int32_t KeyEvent::KEYCODE_BTN_2 = 3102;
395 const int32_t KeyEvent::KEYCODE_BTN_3 = 3103;
396 const int32_t KeyEvent::KEYCODE_BTN_4 = 3104;
397 const int32_t KeyEvent::KEYCODE_BTN_5 = 3105;
398 const int32_t KeyEvent::KEYCODE_BTN_6 = 3106;
399 const int32_t KeyEvent::KEYCODE_BTN_7 = 3107;
400 const int32_t KeyEvent::KEYCODE_BTN_8 = 3108;
401 const int32_t KeyEvent::KEYCODE_BTN_9 = 3109;
402 const int32_t KeyEvent::KEYCODE_BRL_DOT1 = 3201;
403 const int32_t KeyEvent::KEYCODE_BRL_DOT2 = 3202;
404 const int32_t KeyEvent::KEYCODE_BRL_DOT3 = 3203;
405 const int32_t KeyEvent::KEYCODE_BRL_DOT4 = 3204;
406 const int32_t KeyEvent::KEYCODE_BRL_DOT5 = 3205;
407 const int32_t KeyEvent::KEYCODE_BRL_DOT6 = 3206;
408 const int32_t KeyEvent::KEYCODE_BRL_DOT7 = 3207;
409 const int32_t KeyEvent::KEYCODE_BRL_DOT8 = 3208;
410 const int32_t KeyEvent::KEYCODE_BRL_DOT9 = 3209;
411 const int32_t KeyEvent::KEYCODE_BRL_DOT10 = 3210;
412 const int32_t KeyEvent::KEYCODE_LEFT_KNOB_ROLL_UP = 10001;
413 const int32_t KeyEvent::KEYCODE_LEFT_KNOB_ROLL_DOWN = 10002;
414 const int32_t KeyEvent::KEYCODE_LEFT_KNOB = 10003;
415 const int32_t KeyEvent::KEYCODE_RIGHT_KNOB_ROLL_UP = 10004;
416 const int32_t KeyEvent::KEYCODE_RIGHT_KNOB_ROLL_DOWN = 10005;
417 const int32_t KeyEvent::KEYCODE_RIGHT_KNOB = 10006;
418 const int32_t KeyEvent::KEYCODE_VOICE_SOURCE_SWITCH = 10007;
419 const int32_t KeyEvent::KEYCODE_LAUNCHER_MENU = 10008;
420 
421 const int32_t KeyEvent::KEY_ACTION_UNKNOWN = 0X00000000;
422 const int32_t KeyEvent::KEY_ACTION_CANCEL = 0X00000001;
423 
424 const int32_t KeyEvent::KEY_ACTION_DOWN = 0x00000002;
425 const int32_t KeyEvent::KEY_ACTION_UP = 0X00000003;
426 
KeyItem()427 KeyEvent::KeyItem::KeyItem() {}
428 
~KeyItem()429 KeyEvent::KeyItem::~KeyItem() {}
430 
GetKeyCode() const431 int32_t KeyEvent::KeyItem::GetKeyCode() const
432 {
433     return keyCode_;
434 }
435 
SetKeyCode(int32_t keyCode)436 void KeyEvent::KeyItem::SetKeyCode(int32_t keyCode)
437 {
438     keyCode_ = keyCode;
439 }
440 
GetDownTime() const441 int64_t KeyEvent::KeyItem::GetDownTime() const
442 {
443     return downTime_;
444 }
445 
SetDownTime(int64_t downTime)446 void KeyEvent::KeyItem::SetDownTime(int64_t downTime)
447 {
448     downTime_ = downTime;
449 }
450 
GetDeviceId() const451 int32_t KeyEvent::KeyItem::GetDeviceId() const
452 {
453     return deviceId_;
454 }
455 
SetDeviceId(int32_t deviceId)456 void KeyEvent::KeyItem::SetDeviceId(int32_t deviceId)
457 {
458     deviceId_ = deviceId;
459 }
460 
IsPressed() const461 bool KeyEvent::KeyItem::IsPressed() const
462 {
463     return pressed_;
464 }
465 
SetPressed(bool pressed)466 void KeyEvent::KeyItem::SetPressed(bool pressed)
467 {
468     pressed_ = pressed;
469 }
470 
SetUnicode(uint32_t unicode)471 void KeyEvent::KeyItem::SetUnicode(uint32_t unicode)
472 {
473     unicode_ = unicode;
474 }
475 
GetUnicode() const476 uint32_t KeyEvent::KeyItem::GetUnicode() const
477 {
478     return unicode_;
479 }
480 
WriteToParcel(Parcel & out) const481 bool KeyEvent::KeyItem::WriteToParcel(Parcel &out) const
482 {
483     WRITEBOOL(out, pressed_);
484     WRITEINT64(out, downTime_);
485     WRITEINT32(out, deviceId_);
486     WRITEINT32(out, keyCode_);
487 
488     return true;
489 }
490 
ReadFromParcel(Parcel & in)491 bool KeyEvent::KeyItem::ReadFromParcel(Parcel &in)
492 {
493     READBOOL(in, pressed_);
494     READINT64(in, downTime_);
495     READINT32(in, deviceId_);
496     READINT32(in, keyCode_);
497 
498     return true;
499 }
500 
from(std::shared_ptr<InputEvent> inputEvent)501 std::shared_ptr<KeyEvent> KeyEvent::from(std::shared_ptr<InputEvent> inputEvent)
502 {
503     return nullptr;
504 }
505 
KeyEvent(int32_t eventType)506 KeyEvent::KeyEvent(int32_t eventType) : InputEvent(eventType) {}
507 
KeyEvent(const KeyEvent & other)508 KeyEvent::KeyEvent(const KeyEvent& other)
509     : InputEvent(other),
510       keyCode_(other.keyCode_),
511       keys_(other.keys_),
512       keyAction_(other.keyAction_) {}
513 
~KeyEvent()514 KeyEvent::~KeyEvent() {}
515 
Create()516 std::shared_ptr<KeyEvent> KeyEvent::Create()
517 {
518     auto event = std::shared_ptr<KeyEvent>(new (std::nothrow) KeyEvent(InputEvent::EVENT_TYPE_KEY));
519     CHKPP(event);
520     return event;
521 }
522 
GetKeyCode() const523 int32_t KeyEvent::GetKeyCode() const
524 {
525     return keyCode_;
526 }
527 
SetKeyCode(int32_t keyCode)528 void KeyEvent::SetKeyCode(int32_t keyCode)
529 {
530     keyCode_ = keyCode;
531 }
532 
GetKeyAction() const533 int32_t KeyEvent::GetKeyAction() const
534 {
535     return keyAction_;
536 }
537 
SetKeyAction(int32_t keyAction)538 void KeyEvent::SetKeyAction(int32_t keyAction)
539 {
540     keyAction_ = keyAction;
541 }
542 
AddKeyItem(const KeyItem & keyItem)543 void KeyEvent::AddKeyItem(const KeyItem& keyItem)
544 {
545     keys_.push_back(keyItem);
546 }
547 
GetKeyItems() const548 std::vector<KeyEvent::KeyItem> KeyEvent::GetKeyItems() const
549 {
550     return keys_;
551 }
552 
GetPressedKeys() const553 std::vector<int32_t> KeyEvent::GetPressedKeys() const
554 {
555     std::vector<int32_t> result;
556     for (const auto &item : keys_) {
557         if (item.IsPressed()) {
558             result.push_back(item.GetKeyCode());
559         }
560     }
561     return result;
562 }
563 
AddPressedKeyItems(const KeyItem & keyItem)564 void KeyEvent::AddPressedKeyItems(const KeyItem& keyItem)
565 {
566     std::vector<int32_t> pressedkeys = GetPressedKeys();
567     std::vector<int32_t>::iterator result = std::find(pressedkeys.begin(),
568         pressedkeys.end(), keyItem.GetKeyCode());
569     if (result == pressedkeys.end()) {
570         keys_.push_back(keyItem);
571     }
572 }
573 
RemoveReleasedKeyItems(const KeyItem & keyItem)574 void KeyEvent::RemoveReleasedKeyItems(const KeyItem& keyItem)
575 {
576     int32_t keyCode = keyItem.GetKeyCode();
577     std::vector<KeyItem> tempKeyItems = keys_;
578     keys_.clear();
579     for (const auto &item : tempKeyItems) {
580         if (item.GetKeyCode() != keyCode) {
581             keys_.push_back(item);
582         }
583     }
584 }
585 
GetKeyItem() const586 const KeyEvent::KeyItem* KeyEvent::GetKeyItem() const
587 {
588     return GetKeyItem(keyCode_);
589 }
590 
GetKeyItem(int32_t keyCode) const591 const KeyEvent::KeyItem* KeyEvent::GetKeyItem(int32_t keyCode) const
592 {
593     for (const auto &item : keys_) {
594         if (item.GetKeyCode() == keyCode) {
595             return &item;
596         }
597     }
598     return nullptr;
599 }
600 
ActionToString(int32_t action)601 const char* KeyEvent::ActionToString(int32_t action)
602 {
603     switch (action) {
604         case KEY_ACTION_UNKNOWN: {
605             return "KEY_ACTION_UNKNOWN";
606         }
607         case KEY_ACTION_CANCEL: {
608             return "KEY_ACTION_CANCEL";
609         }
610         case KEY_ACTION_DOWN: {
611             return "KEY_ACTION_DOWN";
612         }
613         case KEY_ACTION_UP: {
614             return "KEY_ACTION_UP";
615         }
616         default: {
617             return "KEY_ACTION_INVALID";
618         }
619     }
620 }
621 
KeyCodeToString(int32_t keyCode)622 const char* KeyEvent::KeyCodeToString(int32_t keyCode)
623 {
624     CALL_DEBUG_ENTER;
625     static const std::map <int32_t, std::string> keyCodeToString = {
626         {KEYCODE_FN, "KEYCODE_FN"},
627         {KEYCODE_UNKNOWN, "KEYCODE_UNKNOWN"},
628         {KEYCODE_HOME, "KEYCODE_HOME"},
629         {KEYCODE_BACK, "KEYCODE_BACK"},
630         {KEYCODE_CALL, "KEYCODE_CALL"},
631         {KEYCODE_ENDCALL, "KEYCODE_ENDCALL"},
632         {KEYCODE_CLEAR, "KEYCODE_CLEAR"},
633         {KEYCODE_HEADSETHOOK, "KEYCODE_HEADSETHOOK"},
634         {KEYCODE_FOCUS, "KEYCODE_FOCUS"},
635         {KEYCODE_NOTIFICATION, "KEYCODE_NOTIFICATION"},
636         {KEYCODE_SEARCH, "KEYCODE_SEARCH"},
637         {KEYCODE_MEDIA_PLAY_PAUSE, "KEYCODE_MEDIA_PLAY_PAUSE"},
638         {KEYCODE_MEDIA_STOP, "KEYCODE_MEDIA_STOP"},
639         {KEYCODE_MEDIA_NEXT, "KEYCODE_MEDIA_NEXT"},
640         {KEYCODE_MEDIA_PREVIOUS, "KEYCODE_MEDIA_PREVIOUS"},
641         {KEYCODE_MEDIA_REWIND, "KEYCODE_MEDIA_REWIND"},
642         {KEYCODE_MEDIA_FAST_FORWARD, "KEYCODE_MEDIA_FAST_FORWARD"},
643         {KEYCODE_VOLUME_UP, "KEYCODE_VOLUME_UP"},
644         {KEYCODE_VOLUME_DOWN, "KEYCODE_VOLUME_DOWN"},
645         {KEYCODE_POWER, "KEYCODE_POWER"},
646         {KEYCODE_CAMERA, "KEYCODE_CAMERA"},
647         {KEYCODE_VOICE_ASSISTANT, "KEYCODE_VOICE_ASSISTANT"},
648         {KEYCODE_CUSTOM1, "KEYCODE_CUSTOM1"},
649         {KEYCODE_VOLUME_MUTE, "KEYCODE_VOLUME_MUTE"},
650         {KEYCODE_MUTE, "KEYCODE_MUTE"},
651         {KEYCODE_BRIGHTNESS_UP, "KEYCODE_BRIGHTNESS_UP"},
652         {KEYCODE_BRIGHTNESS_DOWN, "KEYCODE_BRIGHTNESS_DOWN"},
653         {KEYCODE_WEAR_1, "KEYCODE_WEAR_1"},
654         {KEYCODE_0, "KEYCODE_0"},
655         {KEYCODE_1, "KEYCODE_1"},
656         {KEYCODE_2, "KEYCODE_2"},
657         {KEYCODE_3, "KEYCODE_3"},
658         {KEYCODE_4, "KEYCODE_4"},
659         {KEYCODE_5, "KEYCODE_5"},
660         {KEYCODE_6, "KEYCODE_6"},
661         {KEYCODE_7, "KEYCODE_7"},
662         {KEYCODE_8, "KEYCODE_8"},
663         {KEYCODE_9, "KEYCODE_9"},
664         {KEYCODE_STAR, "KEYCODE_STAR"},
665         {KEYCODE_POUND, "KEYCODE_POUND"},
666         {KEYCODE_DPAD_UP, "KEYCODE_DPAD_UP"},
667         {KEYCODE_DPAD_DOWN, "KEYCODE_DPAD_DOWN"},
668         {KEYCODE_DPAD_LEFT, "KEYCODE_DPAD_LEFT"},
669         {KEYCODE_DPAD_RIGHT, "KEYCODE_DPAD_RIGHT"},
670         {KEYCODE_DPAD_CENTER, "KEYCODE_DPAD_CENTER"},
671         {KEYCODE_A, "KEYCODE_A"},
672         {KEYCODE_B, "KEYCODE_B"},
673         {KEYCODE_C, "KEYCODE_C"},
674         {KEYCODE_D, "KEYCODE_D"},
675         {KEYCODE_E, "KEYCODE_E"},
676         {KEYCODE_F, "KEYCODE_F"},
677         {KEYCODE_G, "KEYCODE_G"},
678         {KEYCODE_H, "KEYCODE_H"},
679         {KEYCODE_I, "KEYCODE_I"},
680         {KEYCODE_J, "KEYCODE_J"},
681         {KEYCODE_K, "KEYCODE_K"},
682         {KEYCODE_L, "KEYCODE_L"},
683         {KEYCODE_M, "KEYCODE_M"},
684         {KEYCODE_N, "KEYCODE_N"},
685         {KEYCODE_O, "KEYCODE_O"},
686         {KEYCODE_P, "KEYCODE_P"},
687         {KEYCODE_Q, "KEYCODE_Q"},
688         {KEYCODE_R, "KEYCODE_R"},
689         {KEYCODE_S, "KEYCODE_S"},
690         {KEYCODE_T, "KEYCODE_T"},
691         {KEYCODE_U, "KEYCODE_U"},
692         {KEYCODE_V, "KEYCODE_V"},
693         {KEYCODE_W, "KEYCODE_W"},
694         {KEYCODE_X, "KEYCODE_X"},
695         {KEYCODE_Y, "KEYCODE_Y"},
696         {KEYCODE_Z, "KEYCODE_Z"},
697         {KEYCODE_COMMA, "KEYCODE_COMMA"},
698         {KEYCODE_PERIOD, "KEYCODE_PERIOD"},
699         {KEYCODE_ALT_LEFT, "KEYCODE_ALT_LEFT"},
700         {KEYCODE_ALT_RIGHT, "KEYCODE_ALT_RIGHT"},
701         {KEYCODE_SHIFT_LEFT, "KEYCODE_SHIFT_LEFT"},
702         {KEYCODE_SHIFT_RIGHT, "KEYCODE_SHIFT_RIGHT"},
703         {KEYCODE_TAB, "KEYCODE_TAB"},
704         {KEYCODE_SPACE, "KEYCODE_SPACE"},
705         {KEYCODE_SYM, "KEYCODE_SYM"},
706         {KEYCODE_EXPLORER, "KEYCODE_EXPLORER"},
707         {KEYCODE_ENVELOPE, "KEYCODE_ENVELOPE"},
708         {KEYCODE_ENTER, "KEYCODE_ENTER"},
709         {KEYCODE_DEL, "KEYCODE_DEL"},
710         {KEYCODE_GRAVE, "KEYCODE_GRAVE"},
711         {KEYCODE_MINUS, "KEYCODE_MINUS"},
712         {KEYCODE_EQUALS, "KEYCODE_EQUALS"},
713         {KEYCODE_LEFT_BRACKET, "KEYCODE_LEFT_BRACKET"},
714         {KEYCODE_RIGHT_BRACKET, "KEYCODE_RIGHT_BRACKET"},
715         {KEYCODE_BACKSLASH, "KEYCODE_BACKSLASH"},
716         {KEYCODE_SEMICOLON, "KEYCODE_SEMICOLON"},
717         {KEYCODE_APOSTROPHE, "KEYCODE_APOSTROPHE"},
718         {KEYCODE_SLASH, "KEYCODE_SLASH"},
719         {KEYCODE_AT, "KEYCODE_AT"},
720         {KEYCODE_PLUS, "KEYCODE_PLUS"},
721         {KEYCODE_MENU, "KEYCODE_MENU"},
722         {KEYCODE_PAGE_UP, "KEYCODE_PAGE_UP"},
723         {KEYCODE_PAGE_DOWN, "KEYCODE_PAGE_DOWN"},
724         {KEYCODE_ESCAPE, "KEYCODE_ESCAPE"},
725         {KEYCODE_FORWARD_DEL, "KEYCODE_FORWARD_DEL"},
726         {KEYCODE_CTRL_LEFT, "KEYCODE_CTRL_LEFT"},
727         {KEYCODE_CTRL_RIGHT, "KEYCODE_CTRL_RIGHT"},
728         {KEYCODE_CAPS_LOCK, "KEYCODE_CAPS_LOCK"},
729         {KEYCODE_SCROLL_LOCK, "KEYCODE_SCROLL_LOCK"},
730         {KEYCODE_META_LEFT, "KEYCODE_META_LEFT"},
731         {KEYCODE_META_RIGHT, "KEYCODE_META_RIGHT"},
732         {KEYCODE_FUNCTION, "KEYCODE_FUNCTION"},
733         {KEYCODE_SYSRQ, "KEYCODE_SYSRQ"},
734         {KEYCODE_BREAK, "KEYCODE_BREAK"},
735         {KEYCODE_MOVE_HOME, "KEYCODE_MOVE_HOME"},
736         {KEYCODE_MOVE_END, "KEYCODE_MOVE_END"},
737         {KEYCODE_INSERT, "KEYCODE_INSERT"},
738         {KEYCODE_FORWARD, "KEYCODE_FORWARD"},
739         {KEYCODE_MEDIA_PLAY, "KEYCODE_MEDIA_PLAY"},
740         {KEYCODE_MEDIA_PAUSE, "KEYCODE_MEDIA_PAUSE"},
741         {KEYCODE_MEDIA_CLOSE, "KEYCODE_MEDIA_CLOSE"},
742         {KEYCODE_MEDIA_EJECT, "KEYCODE_MEDIA_EJECT"},
743         {KEYCODE_MEDIA_RECORD, "KEYCODE_MEDIA_RECORD"},
744         {KEYCODE_F1, "KEYCODE_F1"},
745         {KEYCODE_F2, "KEYCODE_F2"},
746         {KEYCODE_F3, "KEYCODE_F3"},
747         {KEYCODE_F4, "KEYCODE_F4"},
748         {KEYCODE_F5, "KEYCODE_F5"},
749         {KEYCODE_F6, "KEYCODE_F6"},
750         {KEYCODE_F7, "KEYCODE_F7"},
751         {KEYCODE_F8, "KEYCODE_F8"},
752         {KEYCODE_F9, "KEYCODE_F9"},
753         {KEYCODE_F10, "KEYCODE_F10"},
754         {KEYCODE_F11, "KEYCODE_F11"},
755         {KEYCODE_F12, "KEYCODE_F12"},
756         {KEYCODE_NUM_LOCK, "KEYCODE_NUM_LOCK"},
757         {KEYCODE_NUMPAD_0, "KEYCODE_NUMPAD_0"},
758         {KEYCODE_NUMPAD_1, "KEYCODE_NUMPAD_1"},
759         {KEYCODE_NUMPAD_2, "KEYCODE_NUMPAD_2"},
760         {KEYCODE_NUMPAD_3, "KEYCODE_NUMPAD_3"},
761         {KEYCODE_NUMPAD_4, "KEYCODE_NUMPAD_4"},
762         {KEYCODE_NUMPAD_5, "KEYCODE_NUMPAD_5"},
763         {KEYCODE_NUMPAD_6, "KEYCODE_NUMPAD_6"},
764         {KEYCODE_NUMPAD_7, "KEYCODE_NUMPAD_7"},
765         {KEYCODE_NUMPAD_8, "KEYCODE_NUMPAD_8"},
766         {KEYCODE_NUMPAD_9, "KEYCODE_NUMPAD_9"},
767         {KEYCODE_NUMPAD_DIVIDE, "KEYCODE_NUMPAD_DIVIDE"},
768         {KEYCODE_NUMPAD_MULTIPLY, "KEYCODE_NUMPAD_MULTIPLY"},
769         {KEYCODE_NUMPAD_SUBTRACT, "KEYCODE_NUMPAD_SUBTRACT"},
770         {KEYCODE_NUMPAD_ADD, "KEYCODE_NUMPAD_ADD"},
771         {KEYCODE_NUMPAD_DOT, "KEYCODE_NUMPAD_DOT"},
772         {KEYCODE_NUMPAD_COMMA, "KEYCODE_NUMPAD_COMMA"},
773         {KEYCODE_NUMPAD_ENTER, "KEYCODE_NUMPAD_ENTER"},
774         {KEYCODE_NUMPAD_EQUALS, "KEYCODE_NUMPAD_EQUALS"},
775         {KEYCODE_NUMPAD_LEFT_PAREN, "KEYCODE_NUMPAD_LEFT_PAREN"},
776         {KEYCODE_NUMPAD_RIGHT_PAREN, "KEYCODE_NUMPAD_RIGHT_PAREN"},
777         {KEYCODE_VIRTUAL_MULTITASK, "KEYCODE_VIRTUAL_MULTITASK"},
778         {KEYCODE_BUTTON_A, "KEYCODE_BUTTON_A"},
779         {KEYCODE_BUTTON_B, "KEYCODE_BUTTON_B"},
780         {KEYCODE_BUTTON_C, "KEYCODE_BUTTON_C"},
781         {KEYCODE_BUTTON_X, "KEYCODE_BUTTON_X"},
782         {KEYCODE_BUTTON_Y, "KEYCODE_BUTTON_Y"},
783         {KEYCODE_BUTTON_Z, "KEYCODE_BUTTON_Z"},
784         {KEYCODE_BUTTON_L1, "KEYCODE_BUTTON_L1"},
785         {KEYCODE_BUTTON_R1, "KEYCODE_BUTTON_R1"},
786         {KEYCODE_BUTTON_L2, "KEYCODE_BUTTON_L2"},
787         {KEYCODE_BUTTON_R2, "KEYCODE_BUTTON_R2"},
788         {KEYCODE_BUTTON_SELECT, "KEYCODE_BUTTON_SELECT"},
789         {KEYCODE_BUTTON_START, "KEYCODE_BUTTON_START"},
790         {KEYCODE_BUTTON_MODE, "KEYCODE_BUTTON_MODE"},
791         {KEYCODE_BUTTON_THUMBL, "KEYCODE_BUTTON_THUMBL"},
792         {KEYCODE_BUTTON_THUMBR, "KEYCODE_BUTTON_THUMBR"},
793         {KEYCODE_BUTTON_TRIGGER, "KEYCODE_BUTTON_TRIGGER"},
794         {KEYCODE_BUTTON_THUMB, "KEYCODE_BUTTON_THUMB"},
795         {KEYCODE_BUTTON_THUMB2, "KEYCODE_BUTTON_THUMB2"},
796         {KEYCODE_BUTTON_TOP, "KEYCODE_BUTTON_TOP"},
797         {KEYCODE_BUTTON_TOP2, "KEYCODE_BUTTON_TOP2"},
798         {KEYCODE_BUTTON_PINKIE, "KEYCODE_BUTTON_PINKIE"},
799         {KEYCODE_BUTTON_BASE1, "KEYCODE_BUTTON_BASE1"},
800         {KEYCODE_BUTTON_BASE2, "KEYCODE_BUTTON_BASE2"},
801         {KEYCODE_BUTTON_BASE3, "KEYCODE_BUTTON_BASE3"},
802         {KEYCODE_BUTTON_BASE4, "KEYCODE_BUTTON_BASE4"},
803         {KEYCODE_BUTTON_BASE5, "KEYCODE_BUTTON_BASE5"},
804         {KEYCODE_BUTTON_BASE6, "KEYCODE_BUTTON_BASE6"},
805         {KEYCODE_BUTTON_BASE7, "KEYCODE_BUTTON_BASE7"},
806         {KEYCODE_BUTTON_BASE8, "KEYCODE_BUTTON_BASE8"},
807         {KEYCODE_BUTTON_BASE9, "KEYCODE_BUTTON_BASE9"},
808         {KEYCODE_BUTTON_DEAD, "KEYCODE_BUTTON_DEAD"},
809         {KEYCODE_SLEEP, "KEYCODE_SLEEP"},
810         {KEYCODE_ZENKAKU_HANKAKU, "KEYCODE_ZENKAKU_HANKAKU"},
811         {KEYCODE_102ND, "KEYCODE_102ND"},
812         {KEYCODE_RO, "KEYCODE_RO"},
813         {KEYCODE_KATAKANA, "KEYCODE_KATAKANA"},
814         {KEYCODE_HIRAGANA, "KEYCODE_HIRAGANA"},
815         {KEYCODE_HENKAN, "KEYCODE_HENKAN"},
816         {KEYCODE_KATAKANA_HIRAGANA, "KEYCODE_KATAKANA_HIRAGANA"},
817         {KEYCODE_MUHENKAN, "KEYCODE_MUHENKAN"},
818         {KEYCODE_LINEFEED, "KEYCODE_LINEFEED"},
819         {KEYCODE_MACRO, "KEYCODE_MACRO"},
820         {KEYCODE_NUMPAD_PLUSMINUS, "KEYCODE_NUMPAD_PLUSMINUS"},
821         {KEYCODE_SCALE, "KEYCODE_SCALE"},
822         {KEYCODE_HANGUEL, "KEYCODE_HANGUEL"},
823         {KEYCODE_HANJA, "KEYCODE_HANJA"},
824         {KEYCODE_YEN, "KEYCODE_YEN"},
825         {KEYCODE_STOP, "KEYCODE_STOP"},
826         {KEYCODE_AGAIN, "KEYCODE_AGAIN"},
827         {KEYCODE_PROPS, "KEYCODE_PROPS"},
828         {KEYCODE_UNDO, "KEYCODE_UNDO"},
829         {KEYCODE_COPY, "KEYCODE_COPY"},
830         {KEYCODE_OPEN, "KEYCODE_OPEN"},
831         {KEYCODE_PASTE, "KEYCODE_PASTE"},
832         {KEYCODE_FIND, "KEYCODE_FIND"},
833         {KEYCODE_CUT, "KEYCODE_CUT"},
834         {KEYCODE_HELP, "KEYCODE_HELP"},
835         {KEYCODE_CALC, "KEYCODE_CALC"},
836         {KEYCODE_FILE, "KEYCODE_FILE"},
837         {KEYCODE_BOOKMARKS, "KEYCODE_BOOKMARKS"},
838         {KEYCODE_NEXT, "KEYCODE_NEXT"},
839         {KEYCODE_PLAYPAUSE, "KEYCODE_PLAYPAUSE"},
840         {KEYCODE_PREVIOUS, "KEYCODE_PREVIOUS"},
841         {KEYCODE_STOPCD, "KEYCODE_STOPCD"},
842         {KEYCODE_CONFIG, "KEYCODE_CONFIG"},
843         {KEYCODE_REFRESH, "KEYCODE_REFRESH"},
844         {KEYCODE_EXIT, "KEYCODE_EXIT"},
845         {KEYCODE_EDIT, "KEYCODE_EDIT"},
846         {KEYCODE_SCROLLUP, "KEYCODE_SCROLLUP"},
847         {KEYCODE_SCROLLDOWN, "KEYCODE_SCROLLDOWN"},
848         {KEYCODE_NEW, "KEYCODE_NEW"},
849         {KEYCODE_REDO, "KEYCODE_REDO"},
850         {KEYCODE_CLOSE, "KEYCODE_CLOSE"},
851         {KEYCODE_PLAY, "KEYCODE_PLAY"},
852         {KEYCODE_BASSBOOST, "KEYCODE_BASSBOOST"},
853         {KEYCODE_PRINT, "KEYCODE_PRINT"},
854         {KEYCODE_CHAT, "KEYCODE_CHAT"},
855         {KEYCODE_FINANCE, "KEYCODE_FINANCE"},
856         {KEYCODE_CANCEL, "KEYCODE_CANCEL"},
857         {KEYCODE_KBDILLUM_TOGGLE, "KEYCODE_KBDILLUM_TOGGLE"},
858         {KEYCODE_KBDILLUM_DOWN, "KEYCODE_KBDILLUM_DOWN"},
859         {KEYCODE_KBDILLUM_UP, "KEYCODE_KBDILLUM_UP"},
860         {KEYCODE_SEND, "KEYCODE_SEND"},
861         {KEYCODE_REPLY, "KEYCODE_REPLY"},
862         {KEYCODE_FORWARDMAIL, "KEYCODE_FORWARDMAIL"},
863         {KEYCODE_SAVE, "KEYCODE_SAVE"},
864         {KEYCODE_DOCUMENTS, "KEYCODE_DOCUMENTS"},
865         {KEYCODE_VIDEO_NEXT, "KEYCODE_VIDEO_NEXT"},
866         {KEYCODE_VIDEO_PREV, "KEYCODE_VIDEO_PREV"},
867         {KEYCODE_BRIGHTNESS_CYCLE, "KEYCODE_BRIGHTNESS_CYCLE"},
868         {KEYCODE_BRIGHTNESS_ZERO, "KEYCODE_BRIGHTNESS_ZERO"},
869         {KEYCODE_DISPLAY_OFF, "KEYCODE_DISPLAY_OFF"},
870         {KEYCODE_BTN_MISC, "KEYCODE_BTN_MISC"},
871         {KEYCODE_GOTO, "KEYCODE_GOTO"},
872         {KEYCODE_INFO, "KEYCODE_INFO"},
873         {KEYCODE_PROGRAM, "KEYCODE_PROGRAM"},
874         {KEYCODE_PVR, "KEYCODE_PVR"},
875         {KEYCODE_SUBTITLE, "KEYCODE_SUBTITLE"},
876         {KEYCODE_FULL_SCREEN, "KEYCODE_FULL_SCREEN"},
877         {KEYCODE_KEYBOARD, "KEYCODE_KEYBOARD"},
878         {KEYCODE_ASPECT_RATIO, "KEYCODE_ASPECT_RATIO"},
879         {KEYCODE_PC, "KEYCODE_PC"},
880         {KEYCODE_TV, "KEYCODE_TV"},
881         {KEYCODE_TV2, "KEYCODE_TV2"},
882         {KEYCODE_VCR, "KEYCODE_VCR"},
883         {KEYCODE_VCR2, "KEYCODE_VCR2"},
884         {KEYCODE_SAT, "KEYCODE_SAT"},
885         {KEYCODE_CD, "KEYCODE_CD"},
886         {KEYCODE_TAPE, "KEYCODE_TAPE"},
887         {KEYCODE_TUNER, "KEYCODE_TUNER"},
888         {KEYCODE_PLAYER, "KEYCODE_PLAYER"},
889         {KEYCODE_DVD, "KEYCODE_DVD"},
890         {KEYCODE_AUDIO, "KEYCODE_AUDIO"},
891         {KEYCODE_VIDEO, "KEYCODE_VIDEO"},
892         {KEYCODE_MEMO, "KEYCODE_MEMO"},
893         {KEYCODE_CALENDAR, "KEYCODE_CALENDAR"},
894         {KEYCODE_RED, "KEYCODE_RED"},
895         {KEYCODE_GREEN, "KEYCODE_GREEN"},
896         {KEYCODE_YELLOW, "KEYCODE_YELLOW"},
897         {KEYCODE_BLUE, "KEYCODE_BLUE"},
898         {KEYCODE_CHANNELUP, "KEYCODE_CHANNELUP"},
899         {KEYCODE_CHANNELDOWN, "KEYCODE_CHANNELDOWN"},
900         {KEYCODE_LAST, "KEYCODE_LAST"},
901         {KEYCODE_RESTART, "KEYCODE_RESTART"},
902         {KEYCODE_SLOW, "KEYCODE_SLOW"},
903         {KEYCODE_SHUFFLE, "KEYCODE_SHUFFLE"},
904         {KEYCODE_VIDEOPHONE, "KEYCODE_VIDEOPHONE"},
905         {KEYCODE_GAMES, "KEYCODE_GAMES"},
906         {KEYCODE_ZOOMIN, "KEYCODE_ZOOMIN"},
907         {KEYCODE_ZOOMOUT, "KEYCODE_ZOOMOUT"},
908         {KEYCODE_ZOOMRESET, "KEYCODE_ZOOMRESET"},
909         {KEYCODE_WORDPROCESSOR, "KEYCODE_WORDPROCESSOR"},
910         {KEYCODE_EDITOR, "KEYCODE_EDITOR"},
911         {KEYCODE_SPREADSHEET, "KEYCODE_SPREADSHEET"},
912         {KEYCODE_GRAPHICSEDITOR, "KEYCODE_GRAPHICSEDITOR"},
913         {KEYCODE_PRESENTATION, "KEYCODE_PRESENTATION"},
914         {KEYCODE_DATABASE, "KEYCODE_DATABASE"},
915         {KEYCODE_NEWS, "KEYCODE_NEWS"},
916         {KEYCODE_VOICEMAIL, "KEYCODE_VOICEMAIL"},
917         {KEYCODE_ADDRESSBOOK, "KEYCODE_ADDRESSBOOK"},
918         {KEYCODE_MESSENGER, "KEYCODE_MESSENGER"},
919         {KEYCODE_BRIGHTNESS_TOGGLE, "KEYCODE_BRIGHTNESS_TOGGLE"},
920         {KEYCODE_SPELLCHECK, "KEYCODE_SPELLCHECK"},
921         {KEYCODE_COFFEE, "KEYCODE_COFFEE"},
922         {KEYCODE_MEDIA_REPEAT, "KEYCODE_MEDIA_REPEAT"},
923         {KEYCODE_IMAGES, "KEYCODE_IMAGES"},
924         {KEYCODE_BUTTONCONFIG, "KEYCODE_BUTTONCONFIG"},
925         {KEYCODE_TASKMANAGER, "KEYCODE_TASKMANAGER"},
926         {KEYCODE_JOURNAL, "KEYCODE_JOURNAL"},
927         {KEYCODE_CONTROLPANEL, "KEYCODE_CONTROLPANEL"},
928         {KEYCODE_APPSELECT, "KEYCODE_APPSELECT"},
929         {KEYCODE_SCREENSAVER, "KEYCODE_SCREENSAVER"},
930         {KEYCODE_ASSISTANT, "KEYCODE_ASSISTANT"},
931         {KEYCODE_KBD_LAYOUT_NEXT, "KEYCODE_KBD_LAYOUT_NEXT"},
932         {KEYCODE_BRIGHTNESS_MIN, "KEYCODE_BRIGHTNESS_MIN"},
933         {KEYCODE_BRIGHTNESS_MAX, "KEYCODE_BRIGHTNESS_MAX"},
934         {KEYCODE_KBDINPUTASSIST_PREV, "KEYCODE_KBDINPUTASSIST_PREV"},
935         {KEYCODE_KBDINPUTASSIST_NEXT, "KEYCODE_KBDINPUTASSIST_NEXT"},
936         {KEYCODE_KBDINPUTASSIST_PREVGROUP, "KEYCODE_KBDINPUTASSIST_PREVGROUP"},
937         {KEYCODE_KBDINPUTASSIST_NEXTGROUP, "KEYCODE_KBDINPUTASSIST_NEXTGROUP"},
938         {KEYCODE_KBDINPUTASSIST_ACCEPT, "KEYCODE_KBDINPUTASSIST_ACCEPT"},
939         {KEYCODE_KBDINPUTASSIST_CANCEL, "KEYCODE_KBDINPUTASSIST_CANCEL"},
940         {KEYCODE_FRONT, "KEYCODE_FRONT"},
941         {KEYCODE_SETUP, "KEYCODE_SETUP"},
942         {KEYCODE_WAKEUP, "KEYCODE_WAKEUP"},
943         {KEYCODE_SENDFILE, "KEYCODE_SENDFILE"},
944         {KEYCODE_DELETEFILE, "KEYCODE_DELETEFILE"},
945         {KEYCODE_XFER, "KEYCODE_XFER"},
946         {KEYCODE_PROG1, "KEYCODE_PROG1"},
947         {KEYCODE_PROG2, "KEYCODE_PROG2"},
948         {KEYCODE_MSDOS, "KEYCODE_MSDOS"},
949         {KEYCODE_SCREENLOCK, "KEYCODE_SCREENLOCK"},
950         {KEYCODE_DIRECTION_ROTATE_DISPLAY, "KEYCODE_DIRECTION_ROTATE_DISPLAY"},
951         {KEYCODE_CYCLEWINDOWS, "KEYCODE_CYCLEWINDOWS"},
952         {KEYCODE_COMPUTER, "KEYCODE_COMPUTER"},
953         {KEYCODE_EJECTCLOSECD, "KEYCODE_EJECTCLOSECD"},
954         {KEYCODE_ISO, "KEYCODE_ISO"},
955         {KEYCODE_MOVE, "KEYCODE_MOVE"},
956         {KEYCODE_F13, "KEYCODE_F13"},
957         {KEYCODE_F14, "KEYCODE_F14"},
958         {KEYCODE_F15, "KEYCODE_F15"},
959         {KEYCODE_F16, "KEYCODE_F16"},
960         {KEYCODE_F17, "KEYCODE_F17"},
961         {KEYCODE_F18, "KEYCODE_F18"},
962         {KEYCODE_F19, "KEYCODE_F19"},
963         {KEYCODE_F20, "KEYCODE_F20"},
964         {KEYCODE_F21, "KEYCODE_F21"},
965         {KEYCODE_F22, "KEYCODE_F22"},
966         {KEYCODE_F23, "KEYCODE_F23"},
967         {KEYCODE_F24, "KEYCODE_F24"},
968         {KEYCODE_PROG3, "KEYCODE_PROG3"},
969         {KEYCODE_PROG4, "KEYCODE_PROG4"},
970         {KEYCODE_DASHBOARD, "KEYCODE_DASHBOARD"},
971         {KEYCODE_SUSPEND, "KEYCODE_SUSPEND"},
972         {KEYCODE_HP, "KEYCODE_HP"},
973         {KEYCODE_SOUND, "KEYCODE_SOUND"},
974         {KEYCODE_QUESTION, "KEYCODE_QUESTION"},
975         {KEYCODE_CONNECT, "KEYCODE_CONNECT"},
976         {KEYCODE_SPORT, "KEYCODE_SPORT"},
977         {KEYCODE_SHOP, "KEYCODE_SHOP"},
978         {KEYCODE_ALTERASE, "KEYCODE_ALTERASE"},
979         {KEYCODE_SWITCHVIDEOMODE, "KEYCODE_SWITCHVIDEOMODE"},
980         {KEYCODE_BATTERY, "KEYCODE_BATTERY"},
981         {KEYCODE_BLUETOOTH, "KEYCODE_BLUETOOTH"},
982         {KEYCODE_WLAN, "KEYCODE_WLAN"},
983         {KEYCODE_UWB, "KEYCODE_UWB"},
984         {KEYCODE_WWAN_WIMAX, "KEYCODE_WWAN_WIMAX"},
985         {KEYCODE_RFKILL, "KEYCODE_RFKILL"},
986         {KEYCODE_CHANNEL, "KEYCODE_CHANNEL"},
987         {KEYCODE_BTN_0, "KEYCODE_BTN_0"},
988         {KEYCODE_BTN_1, "KEYCODE_BTN_1"},
989         {KEYCODE_BTN_2, "KEYCODE_BTN_2"},
990         {KEYCODE_BTN_3, "KEYCODE_BTN_3"},
991         {KEYCODE_BTN_4, "KEYCODE_BTN_4"},
992         {KEYCODE_BTN_5, "KEYCODE_BTN_5"},
993         {KEYCODE_BTN_6, "KEYCODE_BTN_6"},
994         {KEYCODE_BTN_7, "KEYCODE_BTN_7"},
995         {KEYCODE_BTN_8, "KEYCODE_BTN_8"},
996         {KEYCODE_BTN_9, "KEYCODE_BTN_9"},
997         {KEYCODE_BRL_DOT1, "KEYCODE_BRL_DOT1"},
998         {KEYCODE_BRL_DOT2, "KEYCODE_BRL_DOT2"},
999         {KEYCODE_BRL_DOT3, "KEYCODE_BRL_DOT3"},
1000         {KEYCODE_BRL_DOT4, "KEYCODE_BRL_DOT4"},
1001         {KEYCODE_BRL_DOT5, "KEYCODE_BRL_DOT5"},
1002         {KEYCODE_BRL_DOT6, "KEYCODE_BRL_DOT6"},
1003         {KEYCODE_BRL_DOT7, "KEYCODE_BRL_DOT7"},
1004         {KEYCODE_BRL_DOT8, "KEYCODE_BRL_DOT8"},
1005         {KEYCODE_BRL_DOT9, "KEYCODE_BRL_DOT9"},
1006         {KEYCODE_BRL_DOT10, "KEYCODE_BRL_DOT10"},
1007         {KEYCODE_LEFT_KNOB_ROLL_UP, "KEYCODE_LEFT_KNOB_ROLL_UP"},
1008         {KEYCODE_LEFT_KNOB_ROLL_DOWN, "KEYCODE_LEFT_KNOB_ROLL_DOWN"},
1009         {KEYCODE_LEFT_KNOB, "KEYCODE_LEFT_KNOB"},
1010         {KEYCODE_RIGHT_KNOB_ROLL_UP, "KEYCODE_RIGHT_KNOB_ROLL_UP"},
1011         {KEYCODE_RIGHT_KNOB_ROLL_DOWN, "KEYCODE_RIGHT_KNOB_ROLL_DOWN"},
1012         {KEYCODE_RIGHT_KNOB, "KEYCODE_RIGHT_KNOB"},
1013         {KEYCODE_VOICE_SOURCE_SWITCH, "KEYCODE_VOICE_SOURCE_SWITCH"},
1014         {KEYCODE_LAUNCHER_MENU, "KEYCODE_LAUNCHER_MENU"},
1015     };
1016     auto iter = keyCodeToString.find(keyCode);
1017     if (iter == keyCodeToString.end()) {
1018         MMI_HILOGD("Failed to find the keycode");
1019         return "KEYCODE_INVALID";
1020     }
1021     return iter->second.c_str();
1022 }
1023 
Clone(std::shared_ptr<KeyEvent> keyEvent)1024 std::shared_ptr<KeyEvent> KeyEvent::Clone(std::shared_ptr<KeyEvent> keyEvent)
1025 {
1026     if (!keyEvent) {
1027         return nullptr;
1028     }
1029     auto event = std::shared_ptr<KeyEvent>(new (std::nothrow) KeyEvent(*keyEvent.get()));
1030     CHKPP(event);
1031     return event;
1032 }
1033 
IsValidKeyItem() const1034 bool KeyEvent::IsValidKeyItem() const
1035 {
1036     CALL_DEBUG_ENTER;
1037     int32_t sameKeyCodeNum = 0;
1038     int32_t keyCode = GetKeyCode();
1039     int32_t action = GetKeyAction();
1040 
1041     for (auto it = keys_.begin(); it != keys_.end(); ++it) {
1042         if (it->GetKeyCode() == keyCode) {
1043             if (++sameKeyCodeNum > 1) {
1044                 MMI_HILOGE("Keyitems keyCode is not unique with keyEvent keyCode");
1045                 return false;
1046             }
1047         }
1048         if (it->GetKeyCode() <= KEYCODE_UNKNOWN) {
1049             MMI_HILOGE("The keyCode is invalid");
1050             return false;
1051         }
1052         if (it->GetDownTime() <= 0) {
1053             MMI_HILOGE("The downtime is invalid");
1054             return false;
1055         }
1056         if (action != KEY_ACTION_UP && it->IsPressed() == false) {
1057             MMI_HILOGE("The isPressed is invalid");
1058             return false;
1059         }
1060         if (action == KEY_ACTION_UP && it->IsPressed() == false) {
1061             if (it->GetKeyCode() != keyCode) {
1062                 MMI_HILOGE("The keyCode is invalid when isPressed is false");
1063                 return false;
1064             }
1065         }
1066 
1067         auto item = it;
1068         for (++item; item != keys_.end(); item++) {
1069             if (it->GetKeyCode() == item->GetKeyCode()) {
1070                 MMI_HILOGE("Keyitems keyCode exist same items");
1071                 return false;
1072             }
1073         }
1074     }
1075 
1076     if (sameKeyCodeNum == 0) {
1077         MMI_HILOGE("Keyitems keyCode is not exist equal item with keyEvent keyCode");
1078         return false;
1079     }
1080     return true;
1081 }
1082 
IsValid() const1083 bool KeyEvent::IsValid() const
1084 {
1085     CALL_DEBUG_ENTER;
1086     int32_t keyCode = GetKeyCode();
1087     if (keyCode <= KEYCODE_UNKNOWN) {
1088         MMI_HILOGE("KeyCode_ is invalid");
1089         return false;
1090     }
1091 
1092     if (GetActionTime() <= 0) {
1093         MMI_HILOGE("Actiontime is invalid");
1094         return false;
1095     }
1096 
1097     int32_t action = GetKeyAction();
1098     if (action != KEY_ACTION_CANCEL && action != KEY_ACTION_UP &&
1099         action != KEY_ACTION_DOWN) {
1100         MMI_HILOGE("Action is invalid");
1101         return false;
1102     }
1103 
1104     if (!IsValidKeyItem()) {
1105         MMI_HILOGE("IsValidKeyItem is invalid");
1106         return false;
1107     }
1108     return true;
1109 }
1110 
1111 
WriteToParcel(Parcel & out) const1112 bool KeyEvent::WriteToParcel(Parcel &out) const
1113 {
1114     if (!InputEvent::WriteToParcel(out)) {
1115         return false;
1116     }
1117     WRITEINT32(out, keyCode_);
1118     if (keys_.size() > INT_MAX) {
1119         return false;
1120     }
1121     WRITEINT32(out, static_cast<int32_t>(keys_.size()));
1122     for (const auto &item : keys_) {
1123         if (!item.WriteToParcel(out)) {
1124             return false;
1125         }
1126     }
1127     WRITEINT32(out, keyAction_);
1128 
1129     return true;
1130 }
1131 
ReadFromParcel(Parcel & in)1132 bool KeyEvent::ReadFromParcel(Parcel &in)
1133 {
1134     if (!InputEvent::ReadFromParcel(in)) {
1135         return false;
1136     }
1137     READINT32(in, keyCode_);
1138     const int32_t keysSize = in.ReadInt32();
1139     if (keysSize < 0) {
1140         return false;
1141     }
1142     for (int32_t i = 0; i < keysSize; i++) {
1143         KeyItem val = {};
1144         if (!val.ReadFromParcel(in)) {
1145             return false;
1146         }
1147         keys_.push_back(val);
1148     }
1149     READINT32(in, keyAction_);
1150 
1151     return true;
1152 }
1153 
TransitionFunctionKey(int32_t keyCode)1154 int32_t KeyEvent::TransitionFunctionKey(int32_t keyCode)
1155 {
1156     switch (keyCode) {
1157         case KEYCODE_NUM_LOCK: {
1158             return NUM_LOCK_FUNCTION_KEY;
1159         }
1160         case KEYCODE_CAPS_LOCK: {
1161             return CAPS_LOCK_FUNCTION_KEY;
1162         }
1163         case KEYCODE_SCROLL_LOCK: {
1164             return SCROLL_LOCK_FUNCTION_KEY;
1165         }
1166         default: {
1167             MMI_HILOGW("Unknown key code");
1168             return UNKOWN_FUNCTION_KEY;
1169         }
1170     }
1171 }
1172 
GetFunctionKey(int32_t funcKey) const1173 bool KeyEvent::GetFunctionKey(int32_t funcKey) const
1174 {
1175     switch (funcKey) {
1176         case NUM_LOCK_FUNCTION_KEY: {
1177             return numLock_;
1178         }
1179         case CAPS_LOCK_FUNCTION_KEY: {
1180             return capsLock_;
1181         }
1182         case SCROLL_LOCK_FUNCTION_KEY: {
1183             return scrollLock_;
1184         }
1185         default: {
1186             MMI_HILOGW("Unknown function key");
1187             return false;
1188         }
1189     }
1190 }
1191 
SetFunctionKey(int32_t funcKey,int32_t value)1192 int32_t KeyEvent::SetFunctionKey(int32_t funcKey, int32_t value)
1193 {
1194     bool state = static_cast<bool>(value);
1195     switch (funcKey) {
1196         case NUM_LOCK_FUNCTION_KEY: {
1197             numLock_ = state;
1198             return funcKey;
1199         }
1200         case CAPS_LOCK_FUNCTION_KEY: {
1201             capsLock_ = state;
1202             return funcKey;
1203         }
1204         case SCROLL_LOCK_FUNCTION_KEY: {
1205             scrollLock_ = state;
1206             return funcKey;
1207         }
1208         default: {
1209             MMI_HILOGW("Unknown function key");
1210             return UNKOWN_FUNCTION_KEY;
1211         }
1212     }
1213 }
1214 } // namespace MMI
1215 } // namespace OHOS
1216