• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #ifndef KEY_EVENT_H
17 #define KEY_EVENT_H
18 
19 #include "multimodal_event.h"
20 #include "mmi_point.h"
21 
22 namespace OHOS {
23 struct KeyProperty {
24     bool isPressed;
25     int keyCode;
26     int keyDownDuration;
27 };
28 
29 class KeyEvent : public MultimodalEvent {
30 public:
31     void Initialize(MultimodalProperty &multiProperty, KeyProperty &KeyProperty);
32 
33     virtual int GetMaxKeyCode();
34 
35     virtual bool IsKeyDown();
36 
37     virtual int GetKeyCode();
38 
39     virtual int GetKeyDownDuration();
40 
41     bool Marshalling(Parcel &parcel) const override;
42     static KeyEvent *Unmarshalling(Parcel &parcel);
43 
44     static constexpr int KEY_PRESSED = 0;
45 
46     static constexpr int KEY_RELEASED = 1;
47 
48     static constexpr int CODE_UNKNOWN = -1;
49 
50     static constexpr int CODE_HOME = 1;
51 
52     static constexpr int CODE_BACK = 2;
53 
54     static constexpr int CODE_CALL = 3;
55 
56     static constexpr int CODE_ENDCALL = 4;
57 
58     static constexpr int CODE_CLEAR = 5;
59 
60     static constexpr int CODE_HEADSETHOOK = 6;
61 
62     static constexpr int CODE_FOCUS = 7;
63 
64     static constexpr int CODE_NOTIFICATION = 8;
65 
66     static constexpr int CODE_SEARCH = 9;
67 
68     static constexpr int CODE_MEDIA_PLAY_PAUSE = 10;
69 
70     static constexpr int CODE_MEDIA_STOP = 11;
71 
72     static constexpr int CODE_MEDIA_NEXT = 12;
73 
74     static constexpr int CODE_MEDIA_PREVIOUS = 13;
75 
76     static constexpr int CODE_MEDIA_REWIND = 14;
77 
78     static constexpr int CODE_MEDIA_FAST_FORWARD = 15;
79 
80     static constexpr int CODE_VOLUME_UP = 16;
81 
82     static constexpr int CODE_VOLUME_DOWN = 17;
83 
84     static constexpr int CODE_POWER = 18;
85 
86     static constexpr int CODE_CAMERA = 19;
87 
88     static constexpr int CODE_VOICE_ASSISTANT = 20;
89 
90     static constexpr int CODE_CUSTOM1 = 21;
91 
92     static constexpr int CODE_BRIGHTNESS_UP = 40;
93 
94     static constexpr int CODE_BRIGHTNESS_DOWN = 41;
95 
96     static constexpr int CODE_WEAR_1 = 1001;
97 
98     static constexpr int CODE_0 = 2000;
99 
100     static constexpr int CODE_1 = 2001;
101 
102     static constexpr int CODE_2 = 2002;
103 
104     static constexpr int CODE_3 = 2003;
105 
106     static constexpr int CODE_4 = 2004;
107 
108     static constexpr int CODE_5 = 2005;
109 
110     static constexpr int CODE_6 = 2006;
111 
112     static constexpr int CODE_7 = 2007;
113 
114     static constexpr int CODE_8 = 2008;
115 
116     static constexpr int CODE_9 = 2009;
117 
118     static constexpr int CODE_STAR = 2010;
119 
120     static constexpr int CODE_POUND = 2011;
121 
122     static constexpr int CODE_DPAD_UP = 2012;
123 
124     static constexpr int CODE_DPAD_DOWN = 2013;
125 
126     static constexpr int CODE_DPAD_LEFT = 2014;
127 
128     static constexpr int CODE_DPAD_RIGHT = 2015;
129 
130     static constexpr int CODE_DPAD_CENTER = 2016;
131 
132     static constexpr int CODE_A = 2017;
133 
134     static constexpr int CODE_B = 2018;
135 
136     static constexpr int CODE_C = 2019;
137 
138     static constexpr int CODE_D = 2020;
139 
140     static constexpr int CODE_E = 2021;
141 
142     static constexpr int CODE_F = 2022;
143 
144     static constexpr int CODE_G = 2023;
145 
146     static constexpr int CODE_H = 2024;
147 
148     static constexpr int CODE_I = 2025;
149 
150     static constexpr int CODE_J = 2026;
151 
152     static constexpr int CODE_K = 2027;
153 
154     static constexpr int CODE_L = 2028;
155 
156     static constexpr int CODE_M = 2029;
157 
158     static constexpr int CODE_N = 2030;
159 
160     static constexpr int CODE_O = 2031;
161 
162     static constexpr int CODE_P = 2032;
163 
164     static constexpr int CODE_Q = 2033;
165 
166     static constexpr int CODE_R = 2034;
167 
168     static constexpr int CODE_S = 2035;
169 
170     static constexpr int CODE_T = 2036;
171 
172     static constexpr int CODE_U = 2037;
173 
174     static constexpr int CODE_V = 2038;
175 
176     static constexpr int CODE_W = 2039;
177 
178     static constexpr int CODE_X = 2040;
179 
180     static constexpr int CODE_Y = 2041;
181 
182     static constexpr int CODE_Z = 2042;
183 
184     static constexpr int CODE_COMMA = 2043;
185 
186     static constexpr int CODE_PERIOD = 2044;
187 
188     static constexpr int CODE_ALT_LEFT = 2045;
189 
190     static constexpr int CODE_ALT_RIGHT = 2046;
191 
192     static constexpr int CODE_SHIFT_LEFT = 2047;
193 
194     static constexpr int CODE_SHIFT_RIGHT = 2048;
195 
196     static constexpr int CODE_TAB = 2049;
197 
198     static constexpr int CODE_SPACE = 2050;
199 
200     static constexpr int CODE_SYM = 2051;
201 
202     static constexpr int CODE_EXPLORER = 2052;
203 
204     static constexpr int CODE_ENVELOPE = 2053;
205 
206     static constexpr int CODE_ENTER = 2054;
207 
208     static constexpr int CODE_DEL = 2055;
209 
210     static constexpr int CODE_GRAVE = 2056;
211 
212     static constexpr int CODE_MINUS = 2057;
213 
214     static constexpr int CODE_EQUALS = 2058;
215 
216     static constexpr int CODE_LEFT_BRACKET = 2059;
217 
218     static constexpr int CODE_RIGHT_BRACKET = 2060;
219 
220     static constexpr int CODE_BACKSLASH = 2061;
221 
222     static constexpr int CODE_SEMICOLON = 2062;
223 
224     static constexpr int CODE_APOSTROPHE = 2063;
225 
226     static constexpr int CODE_SLASH = 2064;
227 
228     static constexpr int CODE_AT = 2065;
229 
230     static constexpr int CODE_PLUS = 2066;
231 
232     static constexpr int CODE_MENU = 2067;
233 
234     static constexpr int CODE_PAGE_UP = 2068;
235 
236     static constexpr int CODE_PAGE_DOWN = 2069;
237 
238     static constexpr int CODE_ESCAPE = 2070;
239 
240     static constexpr int CODE_FORWARD_DEL = 2071;
241 
242     static constexpr int CODE_CTRL_LEFT = 2072;
243 
244     static constexpr int CODE_CTRL_RIGHT = 2073;
245 
246     static constexpr int CODE_CAPS_LOCK = 2074;
247 
248     static constexpr int CODE_SCROLL_LOCK = 2075;
249 
250     static constexpr int CODE_META_LEFT = 2076;
251 
252     static constexpr int CODE_META_RIGHT = 2077;
253 
254     static constexpr int CODE_FUNCTION = 2078;
255 
256     static constexpr int CODE_SYSRQ = 2079;
257 
258     static constexpr int CODE_BREAK = 2080;
259 
260     static constexpr int CODE_MOVE_HOME = 2081;
261 
262     static constexpr int CODE_MOVE_END = 2082;
263 
264     static constexpr int CODE_INSERT = 2083;
265 
266     static constexpr int CODE_FORWARD = 2084;
267 
268     static constexpr int CODE_MEDIA_PLAY = 2085;
269 
270     static constexpr int CODE_MEDIA_PAUSE = 2086;
271 
272     static constexpr int CODE_MEDIA_CLOSE = 2087;
273 
274     static constexpr int CODE_MEDIA_EJECT = 2088;
275 
276     static constexpr int CODE_MEDIA_RECORD = 2089;
277 
278     static constexpr int CODE_F1 = 2090;
279 
280     static constexpr int CODE_F2 = 2091;
281 
282     static constexpr int CODE_F3 = 2092;
283 
284     static constexpr int CODE_F4 = 2093;
285 
286     static constexpr int CODE_F5 = 2094;
287 
288     static constexpr int CODE_F6 = 2095;
289 
290     static constexpr int CODE_F7 = 2096;
291 
292     static constexpr int CODE_F8 = 2097;
293 
294     static constexpr int CODE_F9 = 2098;
295 
296     static constexpr int CODE_F10 = 2099;
297 
298     static constexpr int CODE_F11 = 2100;
299 
300     static constexpr int CODE_F12 = 2101;
301 
302     static constexpr int CODE_NUM_LOCK = 2102;
303 
304     static constexpr int CODE_NUMPAD_0 = 2103;
305 
306     static constexpr int CODE_NUMPAD_1 = 2104;
307 
308     static constexpr int CODE_NUMPAD_2 = 2105;
309 
310     static constexpr int CODE_NUMPAD_3 = 2106;
311 
312     static constexpr int CODE_NUMPAD_4 = 2107;
313 
314     static constexpr int CODE_NUMPAD_5 = 2108;
315 
316     static constexpr int CODE_NUMPAD_6 = 2109;
317 
318     static constexpr int CODE_NUMPAD_7 = 2110;
319 
320     static constexpr int CODE_NUMPAD_8 = 2111;
321 
322     static constexpr int CODE_NUMPAD_9 = 2112;
323 
324     static constexpr int CODE_NUMPAD_DIVIDE = 2113;
325 
326     static constexpr int CODE_NUMPAD_MULTIPLY = 2114;
327 
328     static constexpr int CODE_NUMPAD_SUBTRACT = 2115;
329 
330     static constexpr int CODE_NUMPAD_ADD = 2116;
331 
332     static constexpr int CODE_NUMPAD_DOT = 2117;
333 
334     static constexpr int CODE_NUMPAD_COMMA = 2118;
335 
336     static constexpr int CODE_NUMPAD_ENTER = 2119;
337 
338     static constexpr int CODE_NUMPAD_EQUALS = 2120;
339 
340     static constexpr int CODE_NUMPAD_LEFT_PAREN = 2121;
341 
342     static constexpr int CODE_NUMPAD_RIGHT_PAREN = 2122;
343 
344     static constexpr int CODE_LEFT_KNOB_ROLL_UP = 10001;
345 
346     static constexpr int CODE_LEFT_KNOB_ROLL_DOWN = 10002;
347 
348     static constexpr int CODE_LEFT_KNOB = 10003;
349 
350     static constexpr int CODE_RIGHT_KNOB_ROLL_UP = 10004;
351 
352     static constexpr int CODE_RIGHT_KNOB_ROLL_DOWN = 10005;
353 
354     static constexpr int CODE_RIGHT_KNOB = 10006;
355 
356     static constexpr int CODE_VOICE_SOURCE_SWITCH = 10007;
357 
358     static constexpr int CODE_LAUNCHER_MENU = 10008;
359 
360     static constexpr int NOW_MAX_CODE = CODE_LAUNCHER_MENU;
361 protected:
362     KeyProperty keyProperty_;
363 };
364 }  // namespace OHOS
365 #endif  // KEY_EVENT_H
366