• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Input Monitor
2
3The input monitor module implements listening for global touch events.
4
5> **NOTE**
6> - 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.
7>
8> - The APIs of this module are system APIs and cannot be called by third-party applications.
9
10
11## Modules to Import
12
13
14```js
15import inputMonitor from '@ohos.multimodalInput.inputMonitor';
16```
17
18
19## Permissions
20
21ohos.permission.INPUT_MONITORING
22
23
24## inputMonitor.on
25
26on(type: "touch", receiver: TouchEventReceiver): void
27
28Starts listening for global touch events.
29
30This is a system API.
31
32**Required permissions**: ohos.permission.INPUT_MONITORING
33
34**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor
35
36  **Parameters**
37| Name      | Type                                      | Mandatory  | Description                  |
38| -------- | ----------------------------------------- | ---- | ------------------------------- |
39| type     | string                                    | Yes  | Type of the input event to listen for. The value is **touch**.|
40| receiver | [TouchEventReceiver](#toucheventreceiver) | Yes  | Callback used to return the touch event.         |
41
42  **Example**
43
44```js
45inputMonitor.off("touch", (event) => {
46  // A touch event is consumed.
47  return false;
48});
49```
50
51
52## inputMonitor.off
53
54off(type: "touch", receiver?: TouchEventReceiver): void
55
56Stops listening for global touch events.
57
58This is a system API.
59
60**Required permissions**: ohos.permission.INPUT_MONITORING
61
62**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor
63
64  **Parameters**
65| Name      | Type                                      | Mandatory  | Description                  |
66| -------- | ----------------------------------------- | ---- | ------------------------------- |
67| type     | string                                    | Yes  | Type of the input event to listen for. The value is **touch**.|
68| receiver | [TouchEventReceiver](#toucheventreceiver) | No  | Callback used to return the touch event.         |
69
70  **Example**
71
72```js
73inputMonitor.off("touch");
74```
75
76
77## TouchEventReceiver
78
79Represents the class of the callback used to return the touch event. If the value **true** is returned, the touch event has been consumed, and the event monitor will be closed.
80
81This is a system API.
82
83**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor
84
85  **Parameters**
86| Name        | Type                                      | Mandatory  | Description                                      |
87| ---------- | ---------------------------------------- | ---- | ---------------------------------------- |
88| touchEvent | [TouchEvent](../arkui-js/js-components-common-events.md) | Yes   | Callback used to return the touch event.|
89
90  **Return value**
91| Type     | Description                                    |
92| ------- | -------------------------------------- |
93| Boolean | Result indicating whether the touch event has been consumed by the input monitor. The value **true** indicates that the touch event has been consumed, and the value **false** indicates the opposite.|
94
95  **Example**
96
97```js
98inputMonitor.on("touch", (event) => {
99  // A touch event is consumed.
100  return false;
101});
102inputMonitor.off("touch");
103```
104