1 /* 2 * Copyright (c) 2021-2024 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 INPUT_MANAGER_H 17 #define INPUT_MANAGER_H 18 19 #include <list> 20 #include <map> 21 #include <memory> 22 #include <vector> 23 24 #include "event_handler.h" 25 #include "nocopyable.h" 26 27 #include "error_multimodal.h" 28 #include "extra_data.h" 29 #include "i_anco_consumer.h" 30 #include "i_anr_observer.h" 31 #include "i_input_device_listener.h" 32 #include "i_input_event_consumer.h" 33 #include "i_input_event_filter.h" 34 #include "i_input_service_watcher.h" 35 #include "i_window_checker.h" 36 #include "infrared_frequency_info.h" 37 #include "input_device.h" 38 #include "input_handler_type.h" 39 #include "key_option.h" 40 #include "mmi_event_observer.h" 41 #include "pointer_style.h" 42 #include "window_info.h" 43 44 namespace OHOS { 45 namespace MMI { 46 class InputManager { 47 public: 48 /** 49 * @brief Obtains an <b>InputManager</b> instance. 50 * @return Returns the pointer to the <b>InputManager</b> instance. 51 * @since 9 52 */ 53 static InputManager *GetInstance(); 54 virtual ~InputManager() = default; 55 56 int32_t GetDisplayBindInfo(DisplayBindInfos &infos); 57 int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg); 58 59 /** 60 * @brief Updates the screen and window information. 61 * @param displayGroupInfo Indicates the logical screen information. 62 * @since 9 63 */ 64 int32_t UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInfo); 65 66 /** 67 * @brief Updates the windows information. 68 * @param windowGroupInfo Indicates the window group information. 69 * @since 9 70 */ 71 int32_t UpdateWindowInfo(const WindowGroupInfo &windowGroupInfo); 72 73 int32_t AddInputEventFilter(std::shared_ptr<IInputEventFilter> filter, int32_t priority, uint32_t deviceTags); 74 int32_t RemoveInputEventFilter(int32_t filterId); 75 76 /** 77 * @brief Updates the process info to other server. 78 * @param observer Indicates the progess info. 79 * @return the observer setting successed or not. 80 * @since 10 81 */ 82 int32_t AddInputEventObserver(std::shared_ptr<MMIEventObserver> observer); 83 84 /** 85 * @brief Callback interface of the remove module. 86 * @param observer Indicates the progess info. 87 * @return EC_OK if unsubscribe successfully, else return other errcodes. 88 * @since 10 89 */ 90 int32_t RemoveInputEventObserver(std::shared_ptr<MMIEventObserver> observer = nullptr); 91 92 /** 93 * @brief Set the process info to mmi server. 94 * @param pid Indicates pid. 95 * @param uid Indicates uid. 96 * @param bundleName Indicates bundleName. 97 * @param napStatus Indicates napStatus. 98 * @since 10 99 */ 100 void SetNapStatus(int32_t pid, int32_t uid, std::string bundleName, int32_t napStatus); 101 102 /** 103 * @brief Get the process info datas to other server. 104 * @param callback Indicates the callback used to receive the reported data. 105 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 106 * @since 10 107 */ 108 int32_t GetAllMmiSubscribedEvents(std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> &datas); 109 110 /** 111 * @brief Sets a consumer for the window input event of the current process. 112 * @param inputEventConsumer Indicates the consumer to set. The window input event of the current process 113 * will be called back to the consumer object for processing. 114 * @since 9 115 */ 116 void SetWindowInputEventConsumer(std::shared_ptr<IInputEventConsumer> inputEventConsumer); 117 118 /** 119 * @brief Sets a window input event consumer that runs on the specified thread. 120 * @param inputEventConsumer Indicates the consumer to set. 121 * @param eventHandler Indicates the thread running the consumer. 122 * @since 9 123 */ 124 void SetWindowInputEventConsumer(std::shared_ptr<IInputEventConsumer> inputEventConsumer, 125 std::shared_ptr<AppExecFwk::EventHandler> eventHandler); 126 127 /** 128 * @brief Subscribes to the key input event that meets a specific condition. When such an event occurs, 129 * the <b>callback</b> specified is invoked to process the event. 130 * @param keyOption Indicates the condition of the key input event. 131 * @param callback Indicates the callback. 132 * @return Returns the subscription ID, which uniquely identifies a subscription in the process. 133 * If the value is greater than or equal to <b>0</b>, 134 * the subscription is successful. Otherwise, the subscription fails. 135 * @since 9 136 */ 137 int32_t SubscribeKeyEvent(std::shared_ptr<KeyOption> keyOption, 138 std::function<void(std::shared_ptr<KeyEvent>)> callback); 139 140 /** 141 * @brief Unsubscribes from a key input event. 142 * @param subscriberId Indicates the subscription ID, which is the return value of <b>SubscribeKeyEvent</b>. 143 * @return void 144 * @since 9 145 */ 146 void UnsubscribeKeyEvent(int32_t subscriberId); 147 148 /** 149 * @brief Subscribes to the switch input event that meets a specific condition. When such an event occurs, 150 * the <b>callback</b> specified is invoked to process the event. 151 * @param callback Indicates the callback. 152 * @param switchType Indicates the type of switch input event. 153 * @return Returns the subscription ID, which uniquely identifies a subscription in the process. 154 * If the value is greater than or equal to <b>0</b>, 155 * the subscription is successful. Otherwise, the subscription fails. 156 * @since 9 157 */ 158 int32_t SubscribeSwitchEvent(std::function<void(std::shared_ptr<SwitchEvent>)> callback, 159 SwitchEvent::SwitchType switchType = SwitchEvent::SwitchType::SWITCH_DEFAULT); 160 161 /** 162 * @brief Unsubscribes from a switch input event. 163 * @param subscriberId Indicates the subscription ID, which is the return value of <b>SubscribeKeyEvent</b>. 164 * @return void 165 * @since 9 166 */ 167 void UnsubscribeSwitchEvent(int32_t subscriberId); 168 169 /** 170 * @brief Adds an input event monitor. After such a monitor is added, 171 * an input event is copied and distributed to the monitor while being distributed to the original target. 172 * @param monitor Indicates the input event monitor. After an input event is generated, 173 * the functions of the monitor object will be called. 174 * @return Returns the monitor ID, which uniquely identifies a monitor in the process. 175 * If the value is greater than or equal to <b>0</b>, the monitor is successfully added. Otherwise, 176 * the monitor fails to be added. 177 * @since 9 178 */ 179 int32_t AddMonitor(std::function<void(std::shared_ptr<KeyEvent>)> monitor); 180 181 /** 182 * @brief Adds an input event monitor. After such a monitor is added, 183 * an input event is copied and distributed to the monitor while being distributed to the original target. 184 * @param monitor Indicates the input event monitor. After an input event is generated, 185 * the functions of the monitor object will be called. 186 * @return Returns the monitor ID, which uniquely identifies a monitor in the process. 187 * If the value is greater than or equal to <b>0</b>, the monitor is successfully added. Otherwise, 188 * the monitor fails to be added. 189 * @since 9 190 */ 191 int32_t AddMonitor(std::function<void(std::shared_ptr<PointerEvent>)> monitor); 192 193 /** 194 * @brief Adds an input event monitor. After such a monitor is added, 195 * an input event is copied and distributed to the monitor while being distributed to the original target. 196 * @param monitor Indicates the input event monitor. After an input event is generated, 197 * the functions of the monitor object will be called. 198 * @param eventType Indicates the eventType for monitor. 199 * @return Returns the monitor ID, which uniquely identifies a monitor in the process. 200 * If the value is greater than or equal to <b>0</b>, the monitor is successfully added. Otherwise, 201 * the monitor fails to be added. 202 * @since 9 203 */ 204 int32_t AddMonitor(std::shared_ptr<IInputEventConsumer> monitor, HandleEventType eventType = HANDLE_EVENT_TYPE_KP); 205 206 /** 207 * @brief Removes a monitor. 208 * @param monitorId Indicates the monitor ID, which is the return value of <b>AddMonitor</b>. 209 * @return void 210 * @since 9 211 */ 212 void RemoveMonitor(int32_t monitorId); 213 214 /** 215 * @brief Marks that a monitor has consumed a touchscreen input event. After being consumed, 216 * the touchscreen input event will not be distributed to the original target. 217 * @param monitorId Indicates the monitor ID. 218 * @param eventId Indicates the ID of the consumed touchscreen input event. 219 * @return void 220 * @since 9 221 */ 222 void MarkConsumed(int32_t monitorId, int32_t eventId); 223 224 /** 225 * @brief Moves the cursor to the specified position. 226 * @param offsetX Indicates the offset on the X axis. 227 * @param offsetY Indicates the offset on the Y axis. 228 * @return void 229 * @since 9 230 */ 231 void MoveMouse(int32_t offsetX, int32_t offsetY); 232 233 /** 234 * @brief Adds an input event interceptor. After such an interceptor is added, 235 * an input event will be distributed to the interceptor instead of the original target and monitor. 236 * @param interceptor Indicates the input event interceptor. After an input event is generated, 237 * the functions of the interceptor object will be called. 238 * @return Returns the interceptor ID, which uniquely identifies an interceptor in the process. 239 * If the value is greater than or equal to <b>0</b>,the interceptor is successfully added. Otherwise, 240 * the interceptor fails to be added. 241 * @since 9 242 */ 243 int32_t AddInterceptor(std::shared_ptr<IInputEventConsumer> interceptor); 244 int32_t AddInterceptor(std::function<void(std::shared_ptr<KeyEvent>)> interceptor); 245 int32_t AddInterceptor(std::shared_ptr<IInputEventConsumer> interceptor, int32_t priority, uint32_t deviceTags); 246 247 /** 248 * @brief Removes an interceptor. 249 * @param interceptorId Indicates the interceptor ID, which is the return value of <b>AddInterceptor</b>. 250 * @return void 251 * @since 9 252 */ 253 void RemoveInterceptor(int32_t interceptorId); 254 255 /** 256 * @brief Simulates a key input event. This event will be distributed and 257 * processed in the same way as the event reported by the input device. 258 * @param keyEvent Indicates the key input event to simulate. 259 * @return void 260 * @since 9 261 */ 262 void SimulateInputEvent(std::shared_ptr<KeyEvent> keyEvent); 263 264 /** 265 * @brief Simulates a touchpad input event, touchscreen input event, or mouse device input event. 266 * This event will be distributed and processed in the same way as the event reported by the input device. 267 * @param pointerEvent Indicates the touchpad input event, touchscreen input event, 268 * or mouse device input event to simulate. 269 * @return void 270 * @since 9 271 */ 272 void SimulateInputEvent(std::shared_ptr<PointerEvent> pointerEvent); 273 274 /** 275 * @brief Simulates a touchpad input event, touchscreen input event, or mouse device input event. 276 * This event will be distributed and processed in the same way as the event reported by the input device. 277 * @param pointerEvent Indicates the touchpad input event, touchscreen input event, 278 * or mouse device input event to simulate. 279 * @param zOrder Indicates the point event will inject to the window whose index value is less than the zOrder 280 * @return void 281 * @since 9 282 */ 283 void SimulateInputEvent(std::shared_ptr<PointerEvent> pointerEvent, float zOrder); 284 285 /** 286 * @brief Starts listening for an input device event. 287 * @param type Indicates the type of the input device event, which is <b>change</b>. 288 * @param listener Indicates the listener for the input device event. 289 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 290 * @since 9 291 */ 292 int32_t RegisterDevListener(std::string type, std::shared_ptr<IInputDeviceListener> listener); 293 294 /** 295 * @brief Stops listening for an input device event. 296 * @param type Indicates the type of the input device event, which is <b>change</b>. 297 * @param listener Indicates the listener for the input device event. 298 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 299 * @since 9 300 */ 301 int32_t UnregisterDevListener(std::string type, std::shared_ptr<IInputDeviceListener> listener = nullptr); 302 303 /** 304 * @brief Obtains the information about an input device. 305 * @param callback Indicates the callback used to receive the reported data. 306 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 307 * @since 9 308 */ 309 int32_t GetDeviceIds(std::function<void(std::vector<int32_t>&)> callback); 310 311 /** 312 * @brief Obtains the information about an input device. 313 * @param deviceId Indicates the ID of the input device whose information is to be obtained. 314 * @param callback Indicates the callback used to receive the reported data. 315 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 316 * @since 9 317 */ 318 int32_t GetDevice(int32_t deviceId, std::function<void(std::shared_ptr<InputDevice>)> callback); 319 320 /** 321 * @brief Checks whether the specified key codes of an input device are supported. 322 * @param deviceId Indicates the ID of the input device. 323 * @param keyCodes Indicates the key codes of the input device. 324 * @param callback Indicates the callback used to receive the reported data. 325 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 326 * @since 9 327 */ 328 int32_t SupportKeys(int32_t deviceId, std::vector<int32_t> keyCodes, 329 std::function<void(std::vector<bool>&)> callback); 330 331 /** 332 * @brief Sets the number of the mouse scrolling rows. 333 * @param rows Indicates the number of the mouse scrolling rows. 334 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 335 * @since 9 336 */ 337 int32_t SetMouseScrollRows(int32_t rows); 338 339 /** 340 * @brief Set pixelMap to override ohos mouse icon resouce. 341 * @param windowId Indicates the windowId of the window 342 * @param pixelMap Indicates the image resouce for this mouse icon. which realtype must be OHOS::Media::PixelMap* 343 * @param focusX Indicates focus x 344 * @param focusY Indicates focus y 345 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 346 * @since 9 347 */ 348 int32_t SetCustomCursor(int32_t windowId, void* pixelMap, int32_t focusX = 0, int32_t focusY = 0); 349 350 /** 351 * @brief Set pixelMap to override ohos mouse icon resouce. 352 * @param windowId Indicates the windowId of the window 353 * @param pixelMap Indicates the image resouce for this mouse icon. which realtype must be OHOS::Media::PixelMap* 354 * @return vint32_t 355 * @since 10 356 */ 357 int32_t SetMouseIcon(int32_t windowId, void* pixelMap); 358 359 /** 360 * @brief Set mouse icon hot spot. 361 * @param windowId Indicates the windowId of the window 362 * @param hotSpotX Indicates the hot spot x for this mouse icon. 363 * @param hotSpotY Indicates the hot spot y for this mouse icon. 364 * @return vint32_t 365 * @since 10 366 */ 367 int32_t SetMouseHotSpot(int32_t windowId, int32_t hotSpotX, int32_t hotSpotY); 368 369 /** 370 * @brief Gets the number of the mouse scrolling rows. 371 * @param rows Indicates the number of the mouse scrolling rows. 372 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 373 * @since 9 374 */ 375 int32_t GetMouseScrollRows(int32_t &rows); 376 377 /** 378 * @brief Sets pointer size. 379 * @param size Indicates pointer size. 380 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 381 * @since 9 382 */ 383 int32_t SetPointerSize(int32_t size); 384 385 /** 386 * @brief Gets pointer size. 387 * @param size Indicates pointer size. 388 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 389 * @since 9 390 */ 391 int32_t GetPointerSize(int32_t &size); 392 393 /** 394 * @brief Enable combine key 395 * @param enable Indicates whether the combine key is enabled. The value true indicates that the combine key 396 * is enabled, and the value false indicates the opposite. 397 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 398 * @since 11 399 */ 400 int32_t EnableCombineKey(bool enable); 401 402 /** 403 * @brief Sets mouse primary button. 404 * @param primaryButton Indicates the ID of the mouse primary button.The value 0 indicates that 405 * the primary button is left button.The value 1 indicates that the primary button is right button. 406 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 407 * @since 9 408 */ 409 int32_t SetMousePrimaryButton(int32_t primaryButton); 410 411 /** 412 * @brief Gets mouse primary button. 413 * @param primaryButton Indicates the ID of the mouse primary button.The value 0 indicates that 414 * the primary button is left button.The value 1 indicates that the primary button is right button. 415 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 416 * @since 9 417 */ 418 int32_t GetMousePrimaryButton(int32_t &primaryButton); 419 420 /** 421 * @brief Sets whether the mouse hover scroll is enabled in inactive window. 422 * @param state Indicates whether the mouse hover scroll is enabled in inactive window. The value true 423 * indicates that the mouse hover scroll is enabled, and the value false indicates the opposite. 424 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 425 * @since 9 426 */ 427 int32_t SetHoverScrollState(bool state); 428 429 /** 430 * @brief Gets a status whether the mouse hover scroll is enabled in inactive window. 431 * @param state Indicates whether the mouse hover scroll is enabled in inactive window. The value true 432 * indicates that the mouse hover scroll is enabled, and the value false indicates the opposite. 433 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 434 * @since 9 435 */ 436 int32_t GetHoverScrollState(bool &state); 437 438 /** 439 * @brief Sets whether the pointer icon is visible. 440 * @param visible Indicates whether the pointer icon is visible. The value <b>true</b> indicates that 441 * the pointer icon is visible, and the value <b>false</b> indicates the opposite. 442 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 443 * @since 9 444 */ 445 int32_t SetPointerVisible(bool visible, int32_t priority = 0); 446 447 /** 448 * @brief Checks whether the pointer icon is visible. 449 * @return Returns <b>true</b> if the pointer icon is visible; returns <b>false</b> otherwise. 450 * @since 9 451 */ 452 bool IsPointerVisible(); 453 454 /** 455 * @brief Sets the mouse pointer style. 456 * @param windowId Indicates the ID of the window for which the mouse pointer style is set. 457 * @param pointerStyle Indicates the ID of the mouse pointer style. 458 * @return Returns <b>0</b> if the operation is successful; returns an error code otherwise. 459 * @since 9 460 */ 461 int32_t SetPointerStyle(int32_t windowId, PointerStyle pointerStyle, bool isUiExtension = false); 462 463 /** 464 * @brief Obtains the mouse pointer style. 465 * @param windowId Indicates the ID of the window for which the mouse pointer style is obtained. 466 * @param pointerStyle Indicates the ID of the mouse pointer style. 467 * @return Returns <b>0</b> if the operation is successful; returns an error code otherwise. 468 * @since 9 469 */ 470 int32_t GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle, bool isUiExtension = false); 471 472 /** 473 * @brief Sets pointer color. 474 * @param color Indicates pointer color. 475 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 476 * @since 9 477 */ 478 int32_t SetPointerColor(int32_t color); 479 480 /** 481 * @brief Gets pointer color. 482 * @param color Indicates pointer color. 483 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 484 * @since 9 485 */ 486 int32_t GetPointerColor(int32_t &color); 487 488 /** 489 * @brief Sets the mouse pointer speed, which ranges from 1 to 11. 490 * @param speed Indicates the mouse pointer speed to set. 491 * @return Returns <b>RET_OK</b> if success; returns <b>RET_ERR</b> otherwise. 492 * @since 9 493 */ 494 int32_t SetPointerSpeed(int32_t speed); 495 496 /** 497 * @brief Obtains the mouse pointer speed. 498 * @param speed Indicates the mouse pointer speed to get. 499 * @return Returns the mouse pointer speed if the operation is successful; returns <b>RET_ERR</b> otherwise. 500 * @since 9 501 */ 502 int32_t GetPointerSpeed(int32_t &speed); 503 504 /** 505 * @brief Queries the keyboard type. 506 * @param deviceId Indicates the keyboard device ID. 507 * @param callback Callback used to return the keyboard type. 508 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 509 * @since 9 510 */ 511 int32_t GetKeyboardType(int32_t deviceId, std::function<void(int32_t)> callback); 512 513 /** 514 * @brief Sets the observer for events indicating that the application does not respond. 515 * @param observer Indicates the observer for events indicating that the application does not respond. 516 * @return void 517 * @since 9 518 */ 519 void SetAnrObserver(std::shared_ptr<IAnrObserver> observer); 520 521 /** 522 * @brief Obtains the enablement status of the specified function key on the keyboard. 523 * @param funcKey Indicates the function key. Currently, the following function keys are supported: 524 * NUM_LOCK_FUNCTION_KEY 525 * CAPS_LOCK_FUNCTION_KEY 526 * SCROLL_LOCK_FUNCTION_KEY 527 * @return Returns <b>true</b> if the function key is enabled; 528 * returns <b>false</b> otherwise. 529 */ 530 bool GetFunctionKeyState(int32_t funcKey); 531 532 /** 533 * @brief Sets the enablement status of the specified function key on the keyboard. 534 * @param funcKey Indicates the function key. Currently, the following function keys are supported: 535 * NUM_LOCK_FUNCTION_KEY 536 * CAPS_LOCK_FUNCTION_KEY 537 * SCROLL_LOCK_FUNCTION_KEY 538 * @param isEnable Indicates the enablement status to set. 539 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 540 */ 541 int32_t SetFunctionKeyState(int32_t funcKey, bool enable); 542 543 /** 544 * @brief Sets the absolute coordinate of mouse. 545 * @param x Specifies the x coordinate of the mouse to be set. 546 * @param y Specifies the y coordinate of the mouse to be set. 547 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 548 * @since 9 549 */ 550 int32_t SetPointerLocation(int32_t x, int32_t y); 551 552 /** 553 * @brief 进入捕获模式 554 * @param windowId 窗口id. 555 * @return 进入捕获模式成功或失败. 556 * @since 9 557 */ 558 int32_t EnterCaptureMode(int32_t windowId); 559 560 /** 561 * @brief 退出捕获模式 562 * @param windowId 窗口id. 563 * @return 退出捕获模式成功或失败. 564 * @since 9 565 */ 566 int32_t LeaveCaptureMode(int32_t windowId); 567 568 int32_t GetWindowPid(int32_t windowId); 569 570 /** 571 * @brief pointer event添加辅助信息 572 * @param extraData 添加的信息. 573 * @return void 574 * @since 9 575 */ 576 void AppendExtraData(const ExtraData& extraData); 577 578 /** 579 * @brief 使能或者禁用输入设备 580 * @param enable 输入设备的使能状态 581 * @return 返回0表示接口调用成功,否则,表示接口调用失败。 582 * @since 9 583 */ 584 int32_t EnableInputDevice(bool enable); 585 586 /** 587 * @brief 自定义设置快捷键拉起ability延迟时间 588 * @param businessId 应用在ability_launch_config.json中注册的唯一标识符. 589 * @param delay 延迟时间 0-4000ms 590 * @return 设置快捷键拉起ability延迟时间成功或失败 591 * @since 10 592 */ 593 int32_t SetKeyDownDuration(const std::string &businessId, int32_t delay); 594 595 /** 596 * @brief Sets the keyboard repeat delay, which ranges from 300 to 1000. 597 * @param delay Indicates the keyboard repeat delay to set. 598 * @return Returns <b>RET_OK</b> if success; returns <b>RET_ERR</b> otherwise. 599 * @since 10 600 */ 601 int32_t SetKeyboardRepeatDelay(int32_t delay); 602 603 /** 604 * @brief Sets the keyboard repeat rate, which ranges from 36 to 100. 605 * @param rate Indicates the keyboard repeat rate to set. 606 * @return Returns <b>RET_OK</b> if success; returns <b>RET_ERR</b> otherwise. 607 * @since 10 608 */ 609 int32_t SetKeyboardRepeatRate(int32_t rate); 610 611 /** 612 * @brief Gets the keyboard repeat delay. 613 * @param callback Callback used to return the keyboard repeat delay. 614 * @return Returns <b>RET_OK</b> if success; returns <b>RET_ERR</b> otherwise. 615 * @since 10 616 */ 617 int32_t GetKeyboardRepeatDelay(std::function<void(int32_t)> callback); 618 619 /** 620 * @brief Gets the keyboard repeat rate. 621 * @param callback Callback used to return the keyboard repeat rate. 622 * @return Returns <b>RET_OK</b> if success; returns <b>RET_ERR</b> otherwise. 623 * @since 10 624 */ 625 int32_t GetKeyboardRepeatRate(std::function<void(int32_t)> callback); 626 627 /** 628 * @brief Set the switch of touchpad scroll. 629 * @param switchFlag Indicates the touchpad scroll switch state. 630 * @return if success; returns a non-0 value otherwise. 631 * @since 9 632 */ 633 int32_t SetTouchpadScrollSwitch(bool switchFlag); 634 635 /** 636 * @brief Get the switch of touchpad scroll. 637 * @param switchFlag Indicates the touchpad scroll switch state. 638 * @return if success; returns a non-0 value otherwise. 639 * @since 9 640 */ 641 int32_t GetTouchpadScrollSwitch(bool &switchFlag); 642 643 /** 644 * @brief Set the switch of touchpad scroll direction. 645 * @param state Indicates the touchpad scroll switch direction state. 646 * @return if success; returns a non-0 value otherwise. 647 * @since 9 648 */ 649 int32_t SetTouchpadScrollDirection(bool state); 650 651 /** 652 * @brief Get the switch of touchpad scroll direction. 653 * @param state Indicates the touchpad scroll switch direction state. 654 * @return if success; returns a non-0 value otherwise. 655 * @since 9 656 */ 657 int32_t GetTouchpadScrollDirection(bool &state); 658 659 /** 660 * @brief Set the switch of touchpad tap. 661 * @param switchFlag Indicates the touchpad tap switch state. 662 * @return if success; returns a non-0 value otherwise. 663 * @since 9 664 */ 665 int32_t SetTouchpadTapSwitch(bool switchFlag); 666 667 /** 668 * @brief Get the switch of touchpad tap. 669 * @param switchFlag Indicates the touchpad tap switch state. 670 * @return if success; returns a non-0 value otherwise. 671 * @since 9 672 */ 673 int32_t GetTouchpadTapSwitch(bool &switchFlag); 674 675 /** 676 * @brief Set the touchpad poniter speed. 677 * @param speed Indicates the touchpad pointer speed. 678 * @return if success; returns a non-0 value otherwise. 679 * @since 9 680 */ 681 int32_t SetTouchpadPointerSpeed(int32_t speed); 682 683 /** 684 * @brief Get the touchpad poniter speed. 685 * @param speed Indicates the touchpad pointer speed. 686 * @return if success; returns a non-0 value otherwise. 687 * @since 9 688 */ 689 int32_t GetTouchpadPointerSpeed(int32_t &speed); 690 691 /** 692 * @brief Set the switch of touchpad pinch. 693 * @param switchFlag Indicates the touchpad pinch switch state. 694 * @return if success; returns a non-0 value otherwise. 695 * @since 9 696 */ 697 int32_t SetTouchpadPinchSwitch(bool switchFlag); 698 699 /** 700 * @brief Get the switch of touchpad pinch. 701 * @param switchFlag Indicates the touchpad pinch switch state. 702 * @return if success; returns a non-0 value otherwise. 703 * @since 9 704 */ 705 int32_t GetTouchpadPinchSwitch(bool &switchFlag); 706 707 /** 708 * @brief Set the switch of touchpad swipe. 709 * @param switchFlag Indicates the touchpad swipe switch state. 710 * @return if success; returns a non-0 value otherwise. 711 * @since 9 712 */ 713 int32_t SetTouchpadSwipeSwitch(bool switchFlag); 714 715 /** 716 * @brief Get the switch of touchpad swipe. 717 * @param switchFlag Indicates the touchpad swipe switch state. 718 * @return if success; returns a non-0 value otherwise. 719 * @since 9 720 */ 721 int32_t GetTouchpadSwipeSwitch(bool &switchFlag); 722 723 /** 724 * @brief Set the touchpad right click type. 725 * @param type Indicates the touchpad right menu type. 726 * @return if success; returns a non-0 value otherwise. 727 * @since 9 728 */ 729 int32_t SetTouchpadRightClickType(int32_t type); 730 731 /** 732 * @brief Get the touchpad right click type. 733 * @param type Indicates the touchpad right menu type. 734 * @return if success; returns a non-0 value otherwise. 735 * @since 9 736 */ 737 int32_t GetTouchpadRightClickType(int32_t &type); 738 /** 739 * @brief SetWindowPointerStyle. 740 * @param area Indicates area. 741 * @param pid Indicates pid. 742 * @param windowId Indicates windowId. 743 * @return void. 744 * @since 9 745 */ 746 void SetWindowPointerStyle(WindowArea area, int32_t pid, int32_t windowId); 747 748 /** 749 * @brief Turn on or off hard cursor statistics. 750 * @param frameCount Counting the frame rate of continuous mouse movement. 751 * @param frameCount Statistics of mouse continuous movement synchronization frame rate. 752 * @return if success; returns a non-0 value otherwise. 753 * @since 12 754 */ 755 int32_t EnableHardwareCursorStats(bool enable); 756 /** 757 * @brief Get the mouse hard cursor information. 758 * @param frameCount Counting the frame rate of continuous mouse movement. 759 * @param frameCount Statistics of mouse continuous movement synchronization frame rate. 760 * @return if success; returns a non-0 value otherwise. 761 * @since 12 762 */ 763 int32_t GetHardwareCursorStats(uint32_t &frameCount, uint32_t &vsyncCount); 764 765 /** 766 * @brief Get the pointer snapshot. 767 * @param pixelMapPtr Indicates the image resource for this mouse icon. which realtype must be 768 * std::shared_ptr<OHOS::Media::PixelMap>*. 769 * @return if success; returns a non-0 value otherwise. 770 * @since 12 771 */ 772 int32_t GetPointerSnapshot(void *pixelMapPtr); 773 774 /** 775 * @brief ClearWindowPointerStyle. 776 * @param pid Indicates pid. 777 * @param windowId Indicates windowId. 778 * @return void. 779 * @since 9 780 */ 781 void ClearWindowPointerStyle(int32_t pid, int32_t windowId); 782 783 /** 784 * @brief Sets whether shield key event interception, only support shield key event. 785 * @param shieldMode Indicates shield mode. 786 * @param isShield Indicates whether key event handler chain is shield. The value <b>true</b> indicates that 787 * the key event build chain is shield, all key events derictly dispatch to window, 788 * if the value <b>false</b> indicates not shield key event interception, handle by the chain. 789 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 790 * @since 9 791 */ 792 int32_t SetShieldStatus(int32_t shieldMode, bool isShield); 793 794 /** 795 * Gets shield event interception status corresponding to shield mode 796 * 797 * @param shieldMode - Accroding the shield mode select shield status. 798 * @param isShield - shield status of shield mode param. 799 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 800 * @since 9 801 */ 802 int32_t GetShieldStatus(int32_t shieldMode, bool &isShield); 803 804 int32_t GetKeyState(std::vector<int32_t> &pressedKeys, std::map<int32_t, int32_t> &specialKeysState); 805 806 void Authorize(bool isAuthorize); 807 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT 808 /** 809 * @brief Sets the enhance config of the security component. 810 * @param cfg Indicates the security component enhance config. 811 * @param cfgLen Indicates the security component enhance config len. 812 * @return void. 813 * @since 9 814 */ 815 void SetEnhanceConfig(uint8_t *cfg, uint32_t cfgLen); 816 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT 817 818 #ifdef OHOS_BUILD_ENABLE_ANCO 819 void SimulateInputEventExt(std::shared_ptr<KeyEvent> keyEvent); 820 void SimulateInputEventExt(std::shared_ptr<PointerEvent> pointerEvent); 821 #endif // OHOS_BUILD_ENABLE_ANCO 822 823 void AddServiceWatcher(std::shared_ptr<IInputServiceWatcher> watcher); 824 void RemoveServiceWatcher(std::shared_ptr<IInputServiceWatcher> watcher); 825 826 int32_t MarkProcessed(int32_t eventId, int64_t actionTime, bool enable = true); 827 828 /** 829 * @brief Set the switch of touchpad rotate. 830 * @param rotateSwitch Indicates the touchpad rotate switch state. 831 * @return 0 if success; returns a non-0 value otherwise. 832 * @since 12 833 */ 834 int32_t SetTouchpadRotateSwitch(bool rotateSwitch); 835 836 /** 837 * @brief Get the switch of touchpad rotate. 838 * @param rotateSwitch Indicates the touchpad rotate switch state. 839 * @return 0 if success; returns a non-0 value otherwise. 840 * @since 12 841 */ 842 int32_t GetTouchpadRotateSwitch(bool &rotateSwitch); 843 844 /** 845 * @brief Set the switch of touchpad double tap and drag. 846 * @param switchFlag Indicates the touchpad double tap and drag switch state. 847 * true: user can use double tap and drag function. otherwise can't use 848 * @return if success; returns a non-0 value otherwise. 849 * @since 12 850 */ 851 int32_t SetTouchpadDoubleTapAndDragState(bool switchFlag); 852 853 /** 854 * @brief Get the switch of touchpad double tap and drag. 855 * @param switchFlag Indicates the touchpad double tap and drag switch state. 856 * true: user can use double tap and drag function. otherwise can't use 857 * @return if success; returns a non-0 value otherwise. 858 * @since 12 859 */ 860 int32_t GetTouchpadDoubleTapAndDragState(bool &switchFlag); 861 862 /** 863 * @brief Get whether System has IrEmitter. 864 * @param hasIrEmitter the para takes the value which Indicates the device has IrEmitter or not. 865 * @return 0 if success; returns a non-0 value otherwise. 866 * @since 12 867 */ 868 int32_t HasIrEmitter(bool &hasIrEmitter); 869 870 /** 871 * @brief Get InfraredFrequency of the IrEmitter in device. 872 * @param requencys take out the IrEmitter's Frequency. 873 * @return 0 if success; returns a non-0 value otherwise. 874 * @since 12 875 */ 876 int32_t GetInfraredFrequencies(std::vector<InfraredFrequency>& requencys); 877 878 /** 879 * @brief user IrEmitter with parameter number and pattern. 880 * @param number Frequency of IrEmitter works . 881 * @param pattern Pattern of signal transmission in alternate on/off mode, in microseconds. 882 * @return 0 if success; returns a non-0 value otherwise. 883 * @since 12 884 */ 885 int32_t TransmitInfrared(int64_t number, std::vector<int64_t>& pattern); 886 887 int32_t SetCurrentUser(int32_t userId); 888 889 int32_t GetWinSyncBatchSize(int32_t maxAreasCount, int32_t displayCount); 890 891 /** 892 * @brief 添加虚拟输入设备 893 * @param device 输入设备信息 894 * @param deviceId 出参,所创建的虚拟输入设备对应的设备Id 895 * @return 返回0表示接口调用成功,否则,表示接口调用失败。 896 * @since 12 897 */ 898 int32_t AddVirtualInputDevice(std::shared_ptr<InputDevice> device, int32_t &deviceId); 899 900 /** 901 * @brief 移除虚拟输入设备 902 * @param deviceId 要移除的虚拟输入设备对应的设备Id 903 * @return 返回0表示接口调用成功,否则,表示接口调用失败。 904 * @since 12 905 */ 906 int32_t RemoveVirtualInputDevice(int32_t deviceId); 907 908 int32_t AncoAddConsumer(std::shared_ptr<IAncoConsumer> consumer); 909 int32_t AncoRemoveConsumer(std::shared_ptr<IAncoConsumer> consumer); 910 911 int32_t SkipPointerLayer(bool isSkip); 912 int32_t RegisterWindowStateErrorCallback(std::function<void(int32_t, int32_t)> callback); 913 914 /** 915 * @brief Converted to a Capi-defined key action value. 916 * @param keyAction The key action value of the return value of inner api. 917 * @return Returns Capi-defined key action value if success; returns a negative number value otherwise. 918 * @since 13 919 */ 920 int32_t ConvertToCapiKeyAction(int32_t keyAction); 921 922 /** 923 * @brief Get Interval Since Last Input. 924 * @param timeInterval the value which Indicates the time interval since last input. 925 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 926 * @since 13 927 */ 928 int32_t GetIntervalSinceLastInput(int64_t &timeInterval); 929 private: 930 InputManager() = default; 931 DISALLOW_COPY_AND_MOVE(InputManager); 932 static InputManager *instance_; 933 }; 934 } // namespace MMI 935 } // namespace OHOS 936 #endif // INPUT_MANAGER_H 937