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