1 /* 2 * Copyright (c) 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 OH_INPUT_MANAGER_H 17 #define OH_INPUT_MANAGER_H 18 19 /** 20 * @addtogroup input 21 * @{ 22 * 23 * @brief Provides the C interface in the multi-modal input domain. 24 * 25 * @since 12 26 */ 27 28 /** 29 * @file oh_input_manager.h 30 * 31 * @brief Provides capabilities such as event injection and key status query. 32 * 33 * @syscap SystemCapability.MultimodalInput.Input.Core 34 * @library liboh_input.so 35 * @since 12 36 */ 37 38 #include <stdint.h> 39 40 #include "oh_axis_type.h" 41 #include "oh_key_code.h" 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 /** 48 * @brief Enumerated values of key event action. 49 * 50 * @since 12 51 */ 52 typedef enum Input_KeyStateAction { 53 /** Default */ 54 KEY_DEFAULT = -1, 55 /** Pressing of a key */ 56 KEY_PRESSED = 0, 57 /** Release of a key */ 58 KEY_RELEASED = 1, 59 /** Key switch enabled */ 60 KEY_SWITCH_ON = 2, 61 /** Key switch disabled */ 62 KEY_SWITCH_OFF = 3 63 } Input_KeyStateAction; 64 65 /** 66 * @brief Enumerates key event types. 67 * 68 * @since 12 69 */ 70 typedef enum Input_KeyEventAction { 71 /** Cancellation of a key action. */ 72 KEY_ACTION_CANCEL = 0, 73 /** Pressing of a key. */ 74 KEY_ACTION_DOWN = 1, 75 /** Release of a key. */ 76 KEY_ACTION_UP = 2, 77 } Input_KeyEventAction; 78 79 /** 80 * @brief Enumerated values of mouse event action. 81 * 82 * @since 12 83 */ 84 typedef enum Input_MouseEventAction { 85 /** Cancel. */ 86 MOUSE_ACTION_CANCEL = 0, 87 /** Moving of the mouse pointer. */ 88 MOUSE_ACTION_MOVE = 1, 89 /** Pressing down of the mouse. */ 90 MOUSE_ACTION_BUTTON_DOWN = 2, 91 /** Lifting of the mouse button. */ 92 MOUSE_ACTION_BUTTON_UP = 3, 93 /** Beginning of the mouse axis event */ 94 MOUSE_ACTION_AXIS_BEGIN = 4, 95 /** Updating of the mouse axis event */ 96 MOUSE_ACTION_AXIS_UPDATE = 5, 97 /** End of the mouse axis event */ 98 MOUSE_ACTION_AXIS_END = 6, 99 } Input_MouseEventAction; 100 101 /** 102 * @brief Mouse axis types. 103 * 104 * @since 12 105 */ 106 typedef enum InputEvent_MouseAxis { 107 /** Vertical scroll axis */ 108 MOUSE_AXIS_SCROLL_VERTICAL = 0, 109 /** Horizontal scroll axis */ 110 MOUSE_AXIS_SCROLL_HORIZONTAL = 1, 111 } InputEvent_MouseAxis; 112 113 /** 114 * @brief Enumerated values of mouse event button. 115 * 116 * @since 12 117 */ 118 typedef enum Input_MouseEventButton { 119 /** Invalid button */ 120 MOUSE_BUTTON_NONE = -1, 121 /** Left button on the mouse. */ 122 MOUSE_BUTTON_LEFT = 0, 123 /** Middle button on the mouse. */ 124 MOUSE_BUTTON_MIDDLE = 1, 125 /** Right button on the mouse. */ 126 MOUSE_BUTTON_RIGHT = 2, 127 /** Forward button on the mouse. */ 128 MOUSE_BUTTON_FORWARD = 3, 129 /** Back button on the mouse. */ 130 MOUSE_BUTTON_BACK = 4, 131 } Input_MouseEventButton; 132 133 /** 134 * @brief Enumerated values of touch event action. 135 * 136 * @since 12 137 */ 138 typedef enum Input_TouchEventAction { 139 /** Touch cancelled. */ 140 TOUCH_ACTION_CANCEL = 0, 141 /** Touch pressed. */ 142 TOUCH_ACTION_DOWN = 1, 143 /** Touch moved. */ 144 TOUCH_ACTION_MOVE = 2, 145 /** Touch lifted. */ 146 TOUCH_ACTION_UP = 3, 147 } Input_TouchEventAction; 148 149 /** 150 * @brief Enumerates event source types. 151 * 152 * @since 12 153 */ 154 typedef enum InputEvent_SourceType { 155 /** 156 * Indicates that the input source generates events similar to mouse cursor movement, 157 * button press and release, and wheel scrolling. 158 * 159 * @since 12 160 */ 161 SOURCE_TYPE_MOUSE = 1, 162 /** 163 * Indicates that the input source generates a touchscreen multi-touch event. 164 * 165 * @since 12 166 */ 167 SOURCE_TYPE_TOUCHSCREEN = 2, 168 /** 169 * Indicates that the input source generates a touchpad multi-touch event. 170 * 171 * @since 12 172 */ 173 SOURCE_TYPE_TOUCHPAD = 3 174 } InputEvent_SourceType; 175 176 /** 177 * @brief Enumerates keyboard types. 178 * 179 * @since 13 180 */ 181 typedef enum Input_KeyboardType { 182 /** Keyboard without keys */ 183 KEYBOARD_TYPE_NONE = 0, 184 /** Keyboard with unknown keys */ 185 KEYBOARD_TYPE_UNKNOWN = 1, 186 /** Full keyboard */ 187 KEYBOARD_TYPE_ALPHABETIC = 2, 188 /** Digital keyboard */ 189 KEYBOARD_TYPE_DIGITAL = 3, 190 /** Stylus */ 191 KEYBOARD_TYPE_STYLUS = 4, 192 /** Remote control */ 193 KEYBOARD_TYPE_REMOTE_CONTROL = 5, 194 } Input_KeyboardType; 195 196 /** 197 * @brief Defines key information, which identifies a key pressing behavior. 198 * For example, the Ctrl key information contains the key value and key type. 199 * 200 * @since 12 201 */ 202 typedef struct Input_KeyState Input_KeyState; 203 204 /** 205 * @brief The key event to be injected. 206 * 207 * @since 12 208 */ 209 typedef struct Input_KeyEvent Input_KeyEvent; 210 211 /** 212 * @brief The mouse event to be injected. 213 * 214 * @since 12 215 */ 216 typedef struct Input_MouseEvent Input_MouseEvent; 217 218 /** 219 * @brief The touch event to be injected. 220 * 221 * @since 12 222 */ 223 typedef struct Input_TouchEvent Input_TouchEvent; 224 225 /** 226 * @brief Enumerates axis events. 227 * 228 * @since 12 229 */ 230 typedef struct Input_AxisEvent Input_AxisEvent; 231 232 /** 233 * @brief Enumerates error codes. 234 * 235 * @since 12 236 */ 237 typedef enum Input_Result { 238 /** Success */ 239 INPUT_SUCCESS = 0, 240 /** Permission verification failed */ 241 INPUT_PERMISSION_DENIED = 201, 242 /** Non-system application */ 243 INPUT_NOT_SYSTEM_APPLICATION = 202, 244 /** Parameter check failed */ 245 INPUT_PARAMETER_ERROR = 401, 246 /** 247 * @error Device not support 248 * @since 14 249 */ 250 INPUT_DEVICE_NOT_SUPPORTED = 801, 251 /** Service error */ 252 INPUT_SERVICE_EXCEPTION = 3800001, 253 /** Interceptor repeatedly created for an application */ 254 INPUT_REPEAT_INTERCEPTOR = 4200001, 255 /** 256 * @error Already occupied by the other 257 * @since 13 258 */ 259 INPUT_OCCUPIED_BY_OTHER = 4200003 260 } Input_Result; 261 262 /** 263 * @brief Defines the hot key structure. 264 * 265 * @since 14 266 */ 267 typedef struct Input_Hotkey Input_Hotkey; 268 269 /** 270 * @brief Defines a lifecycle callback for **keyEvent**. 271 * If the callback is triggered, **keyEvent** will be destroyed. 272 * @since 12 273 */ 274 typedef void (*Input_KeyEventCallback)(const Input_KeyEvent* keyEvent); 275 276 /** 277 * @brief Defines a lifecycle callback for **mouseEvent**. 278 * If the callback is triggered, **mouseEvent** will be destroyed. 279 * @since 12 280 */ 281 typedef void (*Input_MouseEventCallback)(const Input_MouseEvent* mouseEvent); 282 283 /** 284 * @brief Defines a lifecycle callback for **touchEvent**. 285 * If the callback is triggered, **touchEvent** will be destroyed. 286 * @since 12 287 */ 288 typedef void (*Input_TouchEventCallback)(const Input_TouchEvent* touchEvent); 289 290 /** 291 * @brief Defines a lifecycle callback for **axisEvent**. 292 * If the callback is triggered, **axisEvent** will be destroyed. 293 * @since 12 294 */ 295 typedef void (*Input_AxisEventCallback)(const Input_AxisEvent* axisEvent); 296 297 typedef void (*Input_HotkeyCallback)(Input_Hotkey* hotkey); 298 299 /** 300 * @brief Defines the callback for device addition events. 301 * @param deviceId Device ID. 302 * @since 13 303 */ 304 typedef void (*Input_DeviceAddedCallback)(int32_t deviceId); 305 306 /** 307 * @brief Defines the callback for device removal events. 308 * @param deviceId Device ID. 309 * @since 13 310 */ 311 typedef void (*Input_DeviceRemovedCallback)(int32_t deviceId); 312 313 /** 314 * @brief Defines the structure for the interceptor of event callbacks, 315 * including mouseCallback, touchCallback, and axisCallback. 316 * @since 12 317 */ 318 typedef struct Input_InterceptorEventCallback { 319 /** Defines a lifecycle callback for **mouseEvent**. */ 320 Input_MouseEventCallback mouseCallback; 321 /** Defines a lifecycle callback for **touchEvent**. */ 322 Input_TouchEventCallback touchCallback; 323 /** Defines a lifecycle callback for **axisEvent**. */ 324 Input_AxisEventCallback axisCallback; 325 } Input_InterceptorEventCallback; 326 327 /** 328 * @brief Defines a listener for device insertion and removal events. 329 * @since 13 330 */ 331 typedef struct Input_DeviceListener { 332 /** Callback for device addition events */ 333 Input_DeviceAddedCallback deviceAddedCallback; 334 /** Callback for device removal events */ 335 Input_DeviceRemovedCallback deviceRemovedCallback; 336 } Input_DeviceListener; 337 338 /** 339 * @brief Defines event interceptor options. 340 * @since 12 341 */ 342 typedef struct Input_InterceptorOptions Input_InterceptorOptions; 343 344 /** 345 * @brief Represents information about the input device. 346 * 347 * @since 13 348 */ 349 typedef struct Input_DeviceInfo Input_DeviceInfo; 350 351 /** 352 * @brief Queries the key state. 353 * 354 * @param keyState Key state. 355 * @HTTP4O4 Returns {@Link Input_Result#INPUT_SUCCESS} if the operation is successful; 356 * returns an error code defined in {@Link Input_Result} otherwise. 357 * @syscap SystemCapability.MultimodalInput.Input.Core 358 * @since 12 359 */ 360 Input_Result OH_Input_GetKeyState(struct Input_KeyState* keyState); 361 362 /** 363 * @brief Creates a key status enumeration object. 364 * 365 * @return Returns an {@link Input_KeyState} pointer object if the operation is successful. 366 * returns a null pointer otherwise. 367 * @syscap SystemCapability.MultimodalInput.Input.Core 368 * @since 12 369 */ 370 struct Input_KeyState* OH_Input_CreateKeyState(); 371 372 /** 373 * @brief Destroys a key status enumeration object. 374 * 375 * @param keyState Key status enumeration object. 376 * @syscap SystemCapability.MultimodalInput.Input.Core 377 * @since 12 378 */ 379 void OH_Input_DestroyKeyState(struct Input_KeyState** keyState); 380 381 /** 382 * @brief Sets the key value of a key status enumeration object. 383 * 384 * @param keyState Key status enumeration object. 385 * @param keyCode Key value of the key status enumeration object. 386 * @syscap SystemCapability.MultimodalInput.Input.Core 387 * @since 12 388 */ 389 void OH_Input_SetKeyCode(struct Input_KeyState* keyState, int32_t keyCode); 390 391 /** 392 * @brief Obtains the key value of a key status enumeration object. 393 * 394 * @param keyState Key status enumeration object. 395 * @return Key value of the key status enumeration object. 396 * @syscap SystemCapability.MultimodalInput.Input.Core 397 * @since 12 398 */ 399 int32_t OH_Input_GetKeyCode(const struct Input_KeyState* keyState); 400 401 /** 402 * @brief Sets whether the key specific to a key status enumeration object is pressed. 403 * 404 * @param keyState Key status enumeration object. 405 * @param keyAction Whether the key is pressed. 406 * @syscap SystemCapability.MultimodalInput.Input.Core 407 * @since 12 408 */ 409 void OH_Input_SetKeyPressed(struct Input_KeyState* keyState, int32_t keyAction); 410 411 /** 412 * @brief Checks whether the key specific to a key status enumeration object is pressed. 413 * 414 * @param keyState Key status enumeration object. 415 * @return Key pressing status of the key status enumeration object. 416 * @syscap SystemCapability.MultimodalInput.Input.Core 417 * @since 12 418 */ 419 int32_t OH_Input_GetKeyPressed(const struct Input_KeyState* keyState); 420 421 /** 422 * @brief Sets the key switch of the key status enumeration object. 423 * 424 * @param keyState Key status enumeration object. 425 * @param keySwitch Key switch of the key status enumeration object. 426 * @syscap SystemCapability.MultimodalInput.Input.Core 427 * @since 12 428 */ 429 void OH_Input_SetKeySwitch(struct Input_KeyState* keyState, int32_t keySwitch); 430 431 /** 432 * @brief Obtains the key switch of the key status enumeration object. 433 * 434 * @param keyState Key status enumeration object. 435 * @return Key switch of the key status enumeration object. 436 * @syscap SystemCapability.MultimodalInput.Input.Core 437 * @since 12 438 */ 439 int32_t OH_Input_GetKeySwitch(const struct Input_KeyState* keyState); 440 441 /** 442 * @brief Inject system keys. 443 * 444 * @param keyEvent - the key event to be injected. 445 * @return 0 - Success. 446 * 201 - Missing permissions. 447 * 401 - Parameter error. 448 * @syscap SystemCapability.MultimodalInput.Input.Core 449 * @since 12 450 */ 451 int32_t OH_Input_InjectKeyEvent(const struct Input_KeyEvent* keyEvent); 452 453 /** 454 * @brief Creates a key event object. 455 * 456 * @return Returns an {@link Input_KeyEvent} pointer object if the operation is successful. 457 * returns a null pointer otherwise. 458 * @syscap SystemCapability.MultimodalInput.Input.Core 459 * @since 12 460 */ 461 struct Input_KeyEvent* OH_Input_CreateKeyEvent(); 462 463 /** 464 * @brief Destroys a key event object. 465 * 466 * @param keyEvent Key event object. 467 * @syscap SystemCapability.MultimodalInput.Input.Core 468 * @since 12 469 */ 470 void OH_Input_DestroyKeyEvent(struct Input_KeyEvent** keyEvent); 471 472 /** 473 * @brief Sets the key event type. 474 * 475 * @param keyEvent Key event object. 476 * @param action Key event type. 477 * @syscap SystemCapability.MultimodalInput.Input.Core 478 * @since 12 479 */ 480 void OH_Input_SetKeyEventAction(struct Input_KeyEvent* keyEvent, int32_t action); 481 482 /** 483 * @brief Obtains the key event type. 484 * 485 * @param keyEvent Key event object. 486 * @return Key event type. 487 * @syscap SystemCapability.MultimodalInput.Input.Core 488 * @since 12 489 */ 490 int32_t OH_Input_GetKeyEventAction(const struct Input_KeyEvent* keyEvent); 491 492 /** 493 * @brief Sets the key value for a key event. 494 * 495 * @param keyEvent Key event object. 496 * @param keyCode keyCode Key code. 497 * @syscap SystemCapability.MultimodalInput.Input.Core 498 * @since 12 499 */ 500 void OH_Input_SetKeyEventKeyCode(struct Input_KeyEvent* keyEvent, int32_t keyCode); 501 502 /** 503 * @brief Obtains the key value of a key event. 504 * 505 * @param keyEvent Key event object. 506 * @return Key code. 507 * @syscap SystemCapability.MultimodalInput.Input.Core 508 * @since 12 509 */ 510 int32_t OH_Input_GetKeyEventKeyCode(const struct Input_KeyEvent* keyEvent); 511 512 /** 513 * @brief Sets the time when a key event occurs. 514 * 515 * @param keyEvent Key event object. 516 * @param actionTime Time when the key event occurs. 517 * @syscap SystemCapability.MultimodalInput.Input.Core 518 * @since 12 519 */ 520 void OH_Input_SetKeyEventActionTime(struct Input_KeyEvent* keyEvent, int64_t actionTime); 521 522 /** 523 * @brief Obtains the time when a key event occurs. 524 * 525 * @param keyEvent Key event object. 526 * @return Returns the time when the key event occurs. 527 * @syscap SystemCapability.MultimodalInput.Input.Core 528 * @since 12 529 */ 530 int64_t OH_Input_GetKeyEventActionTime(const struct Input_KeyEvent* keyEvent); 531 532 /** 533 * @brief Inject mouse event. 534 * 535 * @param mouseEvent - the mouse event to be injected. 536 * @return 0 - Success. 537 * 201 - Missing permissions. 538 * 401 - Parameter error. 539 * @syscap SystemCapability.MultimodalInput.Input.Core 540 * @since 12 541 */ 542 int32_t OH_Input_InjectMouseEvent(const struct Input_MouseEvent* mouseEvent); 543 544 /** 545 * @brief Creates a mouse event object. 546 * 547 * @return Returns an {@link Input_MouseEvent} pointer object if the operation is successful. 548 * returns a null pointer otherwise. 549 * @syscap SystemCapability.MultimodalInput.Input.Core 550 * @since 12 551 */ 552 struct Input_MouseEvent* OH_Input_CreateMouseEvent(); 553 554 /** 555 * @brief Destroys a mouse event object. 556 * 557 * @param mouseEvent Mouse event object. 558 * @syscap SystemCapability.MultimodalInput.Input.Core 559 * @since 12 560 */ 561 void OH_Input_DestroyMouseEvent(struct Input_MouseEvent** mouseEvent); 562 563 /** 564 * @brief Sets the action for a mouse event. 565 * 566 * @param mouseEvent Mouse event object. 567 * @param action Mouse action. 568 * @syscap SystemCapability.MultimodalInput.Input.Core 569 * @since 12 570 */ 571 void OH_Input_SetMouseEventAction(struct Input_MouseEvent* mouseEvent, int32_t action); 572 573 /** 574 * @brief Obtains the action of a mouse event. 575 * 576 * @param mouseEvent Mouse event object. 577 * @return Mouse action. 578 * @syscap SystemCapability.MultimodalInput.Input.Core 579 * @since 12 580 */ 581 int32_t OH_Input_GetMouseEventAction(const struct Input_MouseEvent* mouseEvent); 582 583 /** 584 * @brief Sets the X coordinate for a mouse event. 585 * 586 * @param mouseEvent Mouse event object. 587 * @param displayX X coordinate on the display. 588 * @syscap SystemCapability.MultimodalInput.Input.Core 589 * @since 12 590 */ 591 void OH_Input_SetMouseEventDisplayX(struct Input_MouseEvent* mouseEvent, int32_t displayX); 592 593 /** 594 * @brief Obtains the X coordinate of a mouse event. 595 * 596 * @param mouseEvent Mouse event object. 597 * @return X coordinate on the display. 598 * @syscap SystemCapability.MultimodalInput.Input.Core 599 * @since 12 600 */ 601 int32_t OH_Input_GetMouseEventDisplayX(const struct Input_MouseEvent* mouseEvent); 602 603 /** 604 * @brief Sets the Y coordinate for a mouse event. 605 * 606 * @param mouseEvent Mouse event object. 607 * @param displayY Y coordinate on the display. 608 * @syscap SystemCapability.MultimodalInput.Input.Core 609 * @since 12 610 */ 611 void OH_Input_SetMouseEventDisplayY(struct Input_MouseEvent* mouseEvent, int32_t displayY); 612 613 /** 614 * @brief Obtains the Y coordinate of a mouse event. 615 * 616 * @param mouseEvent Mouse event object. 617 * @return Y coordinate on the display. 618 * @syscap SystemCapability.MultimodalInput.Input.Core 619 * @since 12 620 */ 621 int32_t OH_Input_GetMouseEventDisplayY(const struct Input_MouseEvent* mouseEvent); 622 623 /** 624 * @brief Sets the button for a mouse event. 625 * 626 * @param mouseEvent Mouse event object. 627 * @param button Mouse button. 628 * @syscap SystemCapability.MultimodalInput.Input.Core 629 * @since 12 630 */ 631 void OH_Input_SetMouseEventButton(struct Input_MouseEvent* mouseEvent, int32_t button); 632 633 /** 634 * @brief Obtains the button of a mouse event. 635 * 636 * @param mouseEvent Mouse event object. 637 * @return Mouse button. 638 * @syscap SystemCapability.MultimodalInput.Input.Core 639 * @since 12 640 */ 641 int32_t OH_Input_GetMouseEventButton(const struct Input_MouseEvent* mouseEvent); 642 643 /** 644 * @brief Sets the axis type for mouse event. 645 * 646 * @param mouseEvent Mouse event object. 647 * @param axisType Axis type, for example, X axis or Y axis. 648 * @syscap SystemCapability.MultimodalInput.Input.Core 649 * @since 12 650 */ 651 void OH_Input_SetMouseEventAxisType(struct Input_MouseEvent* mouseEvent, int32_t axisType); 652 653 /** 654 * @brief Obtains the axis type of a mouse event. 655 * 656 * @param mouseEvent Mouse event object. 657 * @return Axis type. 658 * @syscap SystemCapability.MultimodalInput.Input.Core 659 * @since 12 660 */ 661 int32_t OH_Input_GetMouseEventAxisType(const struct Input_MouseEvent* mouseEvent); 662 663 /** 664 * @brief Sets the axis value for a mouse axis event. 665 * 666 * @param mouseEvent Mouse event object. 667 * @param axisType Axis value. A positive value means scrolling forward, and a negative number means scrolling backward. 668 * @syscap SystemCapability.MultimodalInput.Input.Core 669 * @since 12 670 */ 671 void OH_Input_SetMouseEventAxisValue(struct Input_MouseEvent* mouseEvent, float axisValue); 672 673 /** 674 * @brief Obtains the axis value of a mouse event. 675 * 676 * @param mouseEvent Mouse event object. 677 * @return Axis value. 678 * @syscap SystemCapability.MultimodalInput.Input.Core 679 * @since 12 680 */ 681 float OH_Input_GetMouseEventAxisValue(const struct Input_MouseEvent* mouseEvent); 682 683 /** 684 * @brief Sets the time when a mouse event occurs. 685 * 686 * @param mouseEvent Mouse event object. 687 * @param actionTime Time when the mouse event occurs. 688 * @syscap SystemCapability.MultimodalInput.Input.Core 689 * @since 12 690 */ 691 void OH_Input_SetMouseEventActionTime(struct Input_MouseEvent* mouseEvent, int64_t actionTime); 692 693 /** 694 * @brief Obtains the time when a mouse event occurs. 695 * 696 * @param keyEvent Mouse event object. 697 * @return Returns the time when the mouse event occurs. 698 * @syscap SystemCapability.MultimodalInput.Input.Core 699 * @since 12 700 */ 701 int64_t OH_Input_GetMouseEventActionTime(const struct Input_MouseEvent* mouseEvent); 702 703 /** 704 * @brief Inject touch event. 705 * 706 * @param touchEvent - the touch event to be injected. 707 * @return 0 - Success. 708 * 201 - Missing permissions. 709 * 401 - Parameter error. 710 * @syscap SystemCapability.MultimodalInput.Input.Core 711 * @since 12 712 */ 713 int32_t OH_Input_InjectTouchEvent(const struct Input_TouchEvent* touchEvent); 714 715 /** 716 * @brief Creates a touch event object. 717 * 718 * @return Returns an {@link Input_TouchEvent} pointer object if the operation is successful. 719 * returns a null pointer otherwise. 720 * @syscap SystemCapability.MultimodalInput.Input.Core 721 * @since 12 722 */ 723 struct Input_TouchEvent* OH_Input_CreateTouchEvent(); 724 725 /** 726 * @brief Destroys a touch event object. 727 * 728 * @param touchEvent Touch event object. 729 * @syscap SystemCapability.MultimodalInput.Input.Core 730 * @since 12 731 */ 732 void OH_Input_DestroyTouchEvent(struct Input_TouchEvent** touchEvent); 733 734 /** 735 * @brief Sets the action for a touch event. 736 * 737 * @param touchEvent Touch event object. 738 * @param action Touch action. 739 * @syscap SystemCapability.MultimodalInput.Input.Core 740 * @since 12 741 */ 742 void OH_Input_SetTouchEventAction(struct Input_TouchEvent* touchEvent, int32_t action); 743 744 /** 745 * @brief Obtains the action of a touch event. 746 * 747 * @param touchEvent Touch event object. 748 * @return Touch action. 749 * @syscap SystemCapability.MultimodalInput.Input.Core 750 * @since 12 751 */ 752 int32_t OH_Input_GetTouchEventAction(const struct Input_TouchEvent* touchEvent); 753 754 /** 755 * @brief Sets the finger ID for the touch event. 756 * 757 * @param touchEvent Touch event object. 758 * @param id Finger ID. 759 * @syscap SystemCapability.MultimodalInput.Input.Core 760 * @since 12 761 */ 762 void OH_Input_SetTouchEventFingerId(struct Input_TouchEvent* touchEvent, int32_t id); 763 764 /** 765 * @brief Obtains the finger ID of a touch event. 766 * 767 * @param touchEvent Touch event object. 768 * @return Finger ID. 769 * @syscap SystemCapability.MultimodalInput.Input.Core 770 * @since 12 771 */ 772 int32_t OH_Input_GetTouchEventFingerId(const struct Input_TouchEvent* touchEvent); 773 774 /** 775 * @brief Sets the X coordinate for a touch event. 776 * 777 * @param touchEvent Touch event object. 778 * @param displayX X coordinate. 779 * @syscap SystemCapability.MultimodalInput.Input.Core 780 * @since 12 781 */ 782 void OH_Input_SetTouchEventDisplayX(struct Input_TouchEvent* touchEvent, int32_t displayX); 783 784 /** 785 * @brief Obtains the X coordinate of a touch event. 786 * 787 * @param touchEvent Touch event object. 788 * @return X coordinate. 789 * @syscap SystemCapability.MultimodalInput.Input.Core 790 * @since 12 791 */ 792 int32_t OH_Input_GetTouchEventDisplayX(const struct Input_TouchEvent* touchEvent); 793 794 /** 795 * @brief Sets the Y coordinate for a touch event. 796 * 797 * @param touchEvent Touch event object. 798 * @param displayY Y coordinate. 799 * @syscap SystemCapability.MultimodalInput.Input.Core 800 * @since 12 801 */ 802 void OH_Input_SetTouchEventDisplayY(struct Input_TouchEvent* touchEvent, int32_t displayY); 803 804 /** 805 * @brief Obtains the Y coordinate of a touch event. 806 * 807 * @param touchEvent Touch event object. 808 * @return Y coordinate. 809 * @syscap SystemCapability.MultimodalInput.Input.Core 810 * @since 12 811 */ 812 int32_t OH_Input_GetTouchEventDisplayY(const struct Input_TouchEvent* touchEvent); 813 814 /** 815 * @brief Sets the time when a touch event occurs. 816 * 817 * @param keyEvent Touch event object. 818 * @param actionTime Time when the touch event occurs. 819 * @syscap SystemCapability.MultimodalInput.Input.Core 820 * @since 12 821 */ 822 void OH_Input_SetTouchEventActionTime(struct Input_TouchEvent* touchEvent, int64_t actionTime); 823 824 /** 825 * @brief Obtains the time when a touch event occurs. 826 * 827 * @param keyEvent touch event object. 828 * @return Returns the time when the touch event occurs. 829 * @syscap SystemCapability.MultimodalInput.Input.Core 830 * @since 12 831 */ 832 int64_t OH_Input_GetTouchEventActionTime(const struct Input_TouchEvent* touchEvent); 833 834 /** 835 * @brief Cancels event injection and revokes authorization. 836 * 837 * @syscap SystemCapability.MultimodalInput.Input.Core 838 * @since 12 839 */ 840 void OH_Input_CancelInjection(); 841 842 /** 843 * @brief Creates an axis event object. 844 * 845 * @return If the operation is successful, a {@Link Input_AxisEvent} object is returned. 846 * If the operation fails, null is returned. 847 * @syscap SystemCapability.MultimodalInput.Input.Core 848 * @since 12 849 */ 850 Input_AxisEvent* OH_Input_CreateAxisEvent(void); 851 852 /** 853 * @brief Destroys an axis event object. 854 * 855 * @param axisEvent Pointer to the axis event object. 856 * @return OH_Input_DestroyAxisEvent function result code. 857 * {@link INPUT_SUCCESS} Destroys axisEvent success.\n 858 * {@link INPUT_PARAMETER_ERROR}The axisEvent is NULL or the *axisEvent is NULL.\n 859 * @syscap SystemCapability.MultimodalInput.Input.Core 860 * @since 12 861 */ 862 Input_Result OH_Input_DestroyAxisEvent(Input_AxisEvent** axisEvent); 863 864 /** 865 * @brief Sets the axis event action. 866 * 867 * @param axisEvent Axis event object. For details, see {@Link Input_AxisEvent}. 868 * @param action Axis event action. The values are defined in {@link InputEvent_AxisAction}. 869 * @return OH_Input_SetAxisEventAction function result code. 870 * {@link INPUT_SUCCESS} Sets the axis event action success.\n 871 * {@link INPUT_PARAMETER_ERROR} The axisEvent is NULL.\n 872 * @syscap SystemCapability.MultimodalInput.Input.Core 873 * @since 12 874 */ 875 Input_Result OH_Input_SetAxisEventAction(Input_AxisEvent* axisEvent, InputEvent_AxisAction action); 876 877 /** 878 * @brief Obtains the axis event action. 879 * 880 * @param axisEvent Axis event object. For details, see {@Link Input_AxisEvent}. 881 * @param action Axis event action. The values are defined in {@link InputEvent_AxisAction}. 882 * @return OH_Input_GetAxisEventAction function result code. 883 * {@link INPUT_SUCCESS} Obtains the axis event action success.\n 884 * {@link INPUT_PARAMETER_ERROR} The axisEvent is NULL or the action is NULL.\n 885 * @syscap SystemCapability.MultimodalInput.Input.Core 886 * @since 12 887 */ 888 Input_Result OH_Input_GetAxisEventAction(const Input_AxisEvent* axisEvent, InputEvent_AxisAction *action); 889 890 /** 891 * @brief Sets the X coordinate of an axis event. 892 * 893 * @param axisEvent Axis event object. For details, see {@Link Input_AxisEvent}. 894 * @param displayX X coordinate of the axis event. 895 * @return OH_Input_SetAxisEventDisplayX function result code. 896 * {@link INPUT_SUCCESS} Sets the X coordinate of the axis event success.\n 897 * {@link INPUT_PARAMETER_ERROR} The axisEvent is NULL.\n 898 * @syscap SystemCapability.MultimodalInput.Input.Core 899 * @since 12 900 */ 901 Input_Result OH_Input_SetAxisEventDisplayX(Input_AxisEvent* axisEvent, float displayX); 902 903 /** 904 * @brief Obtains the X coordinate of an axis event. 905 * 906 * @param axisEvent Axis event object. For details, see {@Link Input_AxisEvent}. 907 * @param displayX X coordinate of the axis event. 908 * @return OH_Input_GetAxisEventDisplayX function result code. 909 * {@link INPUT_SUCCESS} Obtains the X coordinate of the axis event success.\n 910 * {@link INPUT_PARAMETER_ERROR} The axisEvent is NULL or the displayX is NULL.\n 911 * @syscap SystemCapability.MultimodalInput.Input.Core 912 * @since 12 913 */ 914 Input_Result OH_Input_GetAxisEventDisplayX(const Input_AxisEvent* axisEvent, float* displayX); 915 916 /** 917 * @brief Sets the Y coordinate of an axis event. 918 * 919 * @param axisEvent Axis event object. For details, see {@Link Input_AxisEvent}. 920 * @param displayY Y coordinate of the axis event. 921 * @return OH_Input_SetAxisEventDisplayY function result code. 922 * {@link INPUT_SUCCESS} Sets the Y coordinate of the axis event success.\n 923 * {@link INPUT_PARAMETER_ERROR} The axisEvent is NULL.\n 924 * @syscap SystemCapability.MultimodalInput.Input.Core 925 * @since 12 926 */ 927 Input_Result OH_Input_SetAxisEventDisplayY(Input_AxisEvent* axisEvent, float displayY); 928 929 /** 930 * @brief Obtains the Y coordinate of an axis event. 931 * 932 * @param axisEvent Axis event object. For details, see {@Link Input_AxisEvent}. 933 * @param displayY Y coordinate of the axis event. 934 * @return OH_Input_GetAxisEventDisplayY function result code. 935 * {@link INPUT_SUCCESS} Obtains the Y coordinate of the axis event success.\n 936 * {@link INPUT_PARAMETER_ERROR} The axisEvent is NULL or the displayY is NULL.\n 937 * @syscap SystemCapability.MultimodalInput.Input.Core 938 * @since 12 939 */ 940 Input_Result OH_Input_GetAxisEventDisplayY(const Input_AxisEvent* axisEvent, float* displayY); 941 942 /** 943 * @brief Sets the axis value of the axis type specified by the axis event. 944 * 945 * @param axisEvent Axis event object. For details, see {@Link Input_AxisEvent}. 946 * @param axisType Axis type. The values are defined in {@link InputEvent_AxisType}. 947 * @param axisValue Axis value. 948 * @return OH_Input_SetAxisEventAxisValue function result code. 949 * {@link INPUT_SUCCESS} Sets the axis value of the axis event success.\n 950 * {@link INPUT_PARAMETER_ERROR} The axisEvent is NULL.\n 951 * @syscap SystemCapability.MultimodalInput.Input.Core 952 * @since 12 953 */ 954 Input_Result OH_Input_SetAxisEventAxisValue(Input_AxisEvent* axisEvent, 955 InputEvent_AxisType axisType, double axisValue); 956 957 /** 958 * @brief Obtains the axis value for the specified axis type of the axis event. 959 * 960 * @param axisEvent Axis event object. For details, see {@Link Input_AxisEvent}. 961 * @param axisType Axis type. The values are defined in {@link InputEvent_AxisType}. 962 * @param axisValue Axis value. 963 * @return OH_Input_GetAxisEventAxisValue function result code. 964 * {@link INPUT_SUCCESS} Obtains the axis value of the axis event success.\n 965 * {@link INPUT_PARAMETER_ERROR} The axisEvent is NULL or the axisValue is NULL, 966 * or the axisType not found in the axisEvent.\n 967 * @syscap SystemCapability.MultimodalInput.Input.Core 968 * @since 12 969 */ 970 Input_Result OH_Input_GetAxisEventAxisValue(const Input_AxisEvent* axisEvent, 971 InputEvent_AxisType axisType, double* axisValue); 972 973 /** 974 * @brief Sets the time when an axis event occurs. 975 * 976 * @param axisEvent Axis event object. For details, see {@Link Input_AxisEvent}. 977 * @param actionTime Time when an axis event occurs. 978 * @return OH_Input_SetAxisEventActionTime function result code. 979 * {@link INPUT_SUCCESS} Sets the time when an axis event occurs success.\n 980 * {@link INPUT_PARAMETER_ERROR} The axisEvent is NULL.\n 981 * @syscap SystemCapability.MultimodalInput.Input.Core 982 * @since 12 983 */ 984 Input_Result OH_Input_SetAxisEventActionTime(Input_AxisEvent* axisEvent, int64_t actionTime); 985 986 /** 987 * @brief Obtains the time when an axis event occurs. 988 * 989 * @param axisEvent Axis event object. For details, see {@Link Input_AxisEvent}. 990 * @param actionTime Time when an axis event occurs. 991 * @return OH_Input_GetAxisEventActionTime function result code. 992 * {@link INPUT_SUCCESS} Obtains the time when an axis event occurs success.\n 993 * {@link INPUT_PARAMETER_ERROR} The axisEvent is NULL or the actionTime is NULL.\n 994 * @syscap SystemCapability.MultimodalInput.Input.Core 995 * @since 12 996 */ 997 Input_Result OH_Input_GetAxisEventActionTime(const Input_AxisEvent* axisEvent, int64_t* actionTime); 998 999 /** 1000 * @brief Sets the axis event type. 1001 * 1002 * @param axisEvent Axis event object. For details, see {@Link Input_AxisEvent}. 1003 * @param axisEventType Axis event type. The values are defined in {@link InputEvent_AxisEventType}. 1004 * @return OH_Input_SetAxisEventType function result code. 1005 * {@link INPUT_SUCCESS} Sets the axis event type success.\n 1006 * {@link INPUT_PARAMETER_ERROR} The axisEvent is NULL.\n 1007 * @syscap SystemCapability.MultimodalInput.Input.Core 1008 * @since 12 1009 */ 1010 Input_Result OH_Input_SetAxisEventType(Input_AxisEvent* axisEvent, InputEvent_AxisEventType axisEventType); 1011 1012 /** 1013 * @brief Obtains the axis event type. 1014 * 1015 * @param axisEvent Axis event object. 1016 * @param axisEventType Axis event type. The values are defined in {@link InputEvent_AxisEventType}. 1017 * @return OH_Input_GetAxisEventType function result code. 1018 * {@link INPUT_SUCCESS} Obtains the axis event type success.\n 1019 * {@Link INPUT_PARAMETER_ERROR} The axisEvent is NULL or the axisEventType is NULL.\n 1020 * @syscap SystemCapability.MultimodalInput.Input.Core 1021 * @since 12 1022 */ 1023 Input_Result OH_Input_GetAxisEventType(const Input_AxisEvent* axisEvent, InputEvent_AxisEventType* axisEventType); 1024 1025 /** 1026 * @brief Sets the axis event source type. 1027 * 1028 * @param axisEvent Axis event object. 1029 * @param sourceType Axis event source type. The values are defined in {@link InputEvent_SourceType}. 1030 * @return OH_Input_SetAxisEventSourceType function result code. 1031 * {@link INPUT_SUCCESS} Sets the axis event source type success.\n 1032 * {@link INPUT_PARAMETER_ERROR} The axisEvent is NULL.\n 1033 * @syscap SystemCapability.MultimodalInput.Input.Core 1034 * @since 12 1035 */ 1036 Input_Result OH_Input_SetAxisEventSourceType(Input_AxisEvent* axisEvent, InputEvent_SourceType sourceType); 1037 1038 /** 1039 * @brief Obtains the axis event source type. 1040 * 1041 * @param axisEvent Axis event object. 1042 * @param axisEventType Axis event source type. The values are defined in {@link InputEvent_SourceType}. 1043 * @return OH_Input_GetAxisEventSourceType function result code. 1044 * {@link INPUT_SUCCESS} Obtains the axis event source type success.\n 1045 * {@link INPUT_PARAMETER_ERROR} The axisEvent is NULL or the sourceType is NULL.\n 1046 * @syscap SystemCapability.MultimodalInput.Input.Core 1047 * @since 12 1048 */ 1049 Input_Result OH_Input_GetAxisEventSourceType(const Input_AxisEvent* axisEvent, InputEvent_SourceType* sourceType); 1050 1051 /** 1052 * @brief Adds a listener of key events. 1053 * 1054 * @permission ohos.permission.INPUT_MONITORING 1055 * @param callback - Callback used to receive key events. 1056 * @return OH_Input_AddKeyEventMonitor function result code. 1057 * {@link INPUT_SUCCESS} Adds a listener of key events success.\n 1058 * {@link INPUT_PERMISSION_DENIED} Permission verification failed.\n 1059 * {@link INPUT_PARAMETER_ERROR} The callback is NULL.\n 1060 * {@link INPUT_SERVICE_EXCEPTION} Failed to add the monitor because the service is exception.\n 1061 * @syscap SystemCapability.MultimodalInput.Input.Core 1062 * @since 12 1063 */ 1064 Input_Result OH_Input_AddKeyEventMonitor(Input_KeyEventCallback callback); 1065 1066 /** 1067 * @brief Adds a listener for mouse events, including mouse click and movement events, 1068 * but not scroll wheel events. Scroll wheel events are axis events. 1069 * 1070 * @permission ohos.permission.INPUT_MONITORING 1071 * @param callback - Callback used to receive mouse events. 1072 * @return OH_Input_AddMouseEventMonitor function result code. 1073 * {@link INPUT_SUCCESS} Adds a listener of mouse events success.\n 1074 * {@link INPUT_PERMISSION_DENIED} Permission verification failed.\n 1075 * {@link INPUT_PARAMETER_ERROR} The callback is NULL.\n 1076 * {@link INPUT_SERVICE_EXCEPTION} Failed to add the monitor because the service is exception.\n 1077 * @syscap SystemCapability.MultimodalInput.Input.Core 1078 * @since 12 1079 */ 1080 Input_Result OH_Input_AddMouseEventMonitor(Input_MouseEventCallback callback); 1081 1082 /** 1083 * @brief Add a listener for touch events. 1084 * 1085 * @permission ohos.permission.INPUT_MONITORING 1086 * @param callback - Callback used to receive touch events. 1087 * @return OH_Input_AddTouchEventMonitor function result code. 1088 * {@link INPUT_SUCCESS} Adds a listener of touch events success.\n 1089 * {@link INPUT_PERMISSION_DENIED} Permission verification failed.\n 1090 * {@link INPUT_PARAMETER_ERROR} The callback is NULL.\n 1091 * {@link INPUT_SERVICE_EXCEPTION} Failed to add the monitor because the service is exception.\n 1092 * @syscap SystemCapability.MultimodalInput.Input.Core 1093 * @since 12 1094 */ 1095 Input_Result OH_Input_AddTouchEventMonitor(Input_TouchEventCallback callback); 1096 1097 /** 1098 * @brief Adds a listener for all types of axis events. 1099 * The axis event types are defined in {@Link InputEvent_AxisEventType}. 1100 * 1101 * @permission ohos.permission.INPUT_MONITORING 1102 * @param callback - Callback used to receive axis events. 1103 * @return OH_Input_AddAxisEventMonitorForAll function result code. 1104 * {@link INPUT_SUCCESS} Adds a listener for all types of axis events success.\n 1105 * {@link INPUT_PERMISSION_DENIED} Permission verification failed.\n 1106 * {@link INPUT_PARAMETER_ERROR} The callback is NULL.\n 1107 * {@link INPUT_SERVICE_EXCEPTION} Failed to add the monitor because the service is exception.\n 1108 * @syscap SystemCapability.MultimodalInput.Input.Core 1109 * @since 12 1110 */ 1111 Input_Result OH_Input_AddAxisEventMonitorForAll(Input_AxisEventCallback callback); 1112 1113 /** 1114 * @brief Adds a listener for the specified type of axis events. 1115 * 1116 * @permission ohos.permission.INPUT_MONITORING 1117 * @param axisEventType - Axis event type. The values are defined in {@Link InputEvent_AxisEventType}. 1118 * @param callback - Callback used to receive the specified type of axis events. 1119 * @return OH_Input_AddAxisEventMonitor function result code. 1120 * {@link INPUT_SUCCESS} Adds a listener for the specified types of axis events success.\n 1121 * {@link INPUT_PERMISSION_DENIED} Permission verification failed.\n 1122 * {@link INPUT_PARAMETER_ERROR} The callback is NULL.\n 1123 * {@link INPUT_SERVICE_EXCEPTION} Failed to add the monitor because the service is exception.\n 1124 * @syscap SystemCapability.MultimodalInput.Input.Core 1125 * @since 12 1126 */ 1127 Input_Result OH_Input_AddAxisEventMonitor(InputEvent_AxisEventType axisEventType, Input_AxisEventCallback callback); 1128 1129 /** 1130 * @brief Removes a key event listener. 1131 * 1132 * @permission ohos.permission.INPUT_MONITORING 1133 * @param callback - Callback for the key event listener. 1134 * @return OH_Input_RemoveKeyEventMonitor function result code. 1135 * {@link INPUT_SUCCESS} Removes a key event listener success.\n 1136 * {@link INPUT_PERMISSION_DENIED} Permission verification failed.\n 1137 * {@link INPUT_PARAMETER_ERROR} The callback is NULL or has not been added.\n 1138 * {@link INPUT_SERVICE_EXCEPTION} Fail to remove the monitor because the service is exception.\n 1139 * @syscap SystemCapability.MultimodalInput.Input.Core 1140 * @since 12 1141 */ 1142 Input_Result OH_Input_RemoveKeyEventMonitor(Input_KeyEventCallback callback); 1143 1144 /** 1145 * @brief Removes a mouse event listener. 1146 * 1147 * @permission ohos.permission.INPUT_MONITORING 1148 * @param callback - Callback for the mouse event listener. 1149 * @return OH_Input_RemoveMouseEventMonitor function result code. 1150 * {@link INPUT_SUCCESS} Removes a mouse event listener success.\n 1151 * {@link INPUT_PERMISSION_DENIED} Permission verification failed.\n 1152 * {@link INPUT_PARAMETER_ERROR} The callback is NULL or has not been added.\n 1153 * {@link INPUT_SERVICE_EXCEPTION} Fail to remove the monitor because the service is exception.\n 1154 * @syscap SystemCapability.MultimodalInput.Input.Core 1155 * @since 12 1156 */ 1157 Input_Result OH_Input_RemoveMouseEventMonitor(Input_MouseEventCallback callback); 1158 1159 /** 1160 * @brief Removes a touch event listener. 1161 * 1162 * @permission ohos.permission.INPUT_MONITORING 1163 * @param callback - Callback for the touch event listener. 1164 * @return OH_Input_RemoveTouchEventMonitor function result code. 1165 * {@link INPUT_SUCCESS} Removes a touch event listener success.\n 1166 * {@link INPUT_PERMISSION_DENIED} Permission verification failed.\n 1167 * {@link INPUT_PARAMETER_ERROR} The callback is NULL or has not been added.\n 1168 * {@link INPUT_SERVICE_EXCEPTION} Fail to remove the monitor because the service is exception.\n 1169 * @syscap SystemCapability.MultimodalInput.Input.Core 1170 * @since 12 1171 */ 1172 Input_Result OH_Input_RemoveTouchEventMonitor(Input_TouchEventCallback callback); 1173 1174 /** 1175 * @brief Removes the listener for all types of axis events. 1176 * 1177 * @permission ohos.permission.INPUT_MONITORING 1178 * @param callback - Callback for the listener used to listen for all types of axis events. 1179 * @return OH_Input_RemoveAxisEventMonitorForAll function result code. 1180 * {@link INPUT_SUCCESS} Removes the listener for all types of axis events success.\n 1181 * {@link INPUT_PERMISSION_DENIED} Permission verification failed.\n 1182 * {@link INPUT_PARAMETER_ERROR} The callback is NULL or has not been added.\n 1183 * {@link INPUT_SERVICE_EXCEPTION} Fail to remove the monitor because the service is exception.\n 1184 * @syscap SystemCapability.MultimodalInput.Input.Core 1185 * @since 12 1186 */ 1187 Input_Result OH_Input_RemoveAxisEventMonitorForAll(Input_AxisEventCallback callback); 1188 1189 /** 1190 * @brief Removes the listener for the specified type of axis events. 1191 * 1192 * @permission ohos.permission.INPUT_MONITORING 1193 * @param axisEventType - Axis event type. The axis event type is defined in {@Link InputEvent_AxisEventType}. 1194 * @param callback - Callback for the listener used to listen for the specified type of axis events. 1195 * @return OH_Input_RemoveAxisEventMonitor function result code. 1196 * {@link INPUT_SUCCESS} Removes the listener for the specified type of axis events success.\n 1197 * {@link INPUT_PERMISSION_DENIED} Permission verification failed.\n 1198 * {@link INPUT_PARAMETER_ERROR} The callback is NULL or has not been added.\n 1199 * {@link INPUT_SERVICE_EXCEPTION} Fail to remove the monitor because the service is exception.\n 1200 * @syscap SystemCapability.MultimodalInput.Input.Core 1201 * @since 12 1202 */ 1203 Input_Result OH_Input_RemoveAxisEventMonitor(InputEvent_AxisEventType axisEventType, Input_AxisEventCallback callback); 1204 1205 /** 1206 * @brief Adds a key event interceptor. If multiple interceptors are added, only the first one takes effect. 1207 * 1208 * @permission ohos.permission.INTERCEPT_INPUT_EVENT 1209 * @param callback - Callback used to receive key events. 1210 * @param option - Options for event interception. If **null** is passed, the default value is used. 1211 * @return OH_Input_AddKeyEventInterceptor function result code. 1212 * {@link INPUT_SUCCESS} Adds a key event interceptor success.\n 1213 * {@link INPUT_PERMISSION_DENIED} Permission verification failed.\n 1214 * {@link INPUT_PARAMETER_ERROR} The callback is NULL.\n 1215 * {@link INPUT_REPEAT_INTERCEPTOR} Interceptor repeatedly created for an application.\n 1216 * {@link INPUT_SERVICE_EXCEPTION} Failed to add the interceptor because the service is exception.\n 1217 * @syscap SystemCapability.MultimodalInput.Input.Core 1218 * @since 12 1219 */ 1220 Input_Result OH_Input_AddKeyEventInterceptor(Input_KeyEventCallback callback, Input_InterceptorOptions *option); 1221 1222 /** 1223 * @brief Adds an interceptor for input events, including mouse, touch, and axis events. 1224 * If multiple interceptors are added, only the first one takes effect. 1225 * 1226 * @permission ohos.permission.INTERCEPT_INPUT_EVENT 1227 * @param callback - Pointer to the structure of the callback for the input event interceptor. 1228 * For details, see {@Link Input_InterceptorEventCallback}. 1229 * @param option - Options for event interception. If **null** is passed, the default value is used. 1230 * @return OH_Input_AddInputEventInterceptor function result code. 1231 * {@link INPUT_SUCCESS} Adds an interceptor for input events success.\n 1232 * {@link INPUT_PERMISSION_DENIED} Permission verification failed.\n 1233 * {@link INPUT_PARAMETER_ERROR} The callback is NULL.\n 1234 * {@link INPUT_REPEAT_INTERCEPTOR} Interceptor repeatedly created for an application.\n 1235 * {@link INPUT_SERVICE_EXCEPTION} Failed to add the interceptor because the service is exception.\n 1236 * @syscap SystemCapability.MultimodalInput.Input.Core 1237 * @since 12 1238 */ 1239 Input_Result OH_Input_AddInputEventInterceptor(Input_InterceptorEventCallback *callback, 1240 Input_InterceptorOptions *option); 1241 1242 /** 1243 * @brief Removes a key event interceptor. 1244 * 1245 * @permission ohos.permission.INTERCEPT_INPUT_EVENT 1246 * @return OH_Input_RemoveKeyEventInterceptor function result code. 1247 * {@link INPUT_SUCCESS}Removes a key event interceptor success.\n 1248 * {@link INPUT_PERMISSION_DENIED} Permission verification failed.\n 1249 * {@link INPUT_SERVICE_EXCEPTION} Failed to remove the interceptor because the service is exception.\n 1250 * @syscap SystemCapability.MultimodalInput.Input.Core 1251 * @since 12 1252 */ 1253 Input_Result OH_Input_RemoveKeyEventInterceptor(void); 1254 1255 /** 1256 * @brief Removes an interceptor for input events, including mouse, touch, and axis events. 1257 * 1258 * @permission ohos.permission.INTERCEPT_INPUT_EVENT 1259 * @return OH_Input_RemoveInputEventInterceptor function result code. 1260 * {@link INPUT_SUCCESS} Removes an interceptor for input events success.\n 1261 * {@link INPUT_PERMISSION_DENIED} Permission verification failed.\n 1262 * {@link INPUT_SERVICE_EXCEPTION} Failed to remove the interceptor because the service is exception.\n 1263 * @syscap SystemCapability.MultimodalInput.Input.Core 1264 * @since 12 1265 */ 1266 Input_Result OH_Input_RemoveInputEventInterceptor(void); 1267 1268 /** 1269 * @brief Creates a hot key object. 1270 * 1271 * @return Returns an {@Link Input_Hotkey} pointer object if the operation is successful. Otherwise, a null pointer is 1272 * returned. The possible cause is memory allocation failure. 1273 * @syscap SystemCapability.MultimodalInput.Input.Core 1274 * @since 14 1275 */ 1276 Input_Hotkey *OH_Input_CreateHotkey(void); 1277 1278 /** 1279 * @brief Destroys a hot key object. 1280 * 1281 * @param hotkey Hot key object. 1282 * @syscap SystemCapability.MultimodalInput.Input.Core 1283 * @since 14 1284 */ 1285 void OH_Input_DestroyHotkey(Input_Hotkey **hotkey); 1286 1287 /** 1288 * @brief Sets a modifier key. 1289 * 1290 * @param hotkey Hotkey key object. 1291 * @param preKeys List of modifier keys. 1292 * @param size Number of modifier keys. One or two modifier keys are supported. 1293 * @syscap SystemCapability.MultimodalInput.Input.Core 1294 * @since 14 1295 */ 1296 void OH_Input_SetPreKeys(Input_Hotkey *hotkey, int32_t *preKeys, int32_t size); 1297 1298 /** 1299 * @brief Obtains a modifier key. 1300 * 1301 * @param hotkey Hotkey key object. 1302 * @param preKeys List of modifier keys. 1303 * @param preKeyCount Number of modifier keys. 1304 * @return OH_Input_GetPreKeys status code, specifically, 1305 * {@link INPUT_SUCCESS} if the operation is successful;\n 1306 * {@link INPUT_PARAMETER_ERROR} The hotkey is NULL or the pressedKeys is NULL or the pressedKeyCount 1307 * is NULL;\n 1308 * {@Link INPUT_DEVICE_NOT_SUPPORTED} Capability not supported.\n 1309 * @syscap SystemCapability.MultimodalInput.Input.Core 1310 * @since 14 1311 */ 1312 Input_Result OH_Input_GetPreKeys(const Input_Hotkey *hotkey, int32_t **preKeys, int32_t *preKeyCount); 1313 1314 /** 1315 * @brief Sets a modified key. 1316 * 1317 * @param hotkey Hotkey key object. 1318 * @param finalKey Modified key. Only one modified key is supported. 1319 * @syscap SystemCapability.MultimodalInput.Input.Core 1320 * @since 14 1321 */ 1322 void OH_Input_SetFinalKey(Input_Hotkey *hotkey, int32_t finalKey); 1323 1324 /** 1325 * @brief Obtains a modified key. 1326 * 1327 * @param hotkey Hotkey key object. 1328 * @param finalKeyCode Returns the key value of the decorated key. 1329 * @return OH_Input_GetfinalKey status code, specifically, 1330 * {@link INPUT_SUCCESS} if the operation is successful;\n 1331 * {@link INPUT_PARAMETER_ERROR} The hotkey is NULL or the finalKeyCode is NULL;\n 1332 * {@Link INPUT_DEVICE_NOT_SUPPORTED} Capability not supported.\n 1333 * @syscap SystemCapability.MultimodalInput.Input.Core 1334 * @since 14 1335 */ 1336 Input_Result OH_Input_GetFinalKey(const Input_Hotkey *hotkey, int32_t *finalKeyCode); 1337 1338 /** 1339 * @brief Creates an array of {@Link Input_Hotkey} instances. 1340 * 1341 * @param count Number of {@Link Input_Hotkey} instances to be created. The count must be the same as the number of 1342 * system shortcut keys. 1343 * @return If the operation is successful, the pointer to an array of {@Link Input_Hotkey} instances is returned. 1344 * If the operation fails, a null pointer is returned. The possible cause is memory allocation failure or count is 1345 * not equal to the number of system hotkeys. 1346 * @syscap SystemCapability.MultimodalInput.Input.Core 1347 * @since 14 1348 */ 1349 Input_Hotkey **OH_Input_CreateAllSystemHotkeys(int32_t count); 1350 1351 /** 1352 * @brief Destroys an array of {@link Input_Hotkey} instances and reclaims memory. 1353 * 1354 * @param hotkeys Pointer to an array of {@Link Input_Hotkey } instances created by the 1355 * {@Link OH_Input_CreateAllSystemHotkeys} method. 1356 * @param count Count of the array to be destroyed, which must be the same as the number of system shortcut keys. 1357 * @syscap SystemCapability.MultimodalInput.Input.Core 1358 * @since 14 1359 */ 1360 void OH_Input_DestroyAllSystemHotkeys(Input_Hotkey **hotkeys, int32_t count); 1361 1362 /** 1363 * @brief Obtains all hot keys supported by the system. 1364 * 1365 * @param hotkey Array of {@Link Input_Hotkey} instances. 1366 * When calling this API for the first time, you can pass NULL to obtain the array length. 1367 * @param count Number of hot keys supported by the system. 1368 * @return OH_Input_GetAllSystemHotkeys status code, specifically, 1369 * {@link INPUT_SUCCESS} if the operation is successful;\n 1370 * {@link INPUT_PARAMETER_ERROR} The hotkey or count is NULL, or the value of count does not match the number 1371 * of system shortcut keys supported by the system;\n 1372 * {@Link INPUT_DEVICE_NOT_SUPPORTED} Capability not supported.\n 1373 * @syscap SystemCapability.MultimodalInput.Input.Core 1374 * @since 14 1375 */ 1376 Input_Result OH_Input_GetAllSystemHotkeys(Input_Hotkey **hotkey, int32_t *count); 1377 1378 /** 1379 * @brief Specifies whether to report repeated key events. 1380 * 1381 * @param hotkey Shortcut key object. 1382 * @param isRepeat Whether to report repeated key events. 1383 * The value <b>true</b> means to report repeated key events, and the value <b>false</b> means the opposite. 1384 * @syscap SystemCapability.MultimodalInput.Input.Core 1385 * @since 14 1386 */ 1387 void OH_Input_SetRepeat(Input_Hotkey* hotkey, bool isRepeat); 1388 1389 /** 1390 * @brief Checks whether to report repeated key events. 1391 * 1392 * @param hotkey Shortcut key object. 1393 * @param isRepeat Whether a key event is repeated. 1394 * @return OH_Input_GetRepeat status code, specifically, 1395 * {@link INPUT_SUCCESS} if the operation is successful;\n 1396 * {@link INPUT_PARAMETER_ERROR} otherwise;\n 1397 * {@Link INPUT_DEVICE_NOT_SUPPORTED} Capability not supported.\n 1398 * @syscap SystemCapability.MultimodalInput.Input.Core 1399 * @since 14 1400 */ 1401 Input_Result OH_Input_GetRepeat(const Input_Hotkey* hotkey, bool *isRepeat); 1402 1403 /** 1404 * @brief Subscribes to shortcut key events. 1405 * 1406 * @param hotkey Shortcut key object. 1407 * @param callback Callback used to return shortcut key events. 1408 * @return OH_Input_AddHotkeyMonitor status code, specifically, 1409 * {@link INPUT_SUCCESS} if the operation is successful;\n 1410 * {@link INPUT_PARAMETER_ERROR} if hotkey or callback is NULL;\n 1411 * {@Link INPUT_DEVICE_NOT_SUPPORTED} Capability not supported;\n 1412 * {@link INPUT_HOTKEY_ALREADY_REGISTER} Subscription has been enabled;\n 1413 * {@link INPUT_REPEAT_INTERCEPTOR} The shortcut key has been occupied. 1414 * You can use {@link getAllSystemHotkeys} to query all system shortcut keys.\n 1415 * @syscap SystemCapability.MultimodalInput.Input.Core 1416 * @since 14 1417 */ 1418 Input_Result OH_Input_AddHotkeyMonitor(const Input_Hotkey* hotkey, Input_HotkeyCallback callback); 1419 1420 /** 1421 * @brief Unsubscribes from shortcut key events. 1422 * 1423 * @param hotkey Shortcut key object. 1424 * @param callback Callback used to return shortcut key events. 1425 * @return OH_Input_RemoveHotkeyMonitor status code, specifically, 1426 * {@link INPUT_SUCCESS} if the operation is successful;\n 1427 * {@link INPUT_PARAMETER_ERROR} if hotkey or callback is NULL;\n 1428 * {@Link INPUT_DEVICE_NOT_SUPPORTED} Capability not supported.\n 1429 * @syscap SystemCapability.MultimodalInput.Input.Core 1430 * @since 14 1431 */ 1432 Input_Result OH_Input_RemoveHotkeyMonitor(const Input_Hotkey* hotkey, Input_HotkeyCallback callback); 1433 1434 /** 1435 * @brief Obtains the IDs of all input devices. 1436 * 1437 * @param deviceIds Array of input device IDs. 1438 * @param inSize Size of the array of input device IDs. 1439 * @param outSize Length of the list of input device IDs. The value cannot be greater than the value of inSize. 1440 * @return OH_Input_GetDeviceIds result code, specifically, 1441 * {@link INPUT_SUCCESS} if the operation is successful; 1442 * {@link INPUT_PARAMETER_ERROR} if deviceIds or outSize is a null pointer or inSize is less than 0. 1443 * @syscap SystemCapability.MultimodalInput.Input.Core 1444 * @since 13 1445 */ 1446 Input_Result OH_Input_GetDeviceIds(int32_t *deviceIds, int32_t inSize, int32_t *outSize); 1447 1448 /** 1449 * @brief Obtains the information about an input device. 1450 * 1451 * @param deviceId Device ID. 1452 * @param deviceInfo Pointer to an {@Link Input_DeviceInfo} object. 1453 * @return OH_Input_GetDevice result code, specifically, 1454 * {@link INPUT_SUCCESS} if the operation is successful; 1455 * {@link INPUT_PARAMETER_ERROR} if the deviceInfo is a null pointer or the deviceId is invalid. 1456 * You can use the {@Link OH_Input_GetDeviceIds} interface to query the device IDs supported by the system. 1457 * @syscap SystemCapability.MultimodalInput.Input.Core 1458 * @since 13 1459 */ 1460 Input_Result OH_Input_GetDevice(int32_t deviceId, Input_DeviceInfo **deviceInfo); 1461 1462 /** 1463 * @brief Creates a deviceInfo object. 1464 * 1465 * @return Pointer to an {@Link Input_DeviceInfo} object if the operation is successful; 1466 * a null pointer otherwise (possibly because of a memory allocation failure). 1467 * @syscap SystemCapability.MultimodalInput.Input.Core 1468 * @since 13 1469 */ 1470 Input_DeviceInfo* OH_Input_CreateDeviceInfo(void); 1471 1472 /** 1473 * @brief Destroys a deviceInfo object. 1474 * 1475 * @param deviceInfo information object. For details, see {@Link Input_DeviceInfo}. 1476 * @syscap SystemCapability.MultimodalInput.Input.Core 1477 * @since 13 1478 */ 1479 void OH_Input_DestroyDeviceInfo(Input_DeviceInfo **deviceInfo); 1480 1481 /** 1482 * @brief Obtains the keyboard type of an input device. 1483 * 1484 * @param deviceId Device ID. 1485 * @param keyboardType Pointer to the keyboard type of the input device. 1486 * @return OH_Input_GetKeyboardType result code, specifically, 1487 * {@link INPUT_SUCCESS} if the operation is successful; 1488 * {@link INPUT_PARAMETER_ERROR} if the device ID is invalid or keyboardType is a null pointer. 1489 * @syscap SystemCapability.MultimodalInput.Input.Core 1490 * @since 13 1491 */ 1492 Input_Result OH_Input_GetKeyboardType(int32_t deviceId, int32_t *keyboardType); 1493 1494 /** 1495 * @brief Obtains the ID of an input device. 1496 * 1497 * @param deviceInfo information object. For details, see {@Link Input_DeviceInfo}. 1498 * @param id Pointer to the ID of the input device. 1499 * @return OH_Input_GetDeviceId result code, specifically, 1500 * {@link INPUT_SUCCESS} if the operation is successful; 1501 * {@link INPUT_PARAMETER_ERROR} if deviceInfo or id is a null pointer. 1502 * @syscap SystemCapability.MultimodalInput.Input.Core 1503 * @since 13 1504 */ 1505 Input_Result OH_Input_GetDeviceId(Input_DeviceInfo *deviceInfo, int32_t *id); 1506 1507 /** 1508 * @brief Obtains the name of an input device. 1509 * 1510 * @param deviceInfo information object. For details, see {@Link Input_DeviceInfo}. 1511 * @param name Pointer to the name of the input device. 1512 * @return OH_Input_GetDeviceName result code, specifically, 1513 * {@link INPUT_SUCCESS} if the operation is successful; 1514 * {@link INPUT_PARAMETER_ERROR} if deviceInfo or name is a null pointer. 1515 * @syscap SystemCapability.MultimodalInput.Input.Core 1516 * @since 13 1517 */ 1518 Input_Result OH_Input_GetDeviceName(Input_DeviceInfo *deviceInfo, char **name); 1519 1520 /** 1521 * @brief Obtains the capabilities of an input device, for example, a touchscreen, touchpad, or keyboard. 1522 * 1523 * @param deviceInfo information object. For details, see {@Link Input_DeviceInfo}. 1524 * @param capabilities Pointer to the capabilities of the input device. 1525 * @return OH_Input_GetCapabilities result code, specifically, 1526 * {@link INPUT_SUCCESS} if the operation is successful; 1527 * {@link INPUT_PARAMETER_ERROR} if deviceInfo or capabilities is a null pointer. 1528 * @syscap SystemCapability.MultimodalInput.Input.Core 1529 * @since 13 1530 */ 1531 Input_Result OH_Input_GetCapabilities(Input_DeviceInfo *deviceInfo, int32_t *capabilities); 1532 1533 /** 1534 * @brief Obtains the version information of an input device. 1535 * 1536 * @param deviceInfo information object. For details, see {@Link Input_DeviceInfo}. 1537 * @param version Pointer to the version information of the input device. 1538 * @return OH_Input_GetDeviceVersion result code, specifically, 1539 * {@link INPUT_SUCCESS} if the operation is successful; 1540 * {@link INPUT_PARAMETER_ERROR} if deviceInfo or version is a null pointer. 1541 * @syscap SystemCapability.MultimodalInput.Input.Core 1542 * @since 13 1543 */ 1544 Input_Result OH_Input_GetDeviceVersion(Input_DeviceInfo *deviceInfo, int32_t *version); 1545 1546 /** 1547 * @brief Obtains the product information of an input device. 1548 * 1549 * @param deviceInfo information object. For details, see {@Link Input_DeviceInfo}. 1550 * @param product Pointer to the product information of the input device. 1551 * @return OH_Input_GetDeviceProduct result code, specifically, 1552 * {@link INPUT_SUCCESS} if the operation is successful; 1553 * {@link INPUT_PARAMETER_ERROR} if deviceInfo or product is a null pointer. 1554 * @syscap SystemCapability.MultimodalInput.Input.Core 1555 * @since 13 1556 */ 1557 Input_Result OH_Input_GetDeviceProduct(Input_DeviceInfo *deviceInfo, int32_t *product); 1558 1559 /** 1560 * @brief Obtains the vendor information of an input device. 1561 * 1562 * @param deviceInfo information object. For details, see {@Link Input_DeviceInfo}. 1563 * @param vendor Pointer to the vendor information of the input device. 1564 * @return OH_Input_GetDeviceVendor result code, specifically, 1565 * {@link INPUT_SUCCESS} if the operation is successful; 1566 * {@link INPUT_PARAMETER_ERROR} if deviceInfo or vendor is a null pointer. 1567 * @syscap SystemCapability.MultimodalInput.Input.Core 1568 * @since 13 1569 */ 1570 Input_Result OH_Input_GetDeviceVendor(Input_DeviceInfo *deviceInfo, int32_t *vendor); 1571 1572 /** 1573 * @brief Obtains the physical address of an input device. 1574 * 1575 * @param deviceInfo information object. For details, see {@Link Input_DeviceInfo}. 1576 * @param address Pointer to the physical address of the input device. 1577 * @return OH_Input_GetDeviceAddress result code, specifically, 1578 * {@link INPUT_SUCCESS} if the operation is successful; 1579 * {@link INPUT_PARAMETER_ERROR} if deviceInfo or address is a null pointer. 1580 * @syscap SystemCapability.MultimodalInput.Input.Core 1581 * @since 13 1582 */ 1583 Input_Result OH_Input_GetDeviceAddress(Input_DeviceInfo *deviceInfo, char **address); 1584 1585 /** 1586 * @brief Registers a listener for device hot swap events. 1587 * 1588 * @param listener Pointer to an {@Link Input_DeviceListener} object. 1589 * 1590 * @return OH_Input_RegisterDeviceListener status code, specifically, 1591 * {@link INPUT_SUCCESS} if the operation is successful;\n 1592 * {@link INPUT_PARAMETER_ERROR} if listener is NULL; 1593 * @syscap SystemCapability.MultimodalInput.Input.Core 1594 * @since 13 1595 */ 1596 Input_Result OH_Input_RegisterDeviceListener(Input_DeviceListener* listener); 1597 1598 /** 1599 * @brief Unregisters the listener for device hot swap events. 1600 * 1601 * @param listener Pointer to the listener for device hot swap events. For details, see {@Link Input_DeviceListener}. 1602 * 1603 * @return OH_Input_UnregisterDeviceListener status code, specifically, 1604 * {@link INPUT_SUCCESS} if the operation is successful;\n 1605 * {@link INPUT_PARAMETER_ERROR} if listener is NULL or no listener is registered; 1606 * {@link INPUT_SERVICE_EXCEPTION} if the service is abnormal. 1607 * @syscap SystemCapability.MultimodalInput.Input.Core 1608 * @since 13 1609 */ 1610 Input_Result OH_Input_UnregisterDeviceListener(Input_DeviceListener* listener); 1611 1612 /** 1613 * @brief Unregisters the listener for all device hot swap events. 1614 * 1615 * @return OH_Input_UnregisterDeviceListener status code, specifically, 1616 * {@link INPUT_SUCCESS} if the operation is successful;\n 1617 * {@link INPUT_SERVICE_EXCEPTION} if the service is abnormal. 1618 * @syscap SystemCapability.MultimodalInput.Input.Core 1619 * @since 13 1620 */ 1621 Input_Result OH_Input_UnregisterDeviceListeners(void); 1622 1623 /** 1624 * @brief Obtains the interval since the last system input event. 1625 * 1626 * @param timeInterval Interval, in microseconds. 1627 * @return OH_Input_GetIntervalSinceLastInput status code, specifically, 1628 * {@Link INPUT_SUCCESS} if the Operation is successful; 1629 * {@Link INPUT_SERVICE_EXCEPTION} otherwise. 1630 * @syscap SystemCapability.MultimodalInput.Input.Core 1631 * @since 13 1632 */ 1633 int32_t OH_Input_GetIntervalSinceLastInput(int64_t *timeInterval); 1634 #ifdef __cplusplus 1635 } 1636 #endif 1637 /** @} */ 1638 1639 #endif /* OH_INPUT_MANAGER_H */ 1640