1 /*
2 * Copyright (c) 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 "event_normalize_handler.h"
17
18 #include "dfx_hisysevent.h"
19 #include "bytrace_adapter.h"
20 #include "define_multimodal.h"
21 #include "error_multimodal.h"
22 #include "event_log_helper.h"
23 #ifdef OHOS_BUILD_ENABLE_COOPERATE
24 #include "input_device_cooperate_sm.h"
25 #include "input_device_cooperate_util.h"
26 #endif // OHOS_BUILD_ENABLE_COOPERATE
27 #include "input_device_manager.h"
28 #include "input_event_handler.h"
29 #include "key_auto_repeat.h"
30 #include "key_event_normalize.h"
31 #include "key_event_value_transformation.h"
32 #include "libinput_adapter.h"
33 #include "mmi_log.h"
34 #include "time_cost_chk.h"
35 #include "timer_manager.h"
36 #include "touch_event_normalize.h"
37
38 namespace OHOS {
39 namespace MMI {
40 namespace {
41 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "EventNormalizeHandler" };
42 }
43
HandleEvent(libinput_event * event)44 void EventNormalizeHandler::HandleEvent(libinput_event* event)
45 {
46 CALL_DEBUG_ENTER;
47 CHKPV(event);
48 DfxHisysevent::GetDispStartTime();
49 auto type = libinput_event_get_type(event);
50 TimeCostChk chk("HandleLibinputEvent", "overtime 1000(us)", MAX_INPUT_EVENT_TIME, type);
51 if (type == LIBINPUT_EVENT_TOUCH_CANCEL || type == LIBINPUT_EVENT_TOUCH_FRAME) {
52 MMI_HILOGD("This touch event is canceled type:%{public}d", type);
53 return;
54 }
55 switch (type) {
56 case LIBINPUT_EVENT_DEVICE_ADDED: {
57 OnEventDeviceAdded(event);
58 break;
59 }
60 case LIBINPUT_EVENT_DEVICE_REMOVED: {
61 OnEventDeviceRemoved(event);
62 break;
63 }
64 case LIBINPUT_EVENT_KEYBOARD_KEY: {
65 HandleKeyboardEvent(event);
66 DfxHisysevent::CalcKeyDispTimes();
67 break;
68 }
69 case LIBINPUT_EVENT_POINTER_MOTION:
70 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
71 case LIBINPUT_EVENT_POINTER_BUTTON:
72 case LIBINPUT_EVENT_POINTER_AXIS: {
73 HandleMouseEvent(event);
74 DfxHisysevent::CalcPointerDispTimes();
75 break;
76 }
77 case LIBINPUT_EVENT_TOUCHPAD_DOWN:
78 case LIBINPUT_EVENT_TOUCHPAD_UP:
79 case LIBINPUT_EVENT_TOUCHPAD_MOTION: {
80 HandleTouchPadEvent(event);
81 DfxHisysevent::CalcPointerDispTimes();
82 break;
83 }
84 case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN:
85 case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE:
86 case LIBINPUT_EVENT_GESTURE_SWIPE_END:
87 case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
88 case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
89 case LIBINPUT_EVENT_GESTURE_PINCH_END: {
90 HandleGestureEvent(event);
91 DfxHisysevent::CalcPointerDispTimes();
92 break;
93 }
94 case LIBINPUT_EVENT_TOUCH_DOWN:
95 case LIBINPUT_EVENT_TOUCH_UP:
96 case LIBINPUT_EVENT_TOUCH_MOTION: {
97 HandleTouchEvent(event);
98 DfxHisysevent::CalcPointerDispTimes();
99 break;
100 }
101 case LIBINPUT_EVENT_TABLET_TOOL_AXIS:
102 case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY:
103 case LIBINPUT_EVENT_TABLET_TOOL_TIP: {
104 HandleTableToolEvent(event);
105 break;
106 }
107 default: {
108 MMI_HILOGW("This device does not support");
109 break;
110 }
111 }
112 DfxHisysevent::ReportDispTimes();
113 }
114
OnEventDeviceAdded(libinput_event * event)115 int32_t EventNormalizeHandler::OnEventDeviceAdded(libinput_event *event)
116 {
117 CHKPR(event, ERROR_NULL_POINTER);
118 auto device = libinput_event_get_device(event);
119 CHKPR(device, ERROR_NULL_POINTER);
120 InputDevMgr->OnInputDeviceAdded(device);
121 KeyMapMgr->ParseDeviceConfigFile(device);
122 KeyRepeat->AddDeviceConfig(device);
123 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
124 KeyEventHdr->ResetKeyEvent(device);
125 #endif // OHOS_BUILD_ENABLE_KEYBOARD
126 return RET_OK;
127 }
128
OnEventDeviceRemoved(libinput_event * event)129 int32_t EventNormalizeHandler::OnEventDeviceRemoved(libinput_event *event)
130 {
131 CHKPR(event, ERROR_NULL_POINTER);
132 auto device = libinput_event_get_device(event);
133 CHKPR(device, ERROR_NULL_POINTER);
134 KeyMapMgr->RemoveKeyValue(device);
135 KeyRepeat->RemoveDeviceConfig(device);
136 InputDevMgr->OnInputDeviceRemoved(device);
137 return RET_OK;
138 }
139
140 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
HandleKeyEvent(const std::shared_ptr<KeyEvent> keyEvent)141 void EventNormalizeHandler::HandleKeyEvent(const std::shared_ptr<KeyEvent> keyEvent)
142 {
143 if (nextHandler_ == nullptr) {
144 MMI_HILOGW("Keyboard device does not support");
145 return;
146 }
147 DfxHisysevent::GetDispStartTime();
148 CHKPV(keyEvent);
149 EventLogHelper::PrintEventData(keyEvent);
150 #ifdef OHOS_BUILD_ENABLE_COOPERATE
151 if (!CheckKeyboardWhiteList(keyEvent)) {
152 MMI_HILOGI("Check white list return false, keyboard event dropped");
153 return;
154 }
155 #endif // OHOS_BUILD_ENABLE_COOPERATE
156 nextHandler_->HandleKeyEvent(keyEvent);
157 DfxHisysevent::CalcKeyDispTimes();
158 DfxHisysevent::ReportDispTimes();
159 }
160 #endif // OHOS_BUILD_ENABLE_KEYBOARD
161
162 #ifdef OHOS_BUILD_ENABLE_POINTER
HandlePointerEvent(const std::shared_ptr<PointerEvent> pointerEvent)163 void EventNormalizeHandler::HandlePointerEvent(const std::shared_ptr<PointerEvent> pointerEvent)
164 {
165 if (nextHandler_ == nullptr) {
166 MMI_HILOGW("Pointer device does not support");
167 return;
168 }
169 DfxHisysevent::GetDispStartTime();
170 CHKPV(pointerEvent);
171 if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_AXIS_END) {
172 MMI_HILOGI("MouseEvent Normalization Results, PointerAction:%{public}d,PointerId:%{public}d,"
173 "SourceType:%{public}d,ButtonId:%{public}d,"
174 "VerticalAxisValue:%{public}lf,HorizontalAxisValue:%{public}lf",
175 pointerEvent->GetPointerAction(), pointerEvent->GetPointerId(), pointerEvent->GetSourceType(),
176 pointerEvent->GetButtonId(), pointerEvent->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL),
177 pointerEvent->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL));
178 PointerEvent::PointerItem item;
179 if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), item)) {
180 MMI_HILOGE("Get pointer item failed. pointer:%{public}d", pointerEvent->GetPointerId());
181 return;
182 }
183 MMI_HILOGI("MouseEvent Item Normalization Results, DownTime:%{public}" PRId64 ",IsPressed:%{public}d,"
184 "DisplayX:%{public}d,DisplayY:%{public}d,WindowX:%{public}d,WindowY:%{public}d,"
185 "Width:%{public}d,Height:%{public}d,Pressure:%{public}f,Device:%{public}d",
186 item.GetDownTime(), static_cast<int32_t>(item.IsPressed()), item.GetDisplayX(), item.GetDisplayY(),
187 item.GetWindowX(), item.GetWindowY(), item.GetWidth(), item.GetHeight(), item.GetPressure(),
188 item.GetDeviceId());
189 }
190 WinMgr->UpdateTargetPointer(pointerEvent);
191 nextHandler_->HandlePointerEvent(pointerEvent);
192 DfxHisysevent::CalcPointerDispTimes();
193 DfxHisysevent::ReportDispTimes();
194 }
195 #endif // OHOS_BUILD_ENABLE_POINTER
196
197 #ifdef OHOS_BUILD_ENABLE_TOUCH
HandleTouchEvent(const std::shared_ptr<PointerEvent> pointerEvent)198 void EventNormalizeHandler::HandleTouchEvent(const std::shared_ptr<PointerEvent> pointerEvent)
199 {
200 if (nextHandler_ == nullptr) {
201 MMI_HILOGW("Touchscreen device does not support");
202 return;
203 }
204 DfxHisysevent::GetDispStartTime();
205 CHKPV(pointerEvent);
206 WinMgr->UpdateTargetPointer(pointerEvent);
207 nextHandler_->HandleTouchEvent(pointerEvent);
208 DfxHisysevent::CalcPointerDispTimes();
209 DfxHisysevent::ReportDispTimes();
210 }
211 #endif // OHOS_BUILD_ENABLE_TOUCH
212
HandleKeyboardEvent(libinput_event * event)213 int32_t EventNormalizeHandler::HandleKeyboardEvent(libinput_event* event)
214 {
215 if (nextHandler_ == nullptr) {
216 MMI_HILOGW("Keyboard device does not support");
217 return ERROR_UNSUPPORT;
218 }
219 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
220 auto keyEvent = KeyEventHdr->GetKeyEvent();
221 CHKPR(keyEvent, ERROR_NULL_POINTER);
222 CHKPR(event, ERROR_NULL_POINTER);
223 std::vector<int32_t> pressedKeys = keyEvent->GetPressedKeys();
224 int32_t lastPressedKey = -1;
225 if (!pressedKeys.empty()) {
226 lastPressedKey = pressedKeys.back();
227 MMI_HILOGD("The last repeat button, keyCode:%{public}d", lastPressedKey);
228 }
229 auto packageResult = KeyEventHdr->Normalize(event, keyEvent);
230 if (packageResult == MULTIDEVICE_SAME_EVENT_MARK) {
231 MMI_HILOGD("The same event reported by multi_device should be discarded");
232 return RET_OK;
233 }
234 if (packageResult != RET_OK) {
235 MMI_HILOGE("KeyEvent package failed, ret:%{public}d,errCode:%{public}d", packageResult, KEY_EVENT_PKG_FAIL);
236 return KEY_EVENT_PKG_FAIL;
237 }
238
239 BytraceAdapter::StartBytrace(keyEvent);
240 EventLogHelper::PrintEventData(keyEvent);
241 #ifdef OHOS_BUILD_ENABLE_COOPERATE
242 if (!CheckKeyboardWhiteList(keyEvent)) {
243 MMI_HILOGI("Check white list return false, keyboard event dropped");
244 return RET_OK;
245 }
246 #endif // OHOS_BUILD_ENABLE_COOPERATE
247 nextHandler_->HandleKeyEvent(keyEvent);
248 KeyRepeat->SelectAutoRepeat(keyEvent);
249 MMI_HILOGD("keyCode:%{public}d, action:%{public}d", keyEvent->GetKeyCode(), keyEvent->GetKeyAction());
250 #else
251 MMI_HILOGW("Keyboard device does not support");
252 #endif // OHOS_BUILD_ENABLE_KEYBOARD
253 return RET_OK;
254 }
255
256 #ifdef OHOS_BUILD_ENABLE_COOPERATE
CheckKeyboardWhiteList(std::shared_ptr<KeyEvent> keyEvent)257 bool EventNormalizeHandler::CheckKeyboardWhiteList(std::shared_ptr<KeyEvent> keyEvent)
258 {
259 CALL_DEBUG_ENTER;
260 CHKPF(keyEvent);
261 InputHandler->SetJumpInterceptState(false);
262 int32_t keyCode = keyEvent->GetKeyCode();
263 if (keyCode == KeyEvent::KEYCODE_BACK || keyCode == KeyEvent::KEYCODE_VOLUME_UP
264 || keyCode == KeyEvent::KEYCODE_VOLUME_DOWN || keyCode == KeyEvent::KEYCODE_POWER) {
265 return true;
266 }
267 CooperateState state = InputDevCooSM->GetCurrentCooperateState();
268 MMI_HILOGI("Get current cooperate state:%{public}d", state);
269 if (state == CooperateState::STATE_IN) {
270 int32_t deviceId = keyEvent->GetDeviceId();
271 if (InputDevMgr->IsRemote(deviceId)) {
272 auto networkId = InputDevMgr->GetOriginNetworkId(deviceId);
273 return !IsNeedFilterOut(networkId, keyEvent);
274 }
275 } else if (state == CooperateState::STATE_OUT) {
276 std::string networkId = GetLocalDeviceId();
277 if (!IsNeedFilterOut(networkId, keyEvent)) {
278 if (keyEvent->GetKeyAction() == KeyEvent::KEY_ACTION_UP) {
279 KeyRepeat->SelectAutoRepeat(keyEvent);
280 }
281 return false;
282 }
283 InputHandler->SetJumpInterceptState(true);
284 } else {
285 MMI_HILOGW("Get current cooperate state:STATE_FREE(%{public}d)", state);
286 }
287 return true;
288 }
289 #endif // OHOS_BUILD_ENABLE_COOPERATE
290
291 #ifdef OHOS_BUILD_ENABLE_COOPERATE
IsNeedFilterOut(const std::string & deviceId,const std::shared_ptr<KeyEvent> keyEvent)292 bool EventNormalizeHandler::IsNeedFilterOut(const std::string& deviceId, const std::shared_ptr<KeyEvent> keyEvent)
293 {
294 CALL_DEBUG_ENTER;
295 std::vector<OHOS::MMI::KeyEvent::KeyItem> KeyItems = keyEvent->GetKeyItems();
296 std::vector<int32_t> KeyItemsForDInput;
297 KeyItemsForDInput.reserve(KeyItems.size());
298 for (const auto& item : KeyItems) {
299 KeyItemsForDInput.push_back(item.GetKeyCode());
300 }
301 OHOS::DistributedHardware::DistributedInput::BusinessEvent businessEvent;
302 businessEvent.keyCode = keyEvent->GetKeyCode();
303 businessEvent.keyAction = keyEvent->GetKeyAction();
304 businessEvent.pressedKeys = KeyItemsForDInput;
305 MMI_HILOGI("businessEvent.keyCode :%{public}d, keyAction :%{public}d",
306 businessEvent.keyCode, businessEvent.keyAction);
307 for (const auto &item : businessEvent.pressedKeys) {
308 MMI_HILOGI("pressedKeys :%{public}d", item);
309 }
310 return DistributedAdapter->IsNeedFilterOut(deviceId, businessEvent);
311 }
312 #endif // OHOS_BUILD_ENABLE_COOPERATE
313
HandleMouseEvent(libinput_event * event)314 int32_t EventNormalizeHandler::HandleMouseEvent(libinput_event* event)
315 {
316 if (nextHandler_ == nullptr) {
317 MMI_HILOGW("Pointer device does not support");
318 return ERROR_UNSUPPORT;
319 }
320 #ifdef OHOS_BUILD_ENABLE_POINTER
321 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
322 const auto &keyEvent = KeyEventHdr->GetKeyEvent();
323 CHKPR(keyEvent, ERROR_NULL_POINTER);
324 #endif // OHOS_BUILD_ENABLE_KEYBOARD
325 MouseEventHdr->Normalize(event);
326 auto pointerEvent = MouseEventHdr->GetPointerEvent();
327 CHKPR(pointerEvent, ERROR_NULL_POINTER);
328 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
329 std::vector<int32_t> pressedKeys = keyEvent->GetPressedKeys();
330 for (const int32_t& keyCode : pressedKeys) {
331 MMI_HILOGI("Pressed keyCode:%{public}d", keyCode);
332 }
333 pointerEvent->SetPressedKeys(pressedKeys);
334 #endif // OHOS_BUILD_ENABLE_KEYBOARD
335 BytraceAdapter::StartBytrace(pointerEvent, BytraceAdapter::TRACE_START);
336 nextHandler_->HandlePointerEvent(pointerEvent);
337 #else
338 MMI_HILOGW("Pointer device does not support");
339 #endif // OHOS_BUILD_ENABLE_POINTER
340 return RET_OK;
341 }
342
HandleTouchPadEvent(libinput_event * event)343 int32_t EventNormalizeHandler::HandleTouchPadEvent(libinput_event* event)
344 {
345 if (nextHandler_ == nullptr) {
346 MMI_HILOGW("Pointer device does not support");
347 return ERROR_UNSUPPORT;
348 }
349 #ifdef OHOS_BUILD_ENABLE_POINTER
350 CHKPR(event, ERROR_NULL_POINTER);
351 auto pointerEvent = TouchEventHdr->OnLibInput(event, INPUT_DEVICE_CAP_TOUCH_PAD);
352 CHKPR(pointerEvent, ERROR_NULL_POINTER);
353 nextHandler_->HandlePointerEvent(pointerEvent);
354 auto type = libinput_event_get_type(event);
355 if (type == LIBINPUT_EVENT_TOUCHPAD_UP) {
356 pointerEvent->RemovePointerItem(pointerEvent->GetPointerId());
357 MMI_HILOGD("This touch pad event is up remove this finger");
358 if (pointerEvent->GetPointerIds().empty()) {
359 MMI_HILOGD("This touch pad event is final finger up remove this finger");
360 pointerEvent->Reset();
361 }
362 }
363 #else
364 MMI_HILOGW("Pointer device does not support");
365 #endif // OHOS_BUILD_ENABLE_POINTER
366 return RET_OK;
367 }
368
HandleGestureEvent(libinput_event * event)369 int32_t EventNormalizeHandler::HandleGestureEvent(libinput_event* event)
370 {
371 if (nextHandler_ == nullptr) {
372 MMI_HILOGW("Pointer device does not support");
373 return ERROR_UNSUPPORT;
374 }
375 #ifdef OHOS_BUILD_ENABLE_POINTER
376 CHKPR(event, ERROR_NULL_POINTER);
377 auto pointerEvent = TouchEventHdr->OnLibInput(event, INPUT_DEVICE_CAP_GESTURE);
378 CHKPR(pointerEvent, GESTURE_EVENT_PKG_FAIL);
379 MMI_HILOGD("GestureEvent package, eventType:%{public}d,actionTime:%{public}" PRId64 ","
380 "action:%{public}d,actionStartTime:%{public}" PRId64 ","
381 "pointerAction:%{public}d,sourceType:%{public}d,"
382 "PinchAxisValue:%{public}.2f",
383 pointerEvent->GetEventType(), pointerEvent->GetActionTime(),
384 pointerEvent->GetAction(), pointerEvent->GetActionStartTime(),
385 pointerEvent->GetPointerAction(), pointerEvent->GetSourceType(),
386 pointerEvent->GetAxisValue(PointerEvent::AXIS_TYPE_PINCH));
387
388 PointerEvent::PointerItem item;
389 pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), item);
390 MMI_HILOGD("Item:DownTime:%{public}" PRId64 ",IsPressed:%{public}s,"
391 "DisplayX:%{public}d,DisplayY:%{public}d,WindowX:%{public}d,WindowY:%{public}d,"
392 "Width:%{public}d,Height:%{public}d",
393 item.GetDownTime(), (item.IsPressed() ? "true" : "false"),
394 item.GetDisplayX(), item.GetDisplayY(), item.GetWindowX(), item.GetWindowY(),
395 item.GetWidth(), item.GetHeight());
396 nextHandler_->HandlePointerEvent(pointerEvent);
397 #else
398 MMI_HILOGW("Pointer device does not support");
399 #endif // OHOS_BUILD_ENABLE_POINTER
400 return RET_OK;
401 }
402
HandleTouchEvent(libinput_event * event)403 int32_t EventNormalizeHandler::HandleTouchEvent(libinput_event* event)
404 {
405 LibinputAdapter::LoginfoPackagingTool(event);
406 if (nextHandler_ == nullptr) {
407 MMI_HILOGW("Touchscreen device does not support");
408 return ERROR_UNSUPPORT;
409 }
410 #ifdef OHOS_BUILD_ENABLE_TOUCH
411 CHKPR(event, ERROR_NULL_POINTER);
412 auto pointerEvent = TouchEventHdr->OnLibInput(event, INPUT_DEVICE_CAP_TOUCH);
413 CHKPR(pointerEvent, ERROR_NULL_POINTER);
414 BytraceAdapter::StartBytrace(pointerEvent, BytraceAdapter::TRACE_START);
415 nextHandler_->HandleTouchEvent(pointerEvent);
416 ResetTouchUpEvent(pointerEvent, event);
417 #else
418 MMI_HILOGW("Touchscreen device does not support");
419 #endif // OHOS_BUILD_ENABLE_TOUCH
420 return RET_OK;
421 }
422
ResetTouchUpEvent(std::shared_ptr<PointerEvent> pointerEvent,struct libinput_event * event)423 void EventNormalizeHandler::ResetTouchUpEvent(std::shared_ptr<PointerEvent> pointerEvent,
424 struct libinput_event *event)
425 {
426 CHKPV(pointerEvent);
427 CHKPV(event);
428 auto type = libinput_event_get_type(event);
429 if (type == LIBINPUT_EVENT_TOUCH_UP) {
430 pointerEvent->RemovePointerItem(pointerEvent->GetPointerId());
431 MMI_HILOGD("This touch event is up remove this finger");
432 if (pointerEvent->GetPointerIds().empty()) {
433 MMI_HILOGD("This touch event is final finger up remove this finger");
434 pointerEvent->Reset();
435 }
436 }
437 }
438
HandleTableToolEvent(libinput_event * event)439 int32_t EventNormalizeHandler::HandleTableToolEvent(libinput_event* event)
440 {
441 if (nextHandler_ == nullptr) {
442 MMI_HILOGW("Touchscreen device does not support");
443 return ERROR_UNSUPPORT;
444 }
445 #ifdef OHOS_BUILD_ENABLE_TOUCH
446 CHKPR(event, ERROR_NULL_POINTER);
447 auto pointerEvent = TouchEventHdr->OnLibInput(event, INPUT_DEVICE_CAP_TABLET_TOOL);
448 CHKPR(pointerEvent, ERROR_NULL_POINTER);
449 BytraceAdapter::StartBytrace(pointerEvent, BytraceAdapter::TRACE_START);
450 nextHandler_->HandleTouchEvent(pointerEvent);
451 if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_UP) {
452 pointerEvent->Reset();
453 }
454 #else
455 MMI_HILOGW("Touchscreen device does not support");
456 #endif // OHOS_BUILD_ENABLE_TOUCH
457 return RET_OK;
458 }
459
AddHandleTimer(int32_t timeout)460 int32_t EventNormalizeHandler::AddHandleTimer(int32_t timeout)
461 {
462 CALL_DEBUG_ENTER;
463 timerId_ = TimerMgr->AddTimer(timeout, 1, [this]() {
464 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
465 auto keyEvent = KeyEventHdr->GetKeyEvent();
466 CHKPV(keyEvent);
467 CHKPV(nextHandler_);
468 nextHandler_->HandleKeyEvent(keyEvent);
469 int32_t triggerTime = KeyRepeat->GetIntervalTime(keyEvent->GetDeviceId());
470 this->AddHandleTimer(triggerTime);
471 #endif // OHOS_BUILD_ENABLE_KEYBOARD
472 });
473 return timerId_;
474 }
475 } // namespace MMI
476 } // namespace OHOS
477