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 44namespace OHOS { 45namespace MMI { 46class InputManager { 47public: 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 int32_t SubscribeHotkey(std::shared_ptr<KeyOption> keyOption, 149 std::function<void(std::shared_ptr<KeyEvent>)> callback); 150 void UnsubscribeHotkey(int32_t subscriberId); 151 152 /** 153 * @brief Subscribes to the switch input event that meets a specific condition. When such an event occurs, 154 * the <b>callback</b> specified is invoked to process the event. 155 * @param callback Indicates the callback. 156 * @param switchType Indicates the type of switch input event. 157 * @return Returns the subscription ID, which uniquely identifies a subscription in the process. 158 * If the value is greater than or equal to <b>0</b>, 159 * the subscription is successful. Otherwise, the subscription fails. 160 * @since 9 161 */ 162 int32_t SubscribeSwitchEvent(std::function<void(std::shared_ptr<SwitchEvent>)> callback, 163 SwitchEvent::SwitchType switchType = SwitchEvent::SwitchType::SWITCH_DEFAULT); 164 165 /** 166 * @brief Unsubscribes from a switch input event. 167 * @param subscriberId Indicates the subscription ID, which is the return value of <b>SubscribeKeyEvent</b>. 168 * @return void 169 * @since 9 170 */ 171 void UnsubscribeSwitchEvent(int32_t subscriberId); 172 173 /** 174 * @brief Adds an input event monitor. After such a monitor is added, 175 * an input event is copied and distributed to the monitor while being distributed to the original target. 176 * @param monitor Indicates the input event monitor. After an input event is generated, 177 * the functions of the monitor object will be called. 178 * @return Returns the monitor ID, which uniquely identifies a monitor in the process. 179 * If the value is greater than or equal to <b>0</b>, the monitor is successfully added. Otherwise, 180 * the monitor fails to be added. 181 * @since 9 182 */ 183 int32_t AddMonitor(std::function<void(std::shared_ptr<KeyEvent>)> monitor); 184 185 /** 186 * @brief Adds an input event monitor. After such a monitor is added, 187 * an input event is copied and distributed to the monitor while being distributed to the original target. 188 * @param monitor Indicates the input event monitor. After an input event is generated, 189 * the functions of the monitor object will be called. 190 * @return Returns the monitor ID, which uniquely identifies a monitor in the process. 191 * If the value is greater than or equal to <b>0</b>, the monitor is successfully added. Otherwise, 192 * the monitor fails to be added. 193 * @since 9 194 */ 195 int32_t AddMonitor(std::function<void(std::shared_ptr<PointerEvent>)> monitor); 196 197 /** 198 * @brief Adds an input event monitor. After such a monitor is added, 199 * an input event is copied and distributed to the monitor while being distributed to the original target. 200 * @param monitor Indicates the input event monitor. After an input event is generated, 201 * the functions of the monitor object will be called. 202 * @param eventType Indicates the eventType for monitor. 203 * @return Returns the monitor ID, which uniquely identifies a monitor in the process. 204 * If the value is greater than or equal to <b>0</b>, the monitor is successfully added. Otherwise, 205 * the monitor fails to be added. 206 * @since 9 207 */ 208 int32_t AddMonitor(std::shared_ptr<IInputEventConsumer> monitor, HandleEventType eventType = HANDLE_EVENT_TYPE_KP); 209 /** 210 * @brief Adds an input event monitor. After such a monitor is added, 211 * an input event is copied and distributed to the monitor while being distributed to the original target. 212 * @param monitor Indicates the input event monitor. After an input event is generated, 213 * the functions of the monitor object will be called. 214 * @param actionsType Indicates the actionsType for monitor. 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::shared_ptr<IInputEventConsumer> monitor, std::vector<int32_t> actionsType); 221 222 /** 223 * @brief Removes a monitor. 224 * @param monitorId Indicates the monitor ID, which is the return value of <b>AddMonitor</b>. 225 * @return void 226 * @since 9 227 */ 228 void RemoveMonitor(int32_t monitorId); 229 230 /** 231 * @brief Marks that a monitor has consumed a touchscreen input event. After being consumed, 232 * the touchscreen input event will not be distributed to the original target. 233 * @param monitorId Indicates the monitor ID. 234 * @param eventId Indicates the ID of the consumed touchscreen input event. 235 * @return void 236 * @since 9 237 */ 238 void MarkConsumed(int32_t monitorId, int32_t eventId); 239 240 /** 241 * @brief Moves the cursor to the specified position. 242 * @param offsetX Indicates the offset on the X axis. 243 * @param offsetY Indicates the offset on the Y axis. 244 * @return void 245 * @since 9 246 */ 247 void MoveMouse(int32_t offsetX, int32_t offsetY); 248 249 /** 250 * @brief Adds an input event interceptor. After such an interceptor is added, 251 * an input event will be distributed to the interceptor instead of the original target and monitor. 252 * @param interceptor Indicates the input event interceptor. After an input event is generated, 253 * the functions of the interceptor object will be called. 254 * @return Returns the interceptor ID, which uniquely identifies an interceptor in the process. 255 * If the value is greater than or equal to <b>0</b>,the interceptor is successfully added. Otherwise, 256 * the interceptor fails to be added. 257 * @since 9 258 */ 259 int32_t AddInterceptor(std::shared_ptr<IInputEventConsumer> interceptor); 260 int32_t AddInterceptor(std::function<void(std::shared_ptr<KeyEvent>)> interceptor); 261 int32_t AddInterceptor(std::shared_ptr<IInputEventConsumer> interceptor, int32_t priority, uint32_t deviceTags); 262 263 /** 264 * @brief Removes an interceptor. 265 * @param interceptorId Indicates the interceptor ID, which is the return value of <b>AddInterceptor</b>. 266 * @return void 267 * @since 9 268 */ 269 void RemoveInterceptor(int32_t interceptorId); 270 271 /** 272 * @brief Simulates a key input event. This event will be distributed and 273 * processed in the same way as the event reported by the input device. 274 * @param keyEvent Indicates the key input event to simulate. 275 * @return void 276 * @since 9 277 */ 278 void SimulateInputEvent(std::shared_ptr<KeyEvent> keyEvent); 279 280 /** 281 * @brief Simulates a touchpad input event, touchscreen input event, or mouse device input event. 282 * This event will be distributed and processed in the same way as the event reported by the input device. 283 * @param pointerEvent Indicates the touchpad input event, touchscreen input event, 284 * or mouse device input event to simulate. 285 * @return void 286 * @since 9 287 */ 288 void SimulateInputEvent(std::shared_ptr<PointerEvent> pointerEvent); 289 290 /** 291 * @brief Simulates a touchpad input event, touchscreen input event, or mouse device input event. 292 * This event will be distributed and processed in the same way as the event reported by the input device. 293 * @param pointerEvent Indicates the touchpad input event, touchscreen input event, 294 * or mouse device input event to simulate. 295 * @param zOrder Indicates the point event will inject to the window whose index value is less than the zOrder 296 * @return void 297 * @since 9 298 */ 299 void SimulateInputEvent(std::shared_ptr<PointerEvent> pointerEvent, float zOrder); 300 301 /** 302 * @brief Simulates a touchpad input event. 303 * because some event for touchpad is very different from other input, 304 * especially pointer.id must be same as actual data 0, 1, 2. 305 * @param pointerEvent Indicates the touchpad input event. 306 * @return void 307 * @since 12 308 */ 309 void SimulateTouchPadEvent(std::shared_ptr<PointerEvent> pointerEvent); 310 311 /** 312 * @brief Starts listening for an input device event. 313 * @param type Indicates the type of the input device event, which is <b>change</b>. 314 * @param listener Indicates the listener for the input device event. 315 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 316 * @since 9 317 */ 318 int32_t RegisterDevListener(std::string type, std::shared_ptr<IInputDeviceListener> listener); 319 320 /** 321 * @brief Stops listening for an input device event. 322 * @param type Indicates the type of the input device event, which is <b>change</b>. 323 * @param listener Indicates the listener for the input device event. 324 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 325 * @since 9 326 */ 327 int32_t UnregisterDevListener(std::string type, std::shared_ptr<IInputDeviceListener> listener = nullptr); 328 329 /** 330 * @brief Obtains the information about an input device. 331 * @param callback Indicates the callback used to receive the reported data. 332 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 333 * @since 9 334 */ 335 int32_t GetDeviceIds(std::function<void(std::vector<int32_t>&)> callback); 336 337 /** 338 * @brief Obtains the information about an input device. 339 * @param deviceId Indicates the ID of the input device whose information is to be obtained. 340 * @param callback Indicates the callback used to receive the reported data. 341 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 342 * @since 9 343 */ 344 int32_t GetDevice(int32_t deviceId, std::function<void(std::shared_ptr<InputDevice>)> callback); 345 346 /** 347 * @brief Checks whether the specified key codes of an input device are supported. 348 * @param deviceId Indicates the ID of the input device. 349 * @param keyCodes Indicates the key codes of the input device. 350 * @param callback Indicates the callback used to receive the reported data. 351 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 352 * @since 9 353 */ 354 int32_t SupportKeys(int32_t deviceId, std::vector<int32_t> keyCodes, 355 std::function<void(std::vector<bool>&)> callback); 356 357 /** 358 * @brief Sets the number of the mouse scrolling rows. 359 * @param rows Indicates the number of the mouse scrolling rows. 360 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 361 * @since 9 362 */ 363 int32_t SetMouseScrollRows(int32_t rows); 364 365 /** 366 * @brief Set pixelMap to override ohos mouse icon resouce. 367 * @param windowId Indicates the windowId of the window 368 * @param pixelMap Indicates the image resouce for this mouse icon. which realtype must be OHOS::Media::PixelMap* 369 * @param focusX Indicates focus x 370 * @param focusY Indicates focus y 371 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 372 * @since 9 373 */ 374 int32_t SetCustomCursor(int32_t windowId, void* pixelMap, int32_t focusX = 0, int32_t focusY = 0); 375 376 /** 377 * @brief Set pixelMap to override ohos mouse icon resouce. 378 * @param windowId Indicates the windowId of the window 379 * @param pixelMap Indicates the image resouce for this mouse icon. which realtype must be OHOS::Media::PixelMap* 380 * @return vint32_t 381 * @since 10 382 */ 383 int32_t SetMouseIcon(int32_t windowId, void* pixelMap); 384 385 /** 386 * @brief Set mouse icon hot spot. 387 * @param windowId Indicates the windowId of the window 388 * @param hotSpotX Indicates the hot spot x for this mouse icon. 389 * @param hotSpotY Indicates the hot spot y for this mouse icon. 390 * @return vint32_t 391 * @since 10 392 */ 393 int32_t SetMouseHotSpot(int32_t windowId, int32_t hotSpotX, int32_t hotSpotY); 394 395 /** 396 * @brief Gets the number of the mouse scrolling rows. 397 * @param rows Indicates the number of the mouse scrolling rows. 398 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 399 * @since 9 400 */ 401 int32_t GetMouseScrollRows(int32_t &rows); 402 403 /** 404 * @brief Sets pointer size. 405 * @param size Indicates pointer size. 406 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 407 * @since 9 408 */ 409 int32_t SetPointerSize(int32_t size); 410 411 /** 412 * @brief Gets pointer size. 413 * @param size Indicates pointer size. 414 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 415 * @since 9 416 */ 417 int32_t GetPointerSize(int32_t &size); 418 419 /** 420 * @brief Enable combine key 421 * @param enable Indicates whether the combine key is enabled. The value true indicates that the combine key 422 * is enabled, and the value false indicates the opposite. 423 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 424 * @since 11 425 */ 426 int32_t EnableCombineKey(bool enable); 427 428 /** 429 * @brief Sets mouse primary button. 430 * @param primaryButton Indicates the ID of the mouse primary button.The value 0 indicates that 431 * the primary button is left button.The value 1 indicates that the primary button is right button. 432 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 433 * @since 9 434 */ 435 int32_t SetMousePrimaryButton(int32_t primaryButton); 436 437 /** 438 * @brief Gets mouse primary button. 439 * @param primaryButton Indicates the ID of the mouse primary button.The value 0 indicates that 440 * the primary button is left button.The value 1 indicates that the primary button is right button. 441 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 442 * @since 9 443 */ 444 int32_t GetMousePrimaryButton(int32_t &primaryButton); 445 446 /** 447 * @brief Sets whether the mouse hover scroll is enabled in inactive window. 448 * @param state Indicates whether the mouse hover scroll is enabled in inactive window. The value true 449 * indicates that the mouse hover scroll is enabled, and the value false indicates the opposite. 450 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 451 * @since 9 452 */ 453 int32_t SetHoverScrollState(bool state); 454 455 /** 456 * @brief Gets a status whether the mouse hover scroll is enabled in inactive window. 457 * @param state Indicates whether the mouse hover scroll is enabled in inactive window. The value true 458 * indicates that the mouse hover scroll is enabled, and the value false indicates the opposite. 459 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 460 * @since 9 461 */ 462 int32_t GetHoverScrollState(bool &state); 463 464 /** 465 * @brief Sets whether the pointer icon is visible. 466 * @param visible Indicates whether the pointer icon is visible. The value <b>true</b> indicates that 467 * the pointer icon is visible, and the value <b>false</b> indicates the opposite. 468 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 469 * @since 9 470 */ 471 int32_t SetPointerVisible(bool visible, int32_t priority = 0); 472 473 /** 474 * @brief Checks whether the pointer icon is visible. 475 * @return Returns <b>true</b> if the pointer icon is visible; returns <b>false</b> otherwise. 476 * @since 9 477 */ 478 bool IsPointerVisible(); 479 480 /** 481 * @brief Sets the mouse pointer style. 482 * @param windowId Indicates the ID of the window for which the mouse pointer style is set. 483 * @param pointerStyle Indicates the ID of the mouse pointer style. 484 * @return Returns <b>0</b> if the operation is successful; returns an error code otherwise. 485 * @since 9 486 */ 487 int32_t SetPointerStyle(int32_t windowId, PointerStyle pointerStyle, bool isUiExtension = false); 488 489 /** 490 * @brief Obtains the mouse pointer style. 491 * @param windowId Indicates the ID of the window for which the mouse pointer style is obtained. 492 * @param pointerStyle Indicates the ID of the mouse pointer style. 493 * @return Returns <b>0</b> if the operation is successful; returns an error code otherwise. 494 * @since 9 495 */ 496 int32_t GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle, bool isUiExtension = false); 497 498 /** 499 * @brief Sets pointer color. 500 * @param color Indicates pointer color. 501 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 502 * @since 9 503 */ 504 int32_t SetPointerColor(int32_t color); 505 506 /** 507 * @brief Gets pointer color. 508 * @param color Indicates pointer color. 509 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 510 * @since 9 511 */ 512 int32_t GetPointerColor(int32_t &color); 513 514 /** 515 * @brief Sets the mouse pointer speed, which ranges from 1 to 11. 516 * @param speed Indicates the mouse pointer speed to set. 517 * @return Returns <b>RET_OK</b> if success; returns <b>RET_ERR</b> otherwise. 518 * @since 9 519 */ 520 int32_t SetPointerSpeed(int32_t speed); 521 522 /** 523 * @brief Obtains the mouse pointer speed. 524 * @param speed Indicates the mouse pointer speed to get. 525 * @return Returns the mouse pointer speed if the operation is successful; returns <b>RET_ERR</b> otherwise. 526 * @since 9 527 */ 528 int32_t GetPointerSpeed(int32_t &speed); 529 530 /** 531 * @brief Queries the keyboard type. 532 * @param deviceId Indicates the keyboard device ID. 533 * @param callback Callback used to return the keyboard type. 534 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 535 * @since 9 536 */ 537 int32_t GetKeyboardType(int32_t deviceId, std::function<void(int32_t)> callback); 538 539 /** 540 * @brief Sets the observer for events indicating that the application does not respond. 541 * @param observer Indicates the observer for events indicating that the application does not respond. 542 * @return void 543 * @since 9 544 */ 545 void SetAnrObserver(std::shared_ptr<IAnrObserver> observer); 546 547 /** 548 * @brief Obtains the enablement status of the specified function key on the keyboard. 549 * @param funcKey Indicates the function key. Currently, the following function keys are supported: 550 * NUM_LOCK_FUNCTION_KEY 551 * CAPS_LOCK_FUNCTION_KEY 552 * SCROLL_LOCK_FUNCTION_KEY 553 * @return Returns <b>true</b> if the function key is enabled; 554 * returns <b>false</b> otherwise. 555 */ 556 bool GetFunctionKeyState(int32_t funcKey); 557 558 /** 559 * @brief Sets the enablement status of the specified function key on the keyboard. 560 * @param funcKey Indicates the function key. Currently, the following function keys are supported: 561 * NUM_LOCK_FUNCTION_KEY 562 * CAPS_LOCK_FUNCTION_KEY 563 * SCROLL_LOCK_FUNCTION_KEY 564 * @param isEnable Indicates the enablement status to set. 565 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 566 */ 567 int32_t SetFunctionKeyState(int32_t funcKey, bool enable); 568 569 /** 570 * @brief Sets the absolute coordinate of mouse. 571 * @param x Specifies the x coordinate of the mouse to be set. 572 * @param y Specifies the y coordinate of the mouse to be set. 573 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 574 * @since 9 575 */ 576 int32_t SetPointerLocation(int32_t x, int32_t y); 577 578 /** 579 * @brief 进入捕获模式 580 * @param windowId 窗口id. 581 * @return 进入捕获模式成功或失败. 582 * @since 9 583 */ 584 int32_t EnterCaptureMode(int32_t windowId); 585 586 /** 587 * @brief 退出捕获模式 588 * @param windowId 窗口id. 589 * @return 退出捕获模式成功或失败. 590 * @since 9 591 */ 592 int32_t LeaveCaptureMode(int32_t windowId); 593 594 int32_t GetWindowPid(int32_t windowId); 595 596 /** 597 * @brief pointer event添加辅助信息 598 * @param extraData 添加的信息. 599 * @return void 600 * @since 9 601 */ 602 void AppendExtraData(const ExtraData& extraData); 603 604 /** 605 * @brief 使能或者禁用输入设备 606 * @param enable 输入设备的使能状态 607 * @return 返回0表示接口调用成功,否则,表示接口调用失败。 608 * @since 9 609 */ 610 int32_t EnableInputDevice(bool enable); 611 612 /** 613 * @brief 自定义设置快捷键拉起ability延迟时间 614 * @param businessId 应用在ability_launch_config.json中注册的唯一标识符. 615 * @param delay 延迟时间 0-4000ms 616 * @return 设置快捷键拉起ability延迟时间成功或失败 617 * @since 10 618 */ 619 int32_t SetKeyDownDuration(const std::string &businessId, int32_t delay); 620 621 /** 622 * @brief Sets the keyboard repeat delay, which ranges from 300 to 1000. 623 * @param delay Indicates the keyboard repeat delay to set. 624 * @return Returns <b>RET_OK</b> if success; returns <b>RET_ERR</b> otherwise. 625 * @since 10 626 */ 627 int32_t SetKeyboardRepeatDelay(int32_t delay); 628 629 /** 630 * @brief Sets the keyboard repeat rate, which ranges from 36 to 100. 631 * @param rate Indicates the keyboard repeat rate to set. 632 * @return Returns <b>RET_OK</b> if success; returns <b>RET_ERR</b> otherwise. 633 * @since 10 634 */ 635 int32_t SetKeyboardRepeatRate(int32_t rate); 636 637 /** 638 * @brief Gets the keyboard repeat delay. 639 * @param callback Callback used to return the keyboard repeat delay. 640 * @return Returns <b>RET_OK</b> if success; returns <b>RET_ERR</b> otherwise. 641 * @since 10 642 */ 643 int32_t GetKeyboardRepeatDelay(std::function<void(int32_t)> callback); 644 645 /** 646 * @brief Gets the keyboard repeat rate. 647 * @param callback Callback used to return the keyboard repeat rate. 648 * @return Returns <b>RET_OK</b> if success; returns <b>RET_ERR</b> otherwise. 649 * @since 10 650 */ 651 int32_t GetKeyboardRepeatRate(std::function<void(int32_t)> callback); 652 653 /** 654 * @brief Set the switch of touchpad scroll. 655 * @param switchFlag Indicates the touchpad scroll switch state. 656 * @return if success; returns a non-0 value otherwise. 657 * @since 9 658 */ 659 int32_t SetTouchpadScrollSwitch(bool switchFlag); 660 661 /** 662 * @brief Get the switch of touchpad scroll. 663 * @param switchFlag Indicates the touchpad scroll switch state. 664 * @return if success; returns a non-0 value otherwise. 665 * @since 9 666 */ 667 int32_t GetTouchpadScrollSwitch(bool &switchFlag); 668 669 /** 670 * @brief Set the switch of touchpad scroll direction. 671 * @param state Indicates the touchpad scroll switch direction state. 672 * @return if success; returns a non-0 value otherwise. 673 * @since 9 674 */ 675 int32_t SetTouchpadScrollDirection(bool state); 676 677 /** 678 * @brief Get the switch of touchpad scroll direction. 679 * @param state Indicates the touchpad scroll switch direction state. 680 * @return if success; returns a non-0 value otherwise. 681 * @since 9 682 */ 683 int32_t GetTouchpadScrollDirection(bool &state); 684 685 /** 686 * @brief Set the switch of touchpad tap. 687 * @param switchFlag Indicates the touchpad tap switch state. 688 * @return if success; returns a non-0 value otherwise. 689 * @since 9 690 */ 691 int32_t SetTouchpadTapSwitch(bool switchFlag); 692 693 /** 694 * @brief Get the switch of touchpad tap. 695 * @param switchFlag Indicates the touchpad tap switch state. 696 * @return if success; returns a non-0 value otherwise. 697 * @since 9 698 */ 699 int32_t GetTouchpadTapSwitch(bool &switchFlag); 700 701 /** 702 * @brief Set the touchpad poniter speed. 703 * @param speed Indicates the touchpad pointer speed. 704 * @return if success; returns a non-0 value otherwise. 705 * @since 9 706 */ 707 int32_t SetTouchpadPointerSpeed(int32_t speed); 708 709 /** 710 * @brief Get the touchpad poniter speed. 711 * @param speed Indicates the touchpad pointer speed. 712 * @return if success; returns a non-0 value otherwise. 713 * @since 9 714 */ 715 int32_t GetTouchpadPointerSpeed(int32_t &speed); 716 717 /** 718 * @brief Set the switch of touchpad pinch. 719 * @param switchFlag Indicates the touchpad pinch switch state. 720 * @return if success; returns a non-0 value otherwise. 721 * @since 9 722 */ 723 int32_t SetTouchpadPinchSwitch(bool switchFlag); 724 725 /** 726 * @brief Get the switch of touchpad pinch. 727 * @param switchFlag Indicates the touchpad pinch switch state. 728 * @return if success; returns a non-0 value otherwise. 729 * @since 9 730 */ 731 int32_t GetTouchpadPinchSwitch(bool &switchFlag); 732 733 /** 734 * @brief Set the switch of touchpad swipe. 735 * @param switchFlag Indicates the touchpad swipe switch state. 736 * @return if success; returns a non-0 value otherwise. 737 * @since 9 738 */ 739 int32_t SetTouchpadSwipeSwitch(bool switchFlag); 740 741 /** 742 * @brief Get the switch of touchpad swipe. 743 * @param switchFlag Indicates the touchpad swipe switch state. 744 * @return if success; returns a non-0 value otherwise. 745 * @since 9 746 */ 747 int32_t GetTouchpadSwipeSwitch(bool &switchFlag); 748 749 /** 750 * @brief Set the touchpad right click type. 751 * @param type Indicates the touchpad right menu type. 752 * @return if success; returns a non-0 value otherwise. 753 * @since 9 754 */ 755 int32_t SetTouchpadRightClickType(int32_t type); 756 757 /** 758 * @brief Get the touchpad right click type. 759 * @param type Indicates the touchpad right menu type. 760 * @return if success; returns a non-0 value otherwise. 761 * @since 9 762 */ 763 int32_t GetTouchpadRightClickType(int32_t &type); 764 /** 765 * @brief SetWindowPointerStyle. 766 * @param area Indicates area. 767 * @param pid Indicates pid. 768 * @param windowId Indicates windowId. 769 * @return void. 770 * @since 9 771 */ 772 void SetWindowPointerStyle(WindowArea area, int32_t pid, int32_t windowId); 773 774 /** 775 * @brief Turn on or off hard cursor statistics. 776 * @param frameCount Counting the frame rate of continuous mouse movement. 777 * @param frameCount Statistics of mouse continuous movement synchronization frame rate. 778 * @return if success; returns a non-0 value otherwise. 779 * @since 12 780 */ 781 int32_t EnableHardwareCursorStats(bool enable); 782 /** 783 * @brief Get the mouse hard cursor information. 784 * @param frameCount Counting the frame rate of continuous mouse movement. 785 * @param frameCount Statistics of mouse continuous movement synchronization frame rate. 786 * @return if success; returns a non-0 value otherwise. 787 * @since 12 788 */ 789 int32_t GetHardwareCursorStats(uint32_t &frameCount, uint32_t &vsyncCount); 790 791 /** 792 * @brief Get the pointer snapshot. 793 * @param pixelMapPtr Indicates the image resource for this mouse icon. which realtype must be 794 * std::shared_ptr<OHOS::Media::PixelMap>*. 795 * @return if success; returns a non-0 value otherwise. 796 * @since 12 797 */ 798 int32_t GetPointerSnapshot(void *pixelMapPtr); 799 800 /** 801 * @brief Sets the number of the touchpad scrolling rows. 802 * @param rows Indicates the number of the touchpad scrolling rows. 803 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 804 * @since 12 805 */ 806 int32_t SetTouchpadScrollRows(int32_t rows); 807 808 /** 809 * @brief Gets the number of the touchpad scrolling rows. 810 * @param rows Indicates the number of the touchpad scrolling rows. 811 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 812 * @since 12 813 */ 814 int32_t GetTouchpadScrollRows(int32_t &rows); 815 816 /** 817 * @brief ClearWindowPointerStyle. 818 * @param pid Indicates pid. 819 * @param windowId Indicates windowId. 820 * @return void. 821 * @since 9 822 */ 823 void ClearWindowPointerStyle(int32_t pid, int32_t windowId); 824 825 /** 826 * @brief Sets whether shield key event interception, only support shield key event. 827 * @param shieldMode Indicates shield mode. 828 * @param isShield Indicates whether key event handler chain is shield. The value <b>true</b> indicates that 829 * the key event build chain is shield, all key events derictly dispatch to window, 830 * if the value <b>false</b> indicates not shield key event interception, handle by the chain. 831 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 832 * @since 9 833 */ 834 int32_t SetShieldStatus(int32_t shieldMode, bool isShield); 835 836 /** 837 * Gets shield event interception status corresponding to shield mode 838 * 839 * @param shieldMode - Accroding the shield mode select shield status. 840 * @param isShield - shield status of shield mode param. 841 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 842 * @since 9 843 */ 844 int32_t GetShieldStatus(int32_t shieldMode, bool &isShield); 845 846 int32_t MarkProcessed(int32_t eventId, int64_t actionTime, bool enable = true); 847 848 int32_t GetKeyState(std::vector<int32_t> &pressedKeys, std::map<int32_t, int32_t> &specialKeysState); 849 850 void Authorize(bool isAuthorize); 851#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT 852 /** 853 * @brief Sets the enhance config of the security component. 854 * @param cfg Indicates the security component enhance config. 855 * @param cfgLen Indicates the security component enhance config len. 856 * @return void. 857 * @since 9 858 */ 859 void SetEnhanceConfig(uint8_t *cfg, uint32_t cfgLen); 860#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT 861 862#ifdef OHOS_BUILD_ENABLE_ANCO 863 void SimulateInputEventExt(std::shared_ptr<KeyEvent> keyEvent); 864 void SimulateInputEventExt(std::shared_ptr<PointerEvent> pointerEvent); 865#endif // OHOS_BUILD_ENABLE_ANCO 866 867 void AddServiceWatcher(std::shared_ptr<IInputServiceWatcher> watcher); 868 void RemoveServiceWatcher(std::shared_ptr<IInputServiceWatcher> watcher); 869 870 /** 871 * @brief Set the switch of touchpad rotate. 872 * @param rotateSwitch Indicates the touchpad rotate switch state. 873 * @return 0 if success; returns a non-0 value otherwise. 874 * @since 11 875 */ 876 int32_t SetTouchpadRotateSwitch(bool rotateSwitch); 877 878 /** 879 * @brief Get the switch of touchpad rotate. 880 * @param rotateSwitch Indicates the touchpad rotate switch state. 881 * @return 0 if success; returns a non-0 value otherwise. 882 * @since 11 883 */ 884 int32_t GetTouchpadRotateSwitch(bool &rotateSwitch); 885 886 /** 887 * @brief Set touch move event filters. 888 * @param flag if set move event filters or not. 889 * @return if success; returns a non-0 value otherwise. 890 * @since 12 891 */ 892 int32_t SetMoveEventFilters(bool flag); 893 894 /** 895 * @brief Get whether System has IrEmitter. 896 * @param hasIrEmitter the para takes the value which Indicates the device has IrEmitter or not. 897 * @return 0 if success; returns a non-0 value otherwise. 898 * @since 12 899 */ 900 int32_t HasIrEmitter(bool &hasIrEmitter); 901 902 /** 903 * @brief Get InfraredFrequency of the IrEmitter in device. 904 * @param requencys take out the IrEmitter's Frequency. 905 * @return 0 if success; returns a non-0 value otherwise. 906 * @since 12 907 */ 908 int32_t GetInfraredFrequencies(std::vector<InfraredFrequency>& requencys); 909 910 /** 911 * @brief user IrEmitter with parameter number and pattern. 912 * @param number Frequency of IrEmitter works . 913 * @param pattern Pattern of signal transmission in alternate on/off mode, in microseconds. 914 * @return 0 if success; returns a non-0 value otherwise. 915 * @since 12 916 */ 917 int32_t TransmitInfrared(int64_t number, std::vector<int64_t>& pattern); 918 919#ifdef OHOS_BUILD_ENABLE_VKEYBOARD 920 int32_t SetVKeyboardArea(double topLeftX, double topLeftY, double bottomRightX, double bottomRightY); 921 922 /** 923 * @brief Sets virtual keyboard motion space. 924 * @param keyName The key name of the virtual keyboard button to be updated. 925 * @param useShift Indicates if the key code injection needs to combine with shift key code. 926 * @param pattern Pattern is an ordered list that contains x, y, width, height, keyCode, 927 * motionSpaceTypeId and pageTypeId of the virtual keyboard button. 928 * @return 0 if success; returns a non-0 value otherwise. 929 * @since 13 930 */ 931 int32_t SetMotionSpace(std::string& keyName, bool useShift, std::vector<int32_t>& pattern); 932#endif // OHOS_BUILD_ENABLE_VKEYBOARD 933 934 int32_t SetCurrentUser(int32_t userId); 935 936 /** 937 * @brief Set the switch of touchpad three finger tap. 938 * @param switchFlag Indicates the touchpad three finger tap switch state. 939 * true: user can use three finger function. otherwise can't use 940 * @return if success; returns a non-0 value otherwise. 941 * @since 12 942 */ 943 int32_t SetTouchpadThreeFingersTapSwitch(bool switchFlag); 944 945 /** 946 * @brief Get the switch of touchpad three finger tap. 947 * @param switchFlag Indicates the touchpad three finger tap switch state. 948 * true: user can use three finger function. otherwise can't use 949 * @return if success; returns a non-0 value otherwise. 950 * @since 12 951 */ 952 int32_t GetTouchpadThreeFingersTapSwitch(bool &switchFlag); 953 954 int32_t GetWinSyncBatchSize(int32_t maxAreasCount, int32_t displayCount); 955 956 /** 957 * @brief 添加虚拟输入设备 958 * @param device 输入设备信息 959 * @param deviceId 出参,所创建的虚拟输入设备对应的设备Id 960 * @return 返回0表示接口调用成功,否则,表示接口调用失败。 961 * @since 12 962 */ 963 int32_t AddVirtualInputDevice(std::shared_ptr<InputDevice> device, int32_t &deviceId); 964 965 /** 966 * @brief 移除虚拟输入设备 967 * @param deviceId 要移除的虚拟输入设备对应的设备Id 968 * @return 返回0表示接口调用成功,否则,表示接口调用失败。 969 * @since 12 970 */ 971 int32_t RemoveVirtualInputDevice(int32_t deviceId); 972 973 int32_t AncoAddConsumer(std::shared_ptr<IAncoConsumer> consumer); 974 int32_t AncoRemoveConsumer(std::shared_ptr<IAncoConsumer> consumer); 975 976 int32_t SkipPointerLayer(bool isSkip); 977 978 int32_t RegisterWindowStateErrorCallback(std::function<void(int32_t, int32_t)> callback); 979 /** 980 * @brief Get Interval Since Last Input. 981 * @param timeInterval the value which Indicates the time interval since last input. 982 * @return Returns <b>0</b> if success; returns a non-0 value otherwise. 983 * @since 13 984 */ 985 int32_t GetIntervalSinceLastInput(int64_t &timeInterval); 986 987 int32_t GetAllSystemHotkeys(std::vector<std::unique_ptr<KeyOption>> &keyOptions, int32_t &count); 988 989 /** 990 * @brief Converted to a Capi-defined key action value. 991 * @param keyAction The key action value of the return value of inner api. 992 * @return Returns Capi-defined key action value if success; returns a negative number value otherwise. 993 * @since 13 994 */ 995 int32_t ConvertToCapiKeyAction(int32_t keyAction); 996 997 /** 998 * @brief 添加手势事件监视器。添加这样的监视器后,手势事件会被分发到到监视器。 999 * @param consumer 表示手势事件监视器。手势事件产生后,将调用监视器对象的函数。 1000 * @param type 表示监视的手势类型。 1001 * @param fingers 表示监视的手势达成的手指数量。 1002 * @return 返回监视器ID,该ID唯一标识进程中的监视器。如果value的值大于等于0,表示添加成功。否则,添加监视器失败。 1003 * @since 13 1004 */ 1005 int32_t AddGestureMonitor(std::shared_ptr<IInputEventConsumer> consumer, 1006 TouchGestureType type, int32_t fingers = 0); 1007 1008 /** 1009 * @brief 删除一个手势监听器。 1010 * @param monitorId 表示手势事件监视器ID,即AddGestureMonitor的返回值。 1011 * @return 如果成功,则返回0;否则返回非0值。 1012 * @since 13 1013 */ 1014 int32_t RemoveGestureMonitor(int32_t monitorId); 1015 1016private: 1017 InputManager() = default; 1018 DISALLOW_COPY_AND_MOVE(InputManager); 1019 static InputManager *instance_; 1020}; 1021} // namespace MMI 1022} // namespace OHOS 1023#endif // INPUT_MANAGER_H 1024