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