1# @ohos.multimodalInput.inputMonitor (Input Monitor) 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>- The APIs provided by this module are system APIs. 10> 11>- 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. 12 13## Modules to Import 14 15```js 16import inputMonitor from '@ohos.multimodalInput.inputMonitor'; 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**Example** 37 38```js 39import { TouchEvent } from '@ohos.multimodalInput.touchEvent'; 40try { 41 inputMonitor.on('touch', (touchEvent: TouchEvent) => { 42 console.log(`Monitor on success ${JSON.stringify(touchEvent)}`); 43 return false; 44 }); 45} catch (error) { 46 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 47} 48``` 49 50## inputMonitor.on('mouse')<sup>9+</sup> 51 52on(type: 'mouse', receiver: Callback<MouseEvent>): void 53 54Enables listening for global mouse events. 55 56**Required permissions**: ohos.permission.INPUT_MONITORING 57 58**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 59 60**Parameters** 61 62| Name | Type | Mandatory | Description | 63| -------- | -------------------------- | ---- | ------------------- | 64| type | string | Yes | Event type. This field has a fixed value of **mouse**.| 65| receiver | Callback<[MouseEvent](./js-apis-mouseevent.md#mouseevent)> | Yes | Callback used to return mouse events asynchronously. | 66 67 **Example** 68 69```js 70import { MouseEvent } from '@ohos.multimodalInput.mouseEvent'; 71 72try { 73 inputMonitor.on('mouse', (mouseEvent: MouseEvent) => { 74 console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`); 75 return false; 76 }); 77} catch (error) { 78 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 79} 80``` 81 82## inputMonitor.on('mouse')<sup>11+</sup> 83 84on(type: 'mouse', rect: display.Rect[], receiver: Callback<MouseEvent>): void 85 86Enables listening for mouse events. When the mouse pointer moves to the specified rectangular area, a callback is triggered. 87 88**Required permissions**: ohos.permission.INPUT_MONITORING 89 90**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 91 92**Parameters** 93 94| Name | Type | Mandatory | Description | 95| -------- | -------------------------- | ---- | ------------------- | 96| type | string | Yes | Event type. This field has a fixed value of **mouse**.| 97| rect | display.Rect[] | Yes | Rectangular area where a callback is triggered. One or two rectangular areas can be specified.| 98| receiver | Callback<[MouseEvent](./js-apis-mouseevent.md#mouseevent)> | Yes | Callback used to return mouse events asynchronously. | 99 100 **Example** 101 102```js 103import { MouseEvent } from '@ohos.multimodalInput.mouseEvent'; 104import promptAction from '@ohos.promptAction' 105import display from '@ohos.display'; 106 107/** 108 * Callback triggered when the mouse pointer moves to the specified rectangular area. 109 */ 110function callback(mouseEvent : MouseEvent) { 111 promptAction.showToast({ 112 message: `Monitor on success: ${JSON.stringify(mouseEvent)}` 113 }) 114 console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`); 115 return false; 116}; 117 118/** 119 * Rectangular area where a callback is triggered. 120 */ 121let rect: display.Rect[] = [{ 122 left: 100, 123 top: 100, 124 width: 100, 125 height: 100 126}, { 127 left: 600, 128 top: 100, 129 width: 100, 130 height: 100 131}]; 132 133try { 134 inputMonitor.on('mouse', rect, callback); 135} catch (error) { 136 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 137} 138``` 139 140## inputMonitor.off('touch') 141 142off(type: 'touch', receiver?: TouchEventReceiver): void 143 144Disables listening for global touch (touchscreen) events. 145 146**Required permissions**: ohos.permission.INPUT_MONITORING 147 148**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 149 150**Parameters** 151 152| Name | Type | Mandatory | Description | 153| -------- | ---------------------------------------- | ---- | ------------------- | 154| type | string | Yes | Event type. This field has a fixed value of **touch**.| 155| 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. | 156 157**Example** 158 159```js 160import { TouchEvent } from '@ohos.multimodalInput.touchEvent'; 161// Disable listening for a single callback. 162let callback = (touchEvent: TouchEvent) => { 163 console.log(`Monitor on success ${JSON.stringify(touchEvent)}`); 164 return false; 165}; 166try { 167 inputMonitor.on('touch', callback); 168 inputMonitor.off('touch', callback); 169 console.log(`Monitor off success`); 170} catch (error) { 171 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 172} 173``` 174 175```js 176import { TouchEvent } from '@ohos.multimodalInput.touchEvent'; 177// Cancel listening for all callbacks. 178let callback = (touchEvent: TouchEvent) => { 179 console.log(`Monitor on success ${JSON.stringify(touchEvent)}`); 180 return false; 181}; 182try { 183 inputMonitor.on('touch', callback); 184 inputMonitor.off('touch'); 185 console.log(`Monitor off success`); 186} catch (error) { 187 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 188} 189``` 190 191## inputMonitor.off('mouse')<sup>9+</sup> 192 193off(type: 'mouse', receiver?: Callback<MouseEvent>): void 194 195Disables listening for global mouse events. 196 197**Required permissions**: ohos.permission.INPUT_MONITORING 198 199**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 200 201**Parameters** 202 203| Name | Type | Mandatory | Description | 204| -------- | -------------------------- | ---- | ------------------- | 205| type | string | Yes | Event type. This field has a fixed value of **mouse**.| 206| 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.| 207 208**Example** 209 210```js 211import { MouseEvent } from '@ohos.multimodalInput.mouseEvent'; 212// Disable listening for a single callback. 213let callback = (mouseEvent: MouseEvent) => { 214 console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`); 215 return false; 216}; 217try { 218 inputMonitor.on('mouse', callback); 219 inputMonitor.off('mouse', callback); 220 console.log(`Monitor off success`); 221} catch (error) { 222 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 223} 224``` 225 226```js 227import { MouseEvent } from '@ohos.multimodalInput.mouseEvent'; 228// Cancel listening for all callbacks. 229let callback = (mouseEvent: MouseEvent) => { 230 console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`); 231 return false; 232}; 233try { 234 inputMonitor.on('mouse', callback); 235 inputMonitor.off('mouse'); 236 console.log(`Monitor off success`); 237} catch (error) { 238 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 239} 240``` 241 242## TouchEventReceiver 243 244Defines the callback for touch (touchscreen) events. 245 246**Required permissions**: ohos.permission.INPUT_MONITORING 247 248**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 249 250**Parameters** 251 252| Name | Type | Mandatory | Description | 253| ---------- | ---------------------------------------- | ---- | ---------------------------------------- | 254| touchEvent | [TouchEvent](./js-apis-touchevent.md#touchevent) | Yes | Touch event.| 255 256**Return value** 257 258| Type | Description | 259| ------- | ---------------------------------------- | 260| 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.| 261 262**Example** 263 264```js 265import { TouchEvent } from '@ohos.multimodalInput.touchEvent'; 266try { 267 inputMonitor.on('touch', touchEvent => { 268 if (touchEvent.touches.length == 3) {// Three fingers are pressed. 269 return true; 270 } 271 return false; 272 }); 273} catch (error) { 274 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 275} 276``` 277 278## inputMonitor.on('pinch')<sup>10+</sup> 279 280on(type: 'pinch', receiver: Callback<[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)>): void 281 282Enables listening for global touchpad pinch events. 283 284**Required permissions**: ohos.permission.INPUT_MONITORING 285 286**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 287 288**Parameters** 289 290| Name | Type | Mandatory | Description | 291| -------- | -------------------------- | ---- | ------------------- | 292| type | string | Yes | Event type. This field has a fixed value of **pinch**.| 293| receiver | Callback<[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)> | Yes | Callback used to return pinch events asynchronously. | 294 295 **Example** 296 297```js 298import type { Pinch } from '@ohos.multimodalInput.gestureEvent'; 299try { 300 inputMonitor.on('pinch', (pinchEvent) => { 301 console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`); 302 return false; 303 }); 304} catch (error) { 305 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 306} 307``` 308 309## inputMonitor.off('pinch')<sup>10+</sup> 310 311off(type: 'pinch', receiver?: Callback<[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)>): void 312 313Disables listening for global touchpad pinch events. 314 315**Required permissions**: ohos.permission.INPUT_MONITORING 316 317**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 318 319**Parameters** 320 321| Name | Type | Mandatory | Description | 322| -------- | -------------------------- | ---- | ------------------- | 323| type | string | Yes | Event type. This field has a fixed value of **pinch**.| 324| 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.| 325 326**Example** 327 328```js 329// Disable listening for a single callback. 330import { Pinch } from '@ohos.multimodalInput.gestureEvent'; 331 332let callback = (pinchEvent: Pinch) => { 333 console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`); 334 return false; 335}; 336try { 337 inputMonitor.on('pinch', callback); 338 inputMonitor.off('pinch', callback); 339 console.log(`Monitor off success`); 340} catch (error) { 341 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 342} 343``` 344 345```js 346// Cancel listening for all callbacks. 347import { Pinch } from '@ohos.multimodalInput.gestureEvent'; 348 349let callback = (pinchEvent: Pinch) => { 350 console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`); 351 return false; 352}; 353try { 354 inputMonitor.on('pinch', callback); 355 inputMonitor.off('pinch'); 356 console.log(`Monitor off success`); 357} catch (error) { 358 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 359} 360``` 361 362## inputMonitor.on('threeFingersSwipe')<sup>10+</sup> 363 364on(type: 'threeFingersSwipe', receiver: Callback<[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)>): void 365 366Enables listening for three-finger swipe events. 367 368**Required permissions**: ohos.permission.INPUT_MONITORING 369 370**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 371 372**Parameters** 373 374| Name | Type | Mandatory | Description | 375| -------- | -------------------------- | ---- | ------------------- | 376| type | string | Yes | Event type. This field has a fixed value of **threeFingersSwipe**.| 377| receiver | Callback<[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)> | Yes | Callback used to return three-finger swipe events asynchronously. | 378 379 **Example** 380 381```js 382try { 383 inputMonitor.on('threeFingersSwipe', (threeFingersSwipe) => { 384 console.log(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`); 385 return false; 386 }); 387} catch (error) { 388 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 389} 390``` 391 392## inputMonitor.off('threeFingersSwipe')<sup>10+</sup> 393 394off(type: 'threeFingersSwipe', receiver?: Callback<[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)>): void 395 396Disables listening for three-finger swipe events. 397 398**Required permissions**: ohos.permission.INPUT_MONITORING 399 400**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 401 402**Parameters** 403 404| Name | Type | Mandatory | Description | 405| -------- | -------------------------- | ---- | ------------------- | 406| type | string | Yes | Event type. This field has a fixed value of **threeFingersSwipe**.| 407| 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.| 408 409**Example** 410 411```js 412// Disable listening for a single callback. 413import { ThreeFingersSwipe } from '@ohos.multimodalInput.gestureEvent'; 414 415let callback = (threeFingersSwipe: ThreeFingersSwipe) => { 416 console.log(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`); 417 return false; 418}; 419try { 420 inputMonitor.on('threeFingersSwipe', callback); 421 inputMonitor.off("threeFingersSwipe", callback); 422 console.log(`Monitor off success`); 423} catch (error) { 424 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 425} 426``` 427 428```js 429// Cancel listening for all callbacks. 430import { ThreeFingersSwipe } from '@ohos.multimodalInput.gestureEvent'; 431 432let callback = (threeFingersSwipe: ThreeFingersSwipe) => { 433 console.log(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`); 434 return false; 435}; 436try { 437 inputMonitor.on("threeFingersSwipe", callback); 438 inputMonitor.off("threeFingersSwipe"); 439 console.log(`Monitor off success`); 440} catch (error) { 441 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 442} 443``` 444 445## inputMonitor.on('fourFingersSwipe')<sup>10+</sup> 446 447on(type: 'fourFingersSwipe', receiver: Callback<[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)>): void 448 449Enables listening for four-finger swipe events. 450 451**Required permissions**: ohos.permission.INPUT_MONITORING 452 453**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 454 455**Parameters** 456 457| Name | Type | Mandatory | Description | 458| -------- | -------------------------- | ---- | ------------------- | 459| type | string | Yes | Event type. This field has a fixed value of **fourFingersSwipe**.| 460| receiver | Callback<[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)> | Yes | Callback used to return four-finger swipe events asynchronously. | 461 462 **Example** 463 464```js 465try { 466 inputMonitor.on('fourFingersSwipe', (fourFingersSwipe) => { 467 console.log(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`); 468 return false; 469 }); 470} catch (error) { 471 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 472} 473``` 474 475## inputMonitor.off('fourFingersSwipe')<sup>10+</sup> 476 477off(type: 'fourFingersSwipe', receiver?: Callback<[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)>): void 478 479Disables listening for four-finger swipe events. 480 481**Required permissions**: ohos.permission.INPUT_MONITORING 482 483**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 484 485**Parameters** 486 487| Name | Type | Mandatory | Description | 488| -------- | -------------------------- | ---- | ------------------- | 489| type | string | Yes | Event type. This field has a fixed value of **fourFingersSwipe**.| 490| 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.| 491 492**Example** 493 494```js 495// Disable listening for a single callback. 496import { FourFingersSwipe } from '@ohos.multimodalInput.gestureEvent'; 497 498let callback = (fourFingersSwipe: FourFingersSwipe) => { 499 console.log(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`); 500 return false; 501}; 502try { 503 inputMonitor.on('fourFingersSwipe', callback); 504 inputMonitor.off('fourFingersSwipe', callback); 505 console.log(`Monitor off success`); 506} catch (error) { 507 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 508} 509``` 510 511```js 512// Cancel listening for all callbacks. 513import { FourFingersSwipe } from '@ohos.multimodalInput.gestureEvent'; 514 515let callback = (fourFingersSwipe: FourFingersSwipe) => { 516 console.log(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`); 517 return false; 518}; 519try { 520 inputMonitor.on('fourFingersSwipe', callback); 521 inputMonitor.off('fourFingersSwipe'); 522 console.log(`Monitor off success`); 523} catch (error) { 524 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 525} 526``` 527 528## inputMonitor.on('rotate')<sup>11+</sup> 529 530on(type: 'rotate', fingers: number, receiver: Callback<Rotate>): void 531 532Enables listening for rotation events of the touchpad. 533 534**Required permissions**: ohos.permission.INPUT_MONITORING 535 536**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 537 538**Parameters** 539 540| Name | Type | Mandatory | Description | 541| -------- | -------------------------- | ---- | ------------------- | 542| type | string | Yes | Event type. This field has a fixed value of **rotate**.| 543| fingers | number | Yes | Number of fingers that trigger a rotation. The value must not be greater than **2**.| 544| receiver | Callback<[Rotate](js-apis-multimodalinput-gestureevent.md#rotate)> | Yes | Callback used to return rotation events asynchronously. | 545 546 **Example** 547 548```js 549import type { Rotate } from '@ohos.multimodalInput.gestureEvent'; 550try { 551 inputMonitor.on('rotate', 2, (rotateEvent: Rotate) => { 552 console.log(`Monitor on success ${JSON.stringify(rotateEvent)}`); 553 return false; 554 }); 555} catch (error) { 556 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 557} 558``` 559 560## inputMonitor.off('rotate')<sup>11+</sup> 561 562off(type: 'rotate', fingers: number, receiver?: Callback<Rotate>): void 563 564Disables listening for rotation events of the touchpad. 565 566**Required permissions**: ohos.permission.INPUT_MONITORING 567 568**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 569 570**Parameters** 571 572| Name | Type | Mandatory | Description | 573| -------- | -------------------------- | ---- | ------------------- | 574| type | string | Yes | Event type. This field has a fixed value of **rotate**.| 575| fingers | number | Yes | Number of fingers that trigger a rotation. The value must not be greater than **2**.| 576| 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.| 577 578**Example** 579 580```js 581// Disable listening for a single callback. 582import { Rotate } from '@ohos.multimodalInput.gestureEvent'; 583 584let callback = (rotateEvent: Rotate) => { 585 console.log(`Monitor on success ${JSON.stringify(rotateEvent)}`); 586 return false; 587}; 588try { 589 inputMonitor.on('rotate', 2, callback); 590 inputMonitor.off('rotate', 2, callback); 591 console.log(`Monitor off success`); 592} catch (error) { 593 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 594} 595``` 596 597```js 598// Cancel listening for all callbacks. 599import { Rotate } from '@ohos.multimodalInput.gestureEvent'; 600 601let callback = (rotateEvent: Rotate) => { 602 console.log(`Monitor on success ${JSON.stringify(rotateEvent)}`); 603 return false; 604}; 605try { 606 inputMonitor.on('rotate', 2, callback); 607 inputMonitor.off('rotate', 2); 608 console.log(`Monitor off success`); 609} catch (error) { 610 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 611} 612``` 613 614## inputMonitor.on('pinch')<sup>11+</sup> 615 616on(type: 'pinch', fingers: number, receiver: Callback<Pinch>): void 617 618Enables listening for global touchpad pinch events. 619 620**Required permissions**: ohos.permission.INPUT_MONITORING 621 622**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 623 624**Parameters** 625 626| Name | Type | Mandatory | Description | 627| -------- | -------------------------- | ---- | ------------------- | 628| type | string | Yes | Event type. This field has a fixed value of **pinch**.| 629| fingers | number | Yes | Number of fingers that trigger the pinch. The value must be greater than or equal to **2**.| 630| receiver | Callback<[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)> | Yes | Callback used to return pinch events asynchronously. | 631 632 **Example** 633 634```js 635import type { Pinch } from '@ohos.multimodalInput.gestureEvent'; 636try { 637 inputMonitor.on('pinch', 2, (pinchEvent: Pinch) => { 638 console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`); 639 return false; 640 }); 641} catch (error) { 642 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 643} 644``` 645 646## inputMonitor.off('pinch')<sup>11+</sup> 647 648off(type: 'pinch', fingers: number, receiver?: Callback<Pinch>): void 649 650Disables listening for global touchpad pinch events. 651 652**Required permissions**: ohos.permission.INPUT_MONITORING 653 654**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 655 656**Parameters** 657 658| Name | Type | Mandatory | Description | 659| -------- | -------------------------- | ---- | ------------------- | 660| type | string | Yes | Event type. This field has a fixed value of **pinch**.| 661| fingers | number | Yes | Number of fingers that trigger the pinch. The value must be greater than or equal to **2**.| 662| 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.| 663 664**Example** 665 666```js 667// Disable listening for a single callback. 668import { Pinch } from '@ohos.multimodalInput.gestureEvent'; 669 670let callback = (pinchEvent: Pinch) => { 671 console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`); 672 return false; 673}; 674try { 675 inputMonitor.on('pinch', 2, callback); 676 inputMonitor.off('pinch', 2, callback); 677 console.log(`Monitor off success`); 678} catch (error) { 679 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 680} 681``` 682 683```js 684// Cancel listening for all callbacks. 685import { Pinch } from '@ohos.multimodalInput.gestureEvent'; 686 687let callback = (pinchEvent: Pinch) => { 688 console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`); 689 return false; 690}; 691try { 692 inputMonitor.on('pinch', 2, callback); 693 inputMonitor.off('pinch', 2); 694 console.log(`Monitor off success`); 695} catch (error) { 696 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 697} 698``` 699 700## inputMonitor.on('threeFingersTap')<sup>11+</sup> 701 702on(type: 'threeFingersTap', receiver: Callback<[ThreeFingersTap](js-apis-multimodalinput-gestureevent.md#threefingerstap)>): void 703 704Enables listening for three-finger tap events. 705 706**Required permissions**: ohos.permission.INPUT_MONITORING 707 708**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 709 710**Parameters** 711 712| Name | Type | Mandatory| Description | 713| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | 714| type | string | Yes | Event type. This field has a fixed value of **threeFingersTap**.| 715| receiver | Callback<[ThreeFingersTap](js-apis-multimodalinput-gestureevent.md#threefingerstap)> | Yes | Callback used to return three-finger tap events asynchronously. | 716 717 **Example** 718 719```js 720try { 721 inputMonitor.on('threeFingersTap', (threeFingersTap) => { 722 console.log(`Monitor on success ${JSON.stringify(threeFingersTap)}`); 723 return false; 724 }); 725} catch (error) { 726 console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 727} 728``` 729 730## inputMonitor.off('threeFingersTap')<sup>11+</sup> 731 732off(type: 'threeFingersTap', receiver?: Callback<[ThreeFingersTap](js-apis-multimodalinput-gestureevent.md#threefingerstap)>): void 733 734Disables listening for three-finger tap events. 735 736**Required permissions**: ohos.permission.INPUT_MONITORING 737 738**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor 739 740**Parameters** 741 742| Name | Type | Mandatory| Description | 743| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 744| type | string | Yes | Event type. This field has a fixed value of **threeFingersTap**. | 745| 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.| 746 747**Example** 748 749```js 750// Disable listening for a single callback. 751import { ThreeFingersTap } from '@ohos.multimodalInput.gestureEvent'; 752 753let callback = (threeFingersTap: ThreeFingersTap) => { 754 console.log(`Monitor on success ${JSON.stringify(threeFingersTap)}`); 755 return false; 756}; 757try { 758 inputMonitor.on('threeFingersTap', callback); 759 inputMonitor.off("threeFingersTap", callback); 760 console.log(`Monitor off success`); 761} catch (error) { 762 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 763} 764``` 765 766```js 767// Cancel listening for all callbacks. 768import { ThreeFingersTap } from '@ohos.multimodalInput.gestureEvent'; 769 770let callback = (threeFingersTap: ThreeFingersTap) => { 771 console.log(`Monitor on success ${JSON.stringify(threeFingersTap)}`); 772 return false; 773}; 774try { 775 inputMonitor.on('threeFingersTap', callback); 776 inputMonitor.off("threeFingersTap"); 777 console.log(`Monitor off success`); 778} catch (error) { 779 console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 780} 781``` 782