1# @ohos.multimodalInput.inputMonitor (Input Monitor) (System API) 2 3The **inputMonitor** module implements listening for events of input devices, including the touchscreen, mouse, touchpad, etc. 4 5>**NOTE** 6> 7>- The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9>- In this document, **global** indicates the entire touchscreen or touchpad. For example, listening for global touch events means to listen for touch events of the entire touchpad when a user touches at any position on the touchpad. 10> 11>- The APIs provided by this module are system APIs. 12 13## Modules to Import 14 15```js 16import { inputMonitor } from '@kit.InputKit'; 17``` 18 19## inputMonitor.on('touch') 20 21on(type: 'touch', receiver: TouchEventReceiver): void 22 23Enables listening for global touch (touchscreen) events. 24 25**Required permissions**: ohos.permission.INPUT_MONITORING 26 27**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 28 29**Parameters** 30 31| Name | Type | Mandatory | Description | 32| -------- | ---------------------------------------- | ---- | ------------------- | 33| type | string | Yes | Event type. This field has a fixed value of **touch**.| 34| receiver | [TouchEventReceiver](#toucheventreceiver) | Yes | Callback used to return touch events asynchronously.| 35 36**Error codes** 37 38For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 39 40| ID | Error Message | 41| ---- | --------------------- | 42| 201 | Permission denied. | 43| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 44 45**Example** 46 47```js 48import { TouchEvent } from '@kit.InputKit'; 49try { 50 inputMonitor.on('touch', (touchEvent: TouchEvent) => { 51 console.log(`Monitor on success ${JSON.stringify(touchEvent)}`); 52 return false; 53 }); 54} catch (error) { 55 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 56} 57``` 58 59## inputMonitor.on('mouse')<sup>9+</sup> 60 61on(type: 'mouse', receiver: Callback<MouseEvent>): void 62 63Enables listening for global mouse events. 64 65**Required permissions**: ohos.permission.INPUT_MONITORING 66 67**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 68 69**Parameters** 70 71| Name | Type | Mandatory | Description | 72| -------- | -------------------------- | ---- | ------------------- | 73| type | string | Yes | Event type. This field has a fixed value of **mouse**.| 74| receiver | Callback<[MouseEvent](js-apis-mouseevent.md#mouseevent)> | Yes | Callback used to return mouse events asynchronously. | 75 76**Error codes** 77 78For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 79 80| ID | Error Message | 81| ---- | --------------------- | 82| 201 | Permission denied. | 83| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 84 85**Example** 86 87```js 88import { MouseEvent } from '@kit.InputKit'; 89 90try { 91 inputMonitor.on('mouse', (mouseEvent: MouseEvent) => { 92 console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`); 93 return false; 94 }); 95} catch (error) { 96 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 97} 98``` 99 100## inputMonitor.on('mouse')<sup>11+</sup> 101 102on(type: 'mouse', rect: display.Rect[], receiver: Callback<MouseEvent>): void 103 104Enables listening for mouse events. When the mouse pointer moves to the specified rectangular area, a callback is triggered. 105 106**Required permissions**: ohos.permission.INPUT_MONITORING 107 108**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 109 110**Parameters** 111 112| Name | Type | Mandatory | Description | 113| -------- | -------------------------- | ---- | ------------------- | 114| type | string | Yes | Event type. This field has a fixed value of **mouse**.| 115| rect | display.Rect[] | Yes | Rectangular area where a callback is triggered. One or two rectangular areas can be specified.| 116| receiver | Callback<[MouseEvent](js-apis-mouseevent.md#mouseevent)> | Yes | Callback used to return mouse events asynchronously. | 117 118**Error codes** 119 120For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 121 122| ID | Error Message | 123| ---- | --------------------- | 124| 201 | Permission denied. | 125| 202 | SystemAPI permission error. | 126| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 127 128**Example** 129 130```js 131import { MouseEvent } from '@kit.InputKit'; 132import { promptAction } from '@kit.ArkUI'; 133import { display } from '@kit.ArkUI'; 134 135/** 136 * Callback triggered when the mouse pointer moves to the specified rectangular area. 137 */ 138function callback(mouseEvent : MouseEvent) { 139 promptAction.showToast({ 140 message: `Monitor on success: ${JSON.stringify(mouseEvent)}` 141 }) 142 console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`); 143 return false; 144}; 145 146/** 147 * Rectangular area where a callback is triggered. 148 */ 149let rect: display.Rect[] = [{ 150 left: 100, 151 top: 100, 152 width: 100, 153 height: 100 154}, { 155 left: 600, 156 top: 100, 157 width: 100, 158 height: 100 159}]; 160 161try { 162 inputMonitor.on('mouse', rect, callback); 163} catch (error) { 164 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 165} 166``` 167 168## inputMonitor.off('touch') 169 170off(type: 'touch', receiver?: TouchEventReceiver): void 171 172Disables listening for global touch (touchscreen) events. 173 174**Required permissions**: ohos.permission.INPUT_MONITORING 175 176**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 177 178**Parameters** 179 180| Name | Type | Mandatory | Description | 181| -------- | ---------------------------------------- | ---- | ------------------- | 182| type | string | Yes | Event type. This field has a fixed value of **touch**.| 183| receiver | [TouchEventReceiver](#toucheventreceiver) | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application. | 184 185**Error codes** 186 187For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 188 189| ID | Error Message | 190| ---- | --------------------- | 191| 201 | Permission denied. | 192| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 193 194**Example** 195 196```js 197import { TouchEvent } from '@kit.InputKit'; 198// Disable listening for a single callback. 199let callback = (touchEvent: TouchEvent) => { 200 console.log(`Monitor on success ${JSON.stringify(touchEvent)}`); 201 return false; 202}; 203try { 204 inputMonitor.on('touch', callback); 205 inputMonitor.off('touch', callback); 206 console.log(`Monitor off success`); 207} catch (error) { 208 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 209} 210``` 211 212```js 213import { TouchEvent } from '@kit.InputKit'; 214// Disable listening for all callbacks. 215let callback = (touchEvent: TouchEvent) => { 216 console.log(`Monitor on success ${JSON.stringify(touchEvent)}`); 217 return false; 218}; 219try { 220 inputMonitor.on('touch', callback); 221 inputMonitor.off('touch'); 222 console.log(`Monitor off success`); 223} catch (error) { 224 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 225} 226``` 227 228## inputMonitor.off('mouse')<sup>9+</sup> 229 230off(type: 'mouse', receiver?: Callback<MouseEvent>): void 231 232Disables listening for global mouse events. 233 234**Required permissions**: ohos.permission.INPUT_MONITORING 235 236**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 237 238**Parameters** 239 240| Name | Type | Mandatory | Description | 241| -------- | -------------------------- | ---- | ------------------- | 242| type | string | Yes | Event type. This field has a fixed value of **mouse**.| 243| receiver | Callback<MouseEvent> | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.| 244 245**Error codes** 246 247For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 248 249| ID | Error Message | 250| ---- | --------------------- | 251| 201 | Permission denied. | 252| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 253 254**Example** 255 256```js 257import { MouseEvent } from '@kit.InputKit'; 258// Disable listening for a single callback. 259let callback = (mouseEvent: MouseEvent) => { 260 console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`); 261 return false; 262}; 263try { 264 inputMonitor.on('mouse', callback); 265 inputMonitor.off('mouse', callback); 266 console.log(`Monitor off success`); 267} catch (error) { 268 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 269} 270``` 271 272```js 273import { MouseEvent } from '@kit.InputKit'; 274// Disable listening for all callbacks. 275let callback = (mouseEvent: MouseEvent) => { 276 console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`); 277 return false; 278}; 279try { 280 inputMonitor.on('mouse', callback); 281 inputMonitor.off('mouse'); 282 console.log(`Monitor off success`); 283} catch (error) { 284 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 285} 286``` 287 288## TouchEventReceiver 289 290(touchEvent: TouchEvent): Boolean 291 292Defines the callback for touch (touchscreen) events. 293 294**Required permissions**: ohos.permission.INPUT_MONITORING 295 296**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 297 298**Parameters** 299 300| Name | Type | Mandatory | Description | 301| ---------- | ---------------------------------------- | ---- | ---------------------------------------- | 302| touchEvent | [TouchEvent](js-apis-touchevent.md#touchevent) | Yes | Touch event.| 303 304**Return value** 305 306| Type | Description | 307| ------- | ---------------------------------------- | 308| Boolean | Result indicating whether the touch event will be dispatched to the window. The value **true** indicates that the touch event will be dispatched to the window, and the value **false** indicates the opposite.| 309 310**Example** 311 312```js 313import { TouchEvent } from '@kit.InputKit'; 314try { 315 inputMonitor.on('touch', touchEvent => { 316 if (touchEvent.touches.length == 3) {// Three fingers are pressed. 317 return true; 318 } 319 return false; 320 }); 321} catch (error) { 322 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 323} 324``` 325 326## inputMonitor.on('pinch')<sup>10+</sup> 327 328on(type: 'pinch', receiver: Callback<[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)>): void 329 330Enables listening for global touchpad pinch events. 331 332**Required permissions**: ohos.permission.INPUT_MONITORING 333 334**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 335 336**Parameters** 337 338| Name | Type | Mandatory | Description | 339| -------- | -------------------------- | ---- | ------------------- | 340| type | string | Yes | Event type. This field has a fixed value of **pinch**.| 341| receiver | Callback<[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)> | Yes | Callback used to return pinch events asynchronously. | 342 343**Error codes** 344 345For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 346 347| ID | Error Message | 348| ---- | --------------------- | 349| 201 | Permission denied. | 350| 202 | SystemAPI permission error. | 351| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 352 353**Example** 354 355```js 356import type { Pinch } from '@kit.InputKit'; 357try { 358 inputMonitor.on('pinch', (pinchEvent) => { 359 console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`); 360 return false; 361 }); 362} catch (error) { 363 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 364} 365``` 366 367## inputMonitor.off('pinch')<sup>10+</sup> 368 369off(type: 'pinch', receiver?: Callback<[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)>): void 370 371Disables listening for global touchpad pinch events. 372 373**Required permissions**: ohos.permission.INPUT_MONITORING 374 375**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 376 377**Parameters** 378 379| Name | Type | Mandatory | Description | 380| -------- | -------------------------- | ---- | ------------------- | 381| type | string | Yes | Event type. This field has a fixed value of **pinch**.| 382| receiver | Callback<[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)> | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.| 383 384**Error codes** 385 386For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 387 388| ID | Error Message | 389| ---- | --------------------- | 390| 201 | Permission denied. | 391| 202 | SystemAPI permission error. | 392| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 393 394**Example** 395 396```js 397// Disable listening for a single callback. 398import { Pinch } from '@kit.InputKit'; 399 400let callback = (pinchEvent: Pinch) => { 401 console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`); 402 return false; 403}; 404try { 405 inputMonitor.on('pinch', callback); 406 inputMonitor.off('pinch', callback); 407 console.log(`Monitor off success`); 408} catch (error) { 409 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 410} 411``` 412 413```js 414// Disable listening for all callbacks. 415import { Pinch } from '@kit.InputKit'; 416 417let callback = (pinchEvent: Pinch) => { 418 console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`); 419 return false; 420}; 421try { 422 inputMonitor.on('pinch', callback); 423 inputMonitor.off('pinch'); 424 console.log(`Monitor off success`); 425} catch (error) { 426 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 427} 428``` 429 430## inputMonitor.on('threeFingersSwipe')<sup>10+</sup> 431 432on(type: 'threeFingersSwipe', receiver: Callback<[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)>): void 433 434Enables listening for three-finger swipe events. 435 436**Required permissions**: ohos.permission.INPUT_MONITORING 437 438**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 439 440**Parameters** 441 442| Name | Type | Mandatory | Description | 443| -------- | -------------------------- | ---- | ------------------- | 444| type | string | Yes | Event type. This field has a fixed value of **threeFingersSwipe**.| 445| receiver | Callback<[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)> | Yes | Callback used to return three-finger swipe events asynchronously. | 446 447**Error codes** 448 449For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 450 451| ID | Error Message | 452| ---- | --------------------- | 453| 201 | Permission denied. | 454| 202 | SystemAPI permission error. | 455| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 456 457**Example** 458 459```js 460try { 461 inputMonitor.on('threeFingersSwipe', (threeFingersSwipe) => { 462 console.log(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`); 463 return false; 464 }); 465} catch (error) { 466 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 467} 468``` 469 470## inputMonitor.off('threeFingersSwipe')<sup>10+</sup> 471 472off(type: 'threeFingersSwipe', receiver?: Callback<[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)>): void 473 474Disables listening for three-finger swipe events. 475 476**Required permissions**: ohos.permission.INPUT_MONITORING 477 478**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 479 480**Parameters** 481 482| Name | Type | Mandatory | Description | 483| -------- | -------------------------- | ---- | ------------------- | 484| type | string | Yes | Event type. This field has a fixed value of **threeFingersSwipe**.| 485| receiver | Callback<[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)> | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.| 486 487**Error codes** 488 489For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 490 491| ID | Error Message | 492| ---- | --------------------- | 493| 201 | Permission denied. | 494| 202 | SystemAPI permission error. | 495| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 496 497**Example** 498 499```js 500// Disable listening for a single callback. 501import { ThreeFingersSwipe } from '@kit.InputKit'; 502 503let callback = (threeFingersSwipe: ThreeFingersSwipe) => { 504 console.log(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`); 505 return false; 506}; 507try { 508 inputMonitor.on('threeFingersSwipe', callback); 509 inputMonitor.off("threeFingersSwipe", callback); 510 console.log(`Monitor off success`); 511} catch (error) { 512 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 513} 514``` 515 516```js 517// Disable listening for all callbacks. 518import { ThreeFingersSwipe } from '@kit.InputKit'; 519 520let callback = (threeFingersSwipe: ThreeFingersSwipe) => { 521 console.log(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`); 522 return false; 523}; 524try { 525 inputMonitor.on("threeFingersSwipe", callback); 526 inputMonitor.off("threeFingersSwipe"); 527 console.log(`Monitor off success`); 528} catch (error) { 529 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 530} 531``` 532 533## inputMonitor.on('fourFingersSwipe')<sup>10+</sup> 534 535on(type: 'fourFingersSwipe', receiver: Callback<[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)>): void 536 537Enables listening for four-finger swipe events. 538 539**Required permissions**: ohos.permission.INPUT_MONITORING 540 541**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 542 543**Parameters** 544 545| Name | Type | Mandatory | Description | 546| -------- | -------------------------- | ---- | ------------------- | 547| type | string | Yes | Event type. This field has a fixed value of **fourFingersSwipe**.| 548| receiver | Callback<[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)> | Yes | Callback used to return four-finger swipe events asynchronously. | 549 550**Error codes** 551 552For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 553 554| ID | Error Message | 555| ---- | --------------------- | 556| 201 | Permission denied. | 557| 202 | SystemAPI permission error. | 558| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 559 560**Example** 561 562```js 563try { 564 inputMonitor.on('fourFingersSwipe', (fourFingersSwipe) => { 565 console.log(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`); 566 return false; 567 }); 568} catch (error) { 569 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 570} 571``` 572 573## inputMonitor.off('fourFingersSwipe')<sup>10+</sup> 574 575off(type: 'fourFingersSwipe', receiver?: Callback<[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)>): void 576 577Disables listening for four-finger swipe events. 578 579**Required permissions**: ohos.permission.INPUT_MONITORING 580 581**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 582 583**Parameters** 584 585| Name | Type | Mandatory | Description | 586| -------- | -------------------------- | ---- | ------------------- | 587| type | string | Yes | Event type. This field has a fixed value of **fourFingersSwipe**.| 588| receiver | Callback<[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)> | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.| 589 590**Error codes** 591 592For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 593 594| ID | Error Message | 595| ---- | --------------------- | 596| 201 | Permission denied. | 597| 202 | SystemAPI permission error. | 598| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 599 600**Example** 601 602```js 603// Disable listening for a single callback. 604import { FourFingersSwipe } from '@kit.InputKit'; 605 606let callback = (fourFingersSwipe: FourFingersSwipe) => { 607 console.log(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`); 608 return false; 609}; 610try { 611 inputMonitor.on('fourFingersSwipe', callback); 612 inputMonitor.off('fourFingersSwipe', callback); 613 console.log(`Monitor off success`); 614} catch (error) { 615 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 616} 617``` 618 619```js 620// Disable listening for all callbacks. 621import { FourFingersSwipe } from '@kit.InputKit'; 622 623let callback = (fourFingersSwipe: FourFingersSwipe) => { 624 console.log(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`); 625 return false; 626}; 627try { 628 inputMonitor.on('fourFingersSwipe', callback); 629 inputMonitor.off('fourFingersSwipe'); 630 console.log(`Monitor off success`); 631} catch (error) { 632 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 633} 634``` 635 636## inputMonitor.on('rotate')<sup>11+</sup> 637 638on(type: 'rotate', fingers: number, receiver: Callback<Rotate>): void 639 640Enables listening for rotation events of the touchpad. 641 642**Required permissions**: ohos.permission.INPUT_MONITORING 643 644**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 645 646**Parameters** 647 648| Name | Type | Mandatory | Description | 649| -------- | -------------------------- | ---- | ------------------- | 650| type | string | Yes | Event type. This field has a fixed value of **rotate**.| 651| fingers | number | Yes | Number of fingers that trigger a rotation. The value must not be greater than **2**.| 652| receiver | Callback<[Rotate](js-apis-multimodalinput-gestureevent.md#rotate)> | Yes | Callback used to return rotation events asynchronously. | 653 654**Error codes** 655 656For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 657 658| ID | Error Message | 659| ---- | --------------------- | 660| 201 | Permission denied. | 661| 202 | SystemAPI permission error. | 662| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 663 664**Example** 665 666```js 667import type { Rotate } from '@kit.InputKit'; 668try { 669 inputMonitor.on('rotate', 2, (rotateEvent: Rotate) => { 670 console.log(`Monitor on success ${JSON.stringify(rotateEvent)}`); 671 return false; 672 }); 673} catch (error) { 674 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 675} 676``` 677 678## inputMonitor.off('rotate')<sup>11+</sup> 679 680off(type: 'rotate', fingers: number, receiver?: Callback<Rotate>): void 681 682Disables listening for rotation events of the touchpad. 683 684**Required permissions**: ohos.permission.INPUT_MONITORING 685 686**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 687 688**Parameters** 689 690| Name | Type | Mandatory | Description | 691| -------- | -------------------------- | ---- | ------------------- | 692| type | string | Yes | Event type. This field has a fixed value of **rotate**.| 693| fingers | number | Yes | Number of fingers that trigger a rotation. The value must not be greater than **2**.| 694| receiver | Callback<[Rotate](js-apis-multimodalinput-gestureevent.md#rotate)> | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.| 695 696**Error codes** 697 698For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 699 700| ID | Error Message | 701| ---- | --------------------- | 702| 201 | Permission denied. | 703| 202 | SystemAPI permission error. | 704| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 705 706**Example** 707 708```js 709// Disable listening for a single callback. 710import { Rotate } from '@kit.InputKit'; 711 712let callback = (rotateEvent: Rotate) => { 713 console.log(`Monitor on success ${JSON.stringify(rotateEvent)}`); 714 return false; 715}; 716try { 717 inputMonitor.on('rotate', 2, callback); 718 inputMonitor.off('rotate', 2, callback); 719 console.log(`Monitor off success`); 720} catch (error) { 721 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 722} 723``` 724 725```js 726// Disable listening for all callbacks. 727import { Rotate } from '@kit.InputKit'; 728 729let callback = (rotateEvent: Rotate) => { 730 console.log(`Monitor on success ${JSON.stringify(rotateEvent)}`); 731 return false; 732}; 733try { 734 inputMonitor.on('rotate', 2, callback); 735 inputMonitor.off('rotate', 2); 736 console.log(`Monitor off success`); 737} catch (error) { 738 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 739} 740``` 741 742## inputMonitor.on('pinch')<sup>11+</sup> 743 744on(type: 'pinch', fingers: number, receiver: Callback<Pinch>): void 745 746Enables listening for global touchpad pinch events. 747 748**Required permissions**: ohos.permission.INPUT_MONITORING 749 750**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 751 752**Parameters** 753 754| Name | Type | Mandatory | Description | 755| -------- | -------------------------- | ---- | ------------------- | 756| type | string | Yes | Event type. This field has a fixed value of **pinch**.| 757| fingers | number | Yes | Number of fingers that trigger the pinch. The value must be greater than or equal to **2**.| 758| receiver | Callback<[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)> | Yes | Callback used to return pinch events asynchronously. | 759 760**Error codes** 761 762For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 763 764| ID | Error Message | 765| ---- | --------------------- | 766| 201 | Permission denied. | 767| 202 | SystemAPI permission error. | 768| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 769 770**Example** 771 772```js 773import type { Pinch } from '@kit.InputKit'; 774try { 775 inputMonitor.on('pinch', 2, (pinchEvent: Pinch) => { 776 console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`); 777 return false; 778 }); 779} catch (error) { 780 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 781} 782``` 783 784## inputMonitor.off('pinch')<sup>11+</sup> 785 786off(type: 'pinch', fingers: number, receiver?: Callback<Pinch>): void 787 788Disables listening for global touchpad pinch events. 789 790**Required permissions**: ohos.permission.INPUT_MONITORING 791 792**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 793 794**Parameters** 795 796| Name | Type | Mandatory | Description | 797| -------- | -------------------------- | ---- | ------------------- | 798| type | string | Yes | Event type. This field has a fixed value of **pinch**.| 799| fingers | number | Yes | Number of fingers that trigger the pinch. The value must be greater than or equal to **2**.| 800| receiver | Callback<[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)> | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.| 801 802**Error codes** 803 804For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 805 806| ID | Error Message | 807| ---- | --------------------- | 808| 201 | Permission denied. | 809| 202 | SystemAPI permission error. | 810| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 811 812**Example** 813 814```js 815// Disable listening for a single callback. 816import { Pinch } from '@kit.InputKit'; 817 818let callback = (pinchEvent: Pinch) => { 819 console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`); 820 return false; 821}; 822try { 823 inputMonitor.on('pinch', 2, callback); 824 inputMonitor.off('pinch', 2, callback); 825 console.log(`Monitor off success`); 826} catch (error) { 827 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 828} 829``` 830 831```js 832// Disable listening for all callbacks. 833import { Pinch } from '@kit.InputKit'; 834 835let callback = (pinchEvent: Pinch) => { 836 console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`); 837 return false; 838}; 839try { 840 inputMonitor.on('pinch', 2, callback); 841 inputMonitor.off('pinch', 2); 842 console.log(`Monitor off success`); 843} catch (error) { 844 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 845} 846``` 847 848## inputMonitor.on('threeFingersTap')<sup>11+</sup> 849 850on(type: 'threeFingersTap', receiver: Callback<[ThreeFingersTap](js-apis-multimodalinput-gestureevent.md#threefingerstap)>): void 851 852Enables listening for three-finger tap events. 853 854**Required permissions**: ohos.permission.INPUT_MONITORING 855 856**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 857 858**Parameters** 859 860| Name | Type | Mandatory| Description | 861| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | 862| type | string | Yes | Event type. This field has a fixed value of **threeFingersTap**.| 863| receiver | Callback<[ThreeFingersTap](js-apis-multimodalinput-gestureevent.md#threefingerstap)> | Yes | Callback used to return three-finger tap events asynchronously. | 864 865**Error codes** 866 867For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 868 869| ID | Error Message | 870| ---- | --------------------- | 871| 201 | Permission denied. | 872| 202 | SystemAPI permission error. | 873| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 874 875**Example** 876 877```js 878try { 879 inputMonitor.on('threeFingersTap', (threeFingersTap) => { 880 console.log(`Monitor on success ${JSON.stringify(threeFingersTap)}`); 881 return false; 882 }); 883} catch (error) { 884 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 885} 886``` 887 888## inputMonitor.off('threeFingersTap')<sup>11+</sup> 889 890off(type: 'threeFingersTap', receiver?: Callback<[ThreeFingersTap](js-apis-multimodalinput-gestureevent.md#threefingerstap)>): void 891 892Disables listening for three-finger tap events. 893 894**Required permissions**: ohos.permission.INPUT_MONITORING 895 896**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 897 898**Parameters** 899 900| Name | Type | Mandatory| Description | 901| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 902| type | string | Yes | Event type. This field has a fixed value of **threeFingersTap**. | 903| receiver | Callback<[ThreeFingersTap](js-apis-multimodalinput-gestureevent.md#threefingerstap)> | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.| 904 905**Error codes** 906 907For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 908 909| ID | Error Message | 910| ---- | --------------------- | 911| 201 | Permission denied. | 912| 202 | SystemAPI permission error. | 913| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 914 915**Example** 916 917```js 918// Disable listening for a single callback. 919import { ThreeFingersTap } from '@kit.InputKit'; 920 921let callback = (threeFingersTap: ThreeFingersTap) => { 922 console.log(`Monitor on success ${JSON.stringify(threeFingersTap)}`); 923 return false; 924}; 925try { 926 inputMonitor.on('threeFingersTap', callback); 927 inputMonitor.off("threeFingersTap", callback); 928 console.log(`Monitor off success`); 929} catch (error) { 930 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 931} 932``` 933 934```js 935// Disable listening for all callbacks. 936import { ThreeFingersTap } from '@kit.InputKit'; 937 938let callback = (threeFingersTap: ThreeFingersTap) => { 939 console.log(`Monitor on success ${JSON.stringify(threeFingersTap)}`); 940 return false; 941}; 942try { 943 inputMonitor.on('threeFingersTap', callback); 944 inputMonitor.off("threeFingersTap"); 945 console.log(`Monitor off success`); 946} catch (error) { 947 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 948} 949``` 950 951## inputMonitor.on('touchscreenSwipe')<sup>14+</sup> 952 953on(type: 'touchscreenSwipe', fingers: number, receiver: Callback<TouchGestureEvent>): void 954 955Enables listening for touchscreen swipe events. 956 957**Required permissions**: ohos.permission.INPUT_MONITORING 958 959**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 960 961**Parameters** 962 963| Name | Type | Mandatory| Description | 964| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 965| type | string | Yes | Event type. This field has a fixed value of **touchscreenSwipe**. | 966| fingers | number | Yes | Number of fingers that trigger the swipe. The value range is [3, 5].| 967| receiver | Callback<[TouchGestureEvent](js-apis-multimodalinput-gestureevent-sys.md#touchgestureevent)> | Yes | Callback used to return touchscreen swipe events asynchronously.| 968 969**Error codes** 970 971For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 972 973| ID | Error Message | 974| ---- | --------------------- | 975| 201 | Permission denied. | 976| 202 | SystemAPI permission error. | 977| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 978 979**Example** 980 981```js 982import inputMonitor from '@ohos.multimodalInput.inputMonitor'; 983import { TouchGestureEvent } from '@ohos.multimodalInput.gestureEvent'; 984 985let fingers: number = 4; 986try { 987 inputMonitor.on('touchscreenSwipe', fingers, (event: TouchGestureEvent) => { 988 console.log(`Monitor on success ${JSON.stringify(event)}`); 989 }); 990} catch (error) { 991 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 992} 993``` 994 995## inputMonitor.off('touchscreenSwipe')<sup>14+</sup> 996 997off(type: 'touchscreenSwipe', fingers: number, receiver?: Callback<TouchGestureEvent>): void 998 999Disables listening for touchscreen swipe events. 1000 1001**Required permissions**: ohos.permission.INPUT_MONITORING 1002 1003**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 1004 1005**Parameters** 1006 1007| Name | Type | Mandatory| Description | 1008| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1009| type | string | Yes | Event type. This field has a fixed value of **touchscreenSwipe**. | 1010| fingers | number | Yes | Number of fingers that trigger the swipe. The value range is [3, 5].| 1011| receiver | Callback<[TouchGestureEvent](js-apis-multimodalinput-gestureevent-sys.md#touchgestureevent)> | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.| 1012 1013**Error codes** 1014 1015For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1016 1017| ID | Error Message | 1018| ---- | --------------------- | 1019| 201 | Permission denied. | 1020| 202 | SystemAPI permission error. | 1021| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 1022 1023**Example** 1024 1025```js 1026// Disable listening for a single callback. 1027import inputMonitor from '@ohos.multimodalInput.inputMonitor'; 1028import { TouchGestureEvent } from '@ohos.multimodalInput.gestureEvent'; 1029 1030let callback = (event: TouchGestureEvent) => { 1031 console.log(`Monitor on success ${JSON.stringify(event)}`); 1032}; 1033let fingers: number = 4; 1034try { 1035 inputMonitor.on('touchscreenSwipe', fingers, callback); 1036 inputMonitor.off('touchscreenSwipe', fingers, callback); 1037} catch (error) { 1038 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 1039} 1040``` 1041 1042```js 1043// Disable listening for all callbacks. 1044import inputMonitor from '@ohos.multimodalInput.inputMonitor'; 1045import { TouchGestureEvent } from '@ohos.multimodalInput.gestureEvent'; 1046 1047let fingers: number = 4; 1048try { 1049 inputMonitor.on('touchscreenSwipe', fingers, (event: TouchGestureEvent) => { 1050 console.log(`Monitor on success ${JSON.stringify(event)}`); 1051 }); 1052 inputMonitor.off('touchscreenSwipe', fingers); 1053} catch (error) { 1054 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 1055} 1056``` 1057 1058## inputMonitor.on('touchscreenPinch')<sup>14+</sup> 1059 1060on(type: 'touchscreenPinch', fingers: number, receiver: Callback<TouchGestureEvent>): void 1061 1062Enables listening for touchscreen pinch events. 1063 1064**Required permissions**: ohos.permission.INPUT_MONITORING 1065 1066**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 1067 1068**Parameters** 1069 1070| Name | Type | Mandatory| Description | 1071| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1072| type | string | Yes | Event type. This field has a fixed value of **touchscreenPinch**. | 1073| fingers | number | Yes | Number of fingers that trigger the pinch. The value range is [4, 5].| 1074| receiver | Callback<[TouchGestureEvent](js-apis-multimodalinput-gestureevent-sys.md#touchgestureevent)> | Yes | Callback used to return touchscreen pinch events asynchronously.| 1075 1076**Error codes** 1077 1078For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1079 1080| ID | Error Message | 1081| ---- | --------------------- | 1082| 201 | Permission denied. | 1083| 202 | SystemAPI permission error. | 1084| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 1085 1086**Example** 1087 1088```js 1089import inputMonitor from '@ohos.multimodalInput.inputMonitor'; 1090import { TouchGestureEvent } from '@ohos.multimodalInput.gestureEvent'; 1091 1092let fingers: number = 4; 1093try { 1094 inputMonitor.on('touchscreenPinch', fingers, (event: TouchGestureEvent) => { 1095 console.log(`Monitor on success ${JSON.stringify(event)}`); 1096 }); 1097} catch (error) { 1098 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 1099} 1100``` 1101 1102## inputMonitor.off('touchscreenPinch')<sup>14+</sup> 1103 1104off(type: 'touchscreenPinch', fingers: number, receiver?: Callback<TouchGestureEvent>): void 1105 1106Disables listening for touchscreen pinch events. 1107 1108**Required permissions**: ohos.permission.INPUT_MONITORING 1109 1110**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 1111 1112**Parameters** 1113 1114| Name | Type | Mandatory| Description | 1115| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1116| type | string | Yes | Event type. This field has a fixed value of **touchscreenPinch**. | 1117| fingers | number | Yes | Number of fingers that trigger the pinch. The value range is [4, 5].| 1118| receiver | Callback<[TouchGestureEvent](js-apis-multimodalinput-gestureevent-sys.md#touchgestureevent)> | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.| 1119 1120**Error codes** 1121 1122For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1123 1124| ID | Error Message | 1125| ---- | --------------------- | 1126| 201 | Permission denied. | 1127| 202 | SystemAPI permission error. | 1128| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 1129 1130**Example** 1131 1132```js 1133// Disable listening for a single callback. 1134import inputMonitor from '@ohos.multimodalInput.inputMonitor'; 1135import { TouchGestureEvent } from '@ohos.multimodalInput.gestureEvent'; 1136 1137let callback = (event: TouchGestureEvent) => { 1138 console.log(`Monitor on success ${JSON.stringify(event)}`); 1139}; 1140let fingers: number = 4; 1141try { 1142 inputMonitor.on('touchscreenPinch', fingers, callback); 1143 inputMonitor.off("touchscreenPinch", fingers, callback); 1144} catch (error) { 1145 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 1146} 1147``` 1148 1149```js 1150// Disable listening for all callbacks. 1151import inputMonitor from '@ohos.multimodalInput.inputMonitor'; 1152import { TouchGestureEvent } from '@ohos.multimodalInput.gestureEvent'; 1153 1154let fingers: number = 4; 1155try { 1156 inputMonitor.on('touchscreenPinch', fingers, (event: TouchGestureEvent) => { 1157 console.log(`Monitor on success ${JSON.stringify(event)}`); 1158 }); 1159 inputMonitor.off("touchscreenPinch", fingers); 1160} catch (error) { 1161 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 1162} 1163``` 1164