# @ohos.multimodalInput.inputMonitor (Input Monitor) The **inputMonitor** module provides APIs to listen for touch events of input devices including touchscreen, mouse, and touchpad. > **NOTE** > > - 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. > > - The APIs provided by this module are system APIs. ## Modules to Import ```js import inputMonitor from '@ohos.multimodalInput.inputMonitor'; ``` ## inputMonitor.on('touch') on(type: 'touch', receiver: TouchEventReceiver): void Enables listening for global touch events. **Required permissions**: ohos.permission.INPUT_MONITORING **System capability**: SystemCapability.MultimodalInput.Input.InputMonitor **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ------------------- | | type | string | Yes | Type of the input device event. The value is **touch**.| | receiver | [TouchEventReceiver](#toucheventreceiver) | Yes | Callback used to return the touch event asynchronously.| **Example** ```js try { inputMonitor.on('touch', (touchEvent: TouchEvent) => { console.log(`Monitor on success ${JSON.stringify(touchEvent)}`); return false; }); } catch (error) { console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## inputMonitor.on('mouse')9+ on(type: 'mouse', receiver: Callback<MouseEvent>): void Enables listening for global mouse events. **Required permissions**: ohos.permission.INPUT_MONITORING **System capability**: SystemCapability.MultimodalInput.Input.InputMonitor **Parameters** | Name | Type | Mandatory | Description | | -------- | -------------------------- | ---- | ------------------- | | type | string | Yes | Type of the input device event. The value is **mouse**.| | receiver | Callback<MouseEvent> | Yes | Callback used to return the mouse event asynchronously. | **Example** ```js import { MouseEvent } from '@ohos.multimodalInput.mouseEvent'; try { inputMonitor.on('mouse', (mouseEvent: MouseEvent) => { console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`); return false; }); } catch (error) { console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## inputMonitor.off('touch') off(type: 'touch', receiver?: TouchEventReceiver): void Disables listening for global touch events. **Required permissions**: ohos.permission.INPUT_MONITORING **System capability**: SystemCapability.MultimodalInput.Input.InputMonitor **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ------------------- | | type | string | Yes | Type of the input device event. The value is **touch**.| | 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. | **Example** ```js // Disable listening for a single callback. let callback = (touchEvent: TouchEvent) => { console.log(`Monitor on success ${JSON.stringify(touchEvent)}`); return false; }; try { inputMonitor.on('touch', callback); inputMonitor.off('touch', callback); console.log(`Monitor off success`); } catch (error) { console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ```js // Cancel listening for all callbacks. let callback = (touchEvent: TouchEvent) => { console.log(`Monitor on success ${JSON.stringify(touchEvent)}`); return false; }; try { inputMonitor.on('touch', callback); inputMonitor.off('touch'); console.log(`Monitor off success`); } catch (error) { console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## inputMonitor.off('mouse')9+ off(type: 'mouse', receiver?: Callback<MouseEvent>): void Disables listening for global mouse events. **Required permissions**: ohos.permission.INPUT_MONITORING **System capability**: SystemCapability.MultimodalInput.Input.InputMonitor **Parameters** | Name | Type | Mandatory | Description | | -------- | -------------------------- | ---- | ------------------- | | type | string | Yes | Type of the input device event. The value is **mouse**.| | 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.| **Example** ```js // Disable listening for a single callback. let callback = (mouseEvent: MouseEvent) => { console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`); return false; }; try { inputMonitor.on('mouse', callback); inputMonitor.off('mouse', callback); console.log(`Monitor off success`); } catch (error) { console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ```js // Cancel listening for all callbacks. let callback = (mouseEvent: MouseEvent) => { console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`); return false; }; try { inputMonitor.on('mouse', callback); inputMonitor.off('mouse'); console.log(`Monitor off success`); } catch (error) { console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## TouchEventReceiver Represents the callback used to return the touch event. **Required permissions**: ohos.permission.INPUT_MONITORING **System capability**: SystemCapability.MultimodalInput.Input.InputMonitor **Parameters** | Name | Type | Mandatory | Description | | ---------- | ---------------------------------------- | ---- | ---------------------------------------- | | touchEvent | [TouchEvent](../arkui-js/js-components-common-events.md) | Yes | Touch event.| **Return value** | Type | Description | | ------- | ---------------------------------------- | | 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.| **Example** ```js try { inputMonitor.on('touch', touchEvent => { if (touchEvent.touches.length == 3) {// Three fingers are pressed. return true; } return false; }); } catch (error) { console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## inputMonitor.on('pinch')10+ on(type: 'pinch', receiver: Callback<[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)>): void Enables listening for global touchpad pinch events. **Required permissions**: ohos.permission.INPUT_MONITORING **System capability**: SystemCapability.MultimodalInput.Input.InputMonitor **Parameters** | Name | Type | Mandatory | Description | | -------- | -------------------------- | ---- | ------------------- | | type | string | Yes | Event type. This field has a fixed value of **pinch**.| | receiver | Callback<[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)> | Yes | Callback used to return the pinch event asynchronously. | **Example** ```js try { inputMonitor.on('pinch', (pinchEvent) => { console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`); return false; }); } catch (error) { console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## inputMonitor.off('pinch')10+ off(type: 'pinch', receiver?: Callback<[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)>): void Disables listening for global touchpad pinch events. **Required permissions**: ohos.permission.INPUT_MONITORING **System capability**: SystemCapability.MultimodalInput.Input.InputMonitor **Parameters** | Name | Type | Mandatory | Description | | -------- | -------------------------- | ---- | ------------------- | | type | string | Yes | Event type. This field has a fixed value of **pinch**.| | 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.| **Example** ```js // Disable listening for a single callback. import { Pinch } from '@ohos.multimodalInput.gestureEvent'; let callback = (pinchEvent: Pinch) => { console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`); return false; }; try { inputMonitor.on('pinch', callback); inputMonitor.off('pinch', callback); console.log(`Monitor off success`); } catch (error) { console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ```js // Cancel listening for all callbacks. import { Pinch } from '@ohos.multimodalInput.gestureEvent'; let callback = (pinchEvent: Pinch) => { console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`); return false; }; try { inputMonitor.on('pinch', callback); inputMonitor.off('pinch'); console.log(`Monitor off success`); } catch (error) { console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## inputMonitor.on('threeFingersSwipe')10+ on(type: 'threeFingersSwipe', receiver: Callback<[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)>): void Enables listening for three-finger swipe events. **Required permissions**: ohos.permission.INPUT_MONITORING **System capability**: SystemCapability.MultimodalInput.Input.InputMonitor **Parameters** | Name | Type | Mandatory | Description | | -------- | -------------------------- | ---- | ------------------- | | type | string | Yes | Event type. This field has a fixed value of **threeFingersSwipe**.| | receiver | Callback<[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)> | Yes | Callback used to return the three-finger swipe event asynchronously. | **Example** ```js try { inputMonitor.on('threeFingersSwipe', (threeFingersSwipe) => { console.log(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`); return false; }); } catch (error) { console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## inputMonitor.off('threeFingersSwipe')10+ off(type: 'threeFingersSwipe', receiver?: Callback<[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)>): void Disables listening for three-finger swipe events. **Required permissions**: ohos.permission.INPUT_MONITORING **System capability**: SystemCapability.MultimodalInput.Input.InputMonitor **Parameters** | Name | Type | Mandatory | Description | | -------- | -------------------------- | ---- | ------------------- | | type | string | Yes | Event type. This field has a fixed value of **threeFingersSwipe**.| | 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.| **Example** ```js // Disable listening for a single callback. import { ThreeFingersSwipe } from '@ohos.multimodalInput.gestureEvent'; let callback = (threeFingersSwipe: ThreeFingersSwipe) => { console.log(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`); return false; }; try { inputMonitor.on('threeFingersSwipe', callback); inputMonitor.off("threeFingersSwipe", callback); console.log(`Monitor off success`); } catch (error) { console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ```js // Cancel listening for all callbacks. import { ThreeFingersSwipe } from '@ohos.multimodalInput.gestureEvent'; let callback = (threeFingersSwipe: ThreeFingersSwipe) => { console.log(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`); return false; }; try { inputMonitor.on("threeFingersSwipe", callback); inputMonitor.off("threeFingersSwipe"); console.log(`Monitor off success`); } catch (error) { console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## inputMonitor.on('fourFingersSwipe')10+ on(type: 'fourFingersSwipe', receiver: Callback<[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)>): void Enables listening for four-finger swipe events. **Required permissions**: ohos.permission.INPUT_MONITORING **System capability**: SystemCapability.MultimodalInput.Input.InputMonitor **Parameters** | Name | Type | Mandatory | Description | | -------- | -------------------------- | ---- | ------------------- | | type | string | Yes | Event type. This field has a fixed value of **fourFingersSwipe**.| | receiver | Callback<[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)> | Yes | Callback used to return the four-finger swipe event asynchronously. | **Example** ```js try { inputMonitor.on('fourFingersSwipe', (fourFingersSwipe) => { console.log(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`); return false; }); } catch (error) { console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## inputMonitor.off('fourFingersSwipe')10+ off(type: 'fourFingersSwipe', receiver?: Callback<[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)>): void Disables listening for four-finger swipe events. **Required permissions**: ohos.permission.INPUT_MONITORING **System capability**: SystemCapability.MultimodalInput.Input.InputMonitor **Parameters** | Name | Type | Mandatory | Description | | -------- | -------------------------- | ---- | ------------------- | | type | string | Yes | Event type. This field has a fixed value of **fourFingersSwipe**.| | 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.| **Example** ```js // Disable listening for a single callback. import { FourFingersSwipe } from '@ohos.multimodalInput.gestureEvent'; let callback = (fourFingersSwipe: FourFingersSwipe) => { console.log(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`); return false; }; try { inputMonitor.on('fourFingersSwipe', callback); inputMonitor.off('fourFingersSwipe', callback); console.log(`Monitor off success`); } catch (error) { console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ```js // Cancel listening for all callbacks. import { FourFingersSwipe } from '@ohos.multimodalInput.gestureEvent'; let callback = (fourFingersSwipe: FourFingersSwipe) => { console.log(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`); return false; }; try { inputMonitor.on('fourFingersSwipe', callback); inputMonitor.off('fourFingersSwipe'); console.log(`Monitor off success`); } catch (error) { console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ```