@ohos.multimodalInput.inputMonitor (Input Monitor) (System API)
The inputMonitor module implements listening for events of input devices, including the touchscreen, mouse, touchpad, etc.
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.
In this document, global indicates the entire touchscreen or touchpad. For example, listening for global touch events means to listen for touch events triggered when a user touches at any position on the touchscreen.
The APIs provided by this module are system APIs.
Modules to Import
import { inputMonitor } from '@kit.InputKit';
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 | Event type. This field has a fixed value of touch. |
| receiver | TouchEventReceiver | Yes | Callback used to return touch events asynchronously. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | Permission denied, non-system app called system api. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { TouchEvent } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
try {
inputMonitor.on('touch', (touchEvent: TouchEvent) => {
console.info(`Monitor on success ${JSON.stringify(touchEvent)}`);
return false;
});
} catch (error) {
console.error(`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. This API uses an asynchronous callback to return the result.
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 mouse. |
| receiver | Callback<MouseEvent> | Yes | Callback used to return mouse events asynchronously. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | Permission denied, non-system app called system api. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { MouseEvent } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
try {
inputMonitor.on('mouse', (mouseEvent: MouseEvent) => {
console.info(`Monitor on success ${JSON.stringify(mouseEvent)}`);
return false;
});
} catch (error) {
console.error(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.on('mouse')11+
on(type: 'mouse', rect: display.Rect[], receiver: Callback<MouseEvent>): void
Enables listening for mouse events. When the mouse pointer moves to the specified rectangular area, a callback is triggered. This API uses an asynchronous callback to return the result.
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 mouse. |
| rect | display.Rect[] | Yes | Rectangular area where a callback is triggered. One or two rectangular areas can be specified. |
| receiver | Callback<MouseEvent> | Yes | Callback used to return mouse events asynchronously. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | SystemAPI permission error. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { MouseEvent } from '@kit.InputKit';
import { display } from '@kit.ArkUI';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
/**
* Callback triggered when the mouse pointer moves to the specified rectangular area.
*/
let callback = (mouseEvent : MouseEvent) => {
this.getUIContext().getPromptAction().showToast({
message: `Monitor on success: ${JSON.stringify(mouseEvent)}`
})
console.info(`Monitor on success ${JSON.stringify(mouseEvent)}`);
return false;
};
/**
* Rectangular area where a callback is triggered.
*/
let rect: display.Rect[] = [{
left: 100,
top: 100,
width: 100,
height: 100
}, {
left: 600,
top: 100,
width: 100,
height: 100
}];
try {
inputMonitor.on('mouse', rect, callback);
} catch (error) {
console.error(`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 | Event type. This field has a fixed value of touch. |
| receiver | 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. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | Permission denied, non-system app called system api. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { TouchEvent } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Disable listening for a single callback.
let callback = (touchEvent: TouchEvent) => {
console.info(`Monitor on success ${JSON.stringify(touchEvent)}`);
return false;
};
try {
inputMonitor.on('touch', callback);
inputMonitor.off('touch', callback);
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
import { inputMonitor } from '@kit.InputKit';
import { TouchEvent } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Cancel listening for all callbacks.
let callback = (touchEvent: TouchEvent) => {
console.info(`Monitor on success ${JSON.stringify(touchEvent)}`);
return false;
};
try {
inputMonitor.on('touch', callback);
inputMonitor.off('touch');
console.info(`Monitor off success`);
} catch (error) {
console.error(`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. This API uses an asynchronous callback to return the result.
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 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. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | Permission denied, non-system app called system api. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { MouseEvent } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Disable listening for a single callback.
let callback = (mouseEvent: MouseEvent) => {
console.info(`Monitor on success ${JSON.stringify(mouseEvent)}`);
return false;
};
try {
inputMonitor.on('mouse', callback);
inputMonitor.off('mouse', callback);
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
import { inputMonitor } from '@kit.InputKit';
import { MouseEvent } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Cancel listening for all callbacks.
let callback = (mouseEvent: MouseEvent) => {
console.info(`Monitor on success ${JSON.stringify(mouseEvent)}`);
return false;
};
try {
inputMonitor.on('mouse', callback);
inputMonitor.off('mouse');
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
TouchEventReceiver
type TouchEventReceiver = (touchEvent: TouchEvent) => boolean
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 | 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 not be dispatched to the window, and the value false indicates the opposite. |
Example
import { inputMonitor } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
try {
inputMonitor.on('touch', touchEvent => {
if (touchEvent.touches.length === 3) { // Three fingers are pressed.
return true;
}
return false;
});
} catch (error) {
console.error(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.on('pinch')10+
on(type: 'pinch', receiver: Callback<Pinch>): void
Enables listening for global touchpad pinch events. This API uses an asynchronous callback to return the result.
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> | Yes | Callback used to return pinch events asynchronously. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | SystemAPI permission error. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
try {
inputMonitor.on('pinch', (pinchEvent) => {
console.info(`Monitor on success ${JSON.stringify(pinchEvent)}`);
return false;
});
} catch (error) {
console.error(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.off('pinch')10+
off(type: 'pinch', receiver?: Callback<Pinch>): void
Disables listening for global touchpad pinch events. This API uses an asynchronous callback to return the result.
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> | 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. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | SystemAPI permission error. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { Pinch } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Disable listening for a single callback.
let callback = (pinchEvent: Pinch) => {
console.info(`Monitor on success ${JSON.stringify(pinchEvent)}`);
return false;
};
try {
inputMonitor.on('pinch', callback);
inputMonitor.off('pinch', callback);
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
import { inputMonitor } from '@kit.InputKit';
import { Pinch } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Cancel listening for all callbacks.
let callback = (pinchEvent: Pinch) => {
console.info(`Monitor on success ${JSON.stringify(pinchEvent)}`);
return false;
};
try {
inputMonitor.on('pinch', callback);
inputMonitor.off('pinch');
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.on('threeFingersSwipe')10+
on(type: 'threeFingersSwipe', receiver: Callback<ThreeFingersSwipe>): void
Enables listening for three-finger swipe events. This API uses an asynchronous callback to return the result.
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> | Yes | Callback used to return three-finger swipe events asynchronously. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | SystemAPI permission error. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
try {
inputMonitor.on('threeFingersSwipe', (threeFingersSwipe) => {
console.info(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`);
return false;
});
} catch (error) {
console.error(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.off('threeFingersSwipe')10+
off(type: 'threeFingersSwipe', receiver?: Callback<ThreeFingersSwipe>): void
Disables listening for three-finger swipe events. This API uses an asynchronous callback to return the result.
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> | 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. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | SystemAPI permission error. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { ThreeFingersSwipe } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Disable listening for a single callback.
let callback = (threeFingersSwipe: ThreeFingersSwipe) => {
console.info(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`);
return false;
};
try {
inputMonitor.on('threeFingersSwipe', callback);
inputMonitor.off("threeFingersSwipe", callback);
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
import { inputMonitor } from '@kit.InputKit';
import { ThreeFingersSwipe } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Cancel listening for all callbacks.
let callback = (threeFingersSwipe: ThreeFingersSwipe) => {
console.info(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`);
return false;
};
try {
inputMonitor.on("threeFingersSwipe", callback);
inputMonitor.off("threeFingersSwipe");
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.on('fourFingersSwipe')10+
on(type: 'fourFingersSwipe', receiver: Callback<FourFingersSwipe>): void
Enables listening for four-finger swipe events. This API uses an asynchronous callback to return the result.
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> | Yes | Callback used to return four-finger swipe events asynchronously. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | SystemAPI permission error. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
try {
inputMonitor.on('fourFingersSwipe', (fourFingersSwipe) => {
console.info(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`);
return false;
});
} catch (error) {
console.error(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.off('fourFingersSwipe')10+
off(type: 'fourFingersSwipe', receiver?: Callback<FourFingersSwipe>): void
Disables listening for four-finger swipe events. This API uses an asynchronous callback to return the result.
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> | 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. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | SystemAPI permission error. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { FourFingersSwipe } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Disable listening for a single callback.
let callback = (fourFingersSwipe: FourFingersSwipe) => {
console.info(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`);
return false;
};
try {
inputMonitor.on('fourFingersSwipe', callback);
inputMonitor.off('fourFingersSwipe', callback);
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
import { inputMonitor } from '@kit.InputKit';
import { FourFingersSwipe } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Cancel listening for all callbacks.
let callback = (fourFingersSwipe: FourFingersSwipe) => {
console.info(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`);
return false;
};
try {
inputMonitor.on('fourFingersSwipe', callback);
inputMonitor.off('fourFingersSwipe');
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.on('rotate')11+
on(type: 'rotate', fingers: number, receiver: Callback<Rotate>): void
Enables listening for rotation events of the touchpad. This API uses an asynchronous callback to return the result.
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 rotate. |
| fingers | number | Yes | Number of fingers that trigger a rotation. The value must not be greater than 2. |
| receiver | Callback<Rotate> | Yes | Callback used to return rotation events asynchronously. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | SystemAPI permission error. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { Rotate } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
try {
inputMonitor.on('rotate', 2, (rotateEvent: Rotate) => {
console.info(`Monitor on success ${JSON.stringify(rotateEvent)}`);
return false;
});
} catch (error) {
console.error(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.off('rotate')11+
off(type: 'rotate', fingers: number, receiver?: Callback<Rotate>): void
Disables listening for rotation events of the touchpad. This API uses an asynchronous callback to return the result.
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 rotate. |
| fingers | number | Yes | Number of fingers that trigger a rotation. The value must not be greater than 2. |
| receiver | Callback<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. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | SystemAPI permission error. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { Rotate } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Disable listening for a single callback.
let callback = (rotateEvent: Rotate) => {
console.info(`Monitor on success ${JSON.stringify(rotateEvent)}`);
return false;
};
try {
inputMonitor.on('rotate', 2, callback);
inputMonitor.off('rotate', 2, callback);
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
import { inputMonitor } from '@kit.InputKit';
import { Rotate } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Cancel listening for all callbacks.
let callback = (rotateEvent: Rotate) => {
console.info(`Monitor on success ${JSON.stringify(rotateEvent)}`);
return false;
};
try {
inputMonitor.on('rotate', 2, callback);
inputMonitor.off('rotate', 2);
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.on('pinch')11+
on(type: 'pinch', fingers: number, receiver: Callback<Pinch>): void
Enables listening for global touchpad pinch events. This API uses an asynchronous callback to return the result.
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. |
| fingers | number | Yes | Number of fingers that trigger the pinch. The value must be greater than or equal to 2. |
| receiver | Callback<Pinch> | Yes | Callback used to return pinch events asynchronously. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | SystemAPI permission error. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { Pinch } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
try {
inputMonitor.on('pinch', 2, (pinchEvent: Pinch) => {
console.info(`Monitor on success ${JSON.stringify(pinchEvent)}`);
return false;
});
} catch (error) {
console.error(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.off('pinch')11+
off(type: 'pinch', fingers: number, receiver?: Callback<Pinch>): void
Disables listening for global touchpad pinch events. This API uses an asynchronous callback to return the result.
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. |
| fingers | number | Yes | Number of fingers that trigger the pinch. The value must be greater than or equal to 2. |
| receiver | Callback<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. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | SystemAPI permission error. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { Pinch } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Disable listening for a single callback.
let callback = (pinchEvent: Pinch) => {
console.info(`Monitor on success ${JSON.stringify(pinchEvent)}`);
return false;
};
try {
inputMonitor.on('pinch', 2, callback);
inputMonitor.off('pinch', 2, callback);
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
import { inputMonitor } from '@kit.InputKit';
import { Pinch } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Cancel listening for all callbacks.
let callback = (pinchEvent: Pinch) => {
console.info(`Monitor on success ${JSON.stringify(pinchEvent)}`);
return false;
};
try {
inputMonitor.on('pinch', 2, callback);
inputMonitor.off('pinch', 2);
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.on('threeFingersTap')11+
on(type: 'threeFingersTap', receiver: Callback<ThreeFingersTap>): void
Enables listening for three-finger tap events. This API uses an asynchronous callback to return the result.
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 threeFingersTap. |
| receiver | Callback<ThreeFingersTap> | Yes | Callback used to return three-finger tap events asynchronously. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | SystemAPI permission error. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
try {
inputMonitor.on('threeFingersTap', (threeFingersTap) => {
console.info(`Monitor on success ${JSON.stringify(threeFingersTap)}`);
return false;
});
} catch (error) {
console.error(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.off('threeFingersTap')11+
off(type: 'threeFingersTap', receiver?: Callback<ThreeFingersTap>): void
Disables listening for three-finger tap events. This API uses an asynchronous callback to return the result.
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 threeFingersTap. |
| receiver | Callback<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. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | SystemAPI permission error. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { ThreeFingersTap } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Disable listening for a single callback.
let callback = (threeFingersTap: ThreeFingersTap) => {
console.info(`Monitor on success ${JSON.stringify(threeFingersTap)}`);
return false;
};
try {
inputMonitor.on('threeFingersTap', callback);
inputMonitor.off("threeFingersTap", callback);
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
import { inputMonitor } from '@kit.InputKit';
import { ThreeFingersTap } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Cancel listening for all callbacks.
let callback = (threeFingersTap: ThreeFingersTap) => {
console.info(`Monitor on success ${JSON.stringify(threeFingersTap)}`);
return false;
};
try {
inputMonitor.on('threeFingersTap', callback);
inputMonitor.off("threeFingersTap");
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.on('touchscreenSwipe')18+
on(type: 'touchscreenSwipe', fingers: number, receiver: Callback<TouchGestureEvent>): void
Enables listening for touchscreen swipe events. This API uses an asynchronous callback to return the result.
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 touchscreenSwipe. |
| fingers | number | Yes | Number of fingers that trigger the swipe. The value range is [3, 5]. |
| receiver | Callback<TouchGestureEvent> | Yes | Callback used to return touchscreen swipe events asynchronously. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | Caller is not a system application. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { TouchGestureEvent } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
let fingers: number = 4;
try {
inputMonitor.on('touchscreenSwipe', fingers, (event: TouchGestureEvent) => {
console.info(`Monitor on success ${JSON.stringify(event)}`);
});
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.off('touchscreenSwipe')18+
off(type: 'touchscreenSwipe', fingers: number, receiver?: Callback<TouchGestureEvent>): void
Disables listening for touchscreen swipe events. This API uses an asynchronous callback to return the result.
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 touchscreenSwipe. |
| fingers | number | Yes | Number of fingers that trigger the swipe. The value range is [3, 5]. |
| receiver | Callback<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. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | Caller is not a system application. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { TouchGestureEvent } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Disable listening for a single callback.
let callback = (event: TouchGestureEvent) => {
console.info(`Monitor on success ${JSON.stringify(event)}`);
};
let fingers: number = 4;
try {
inputMonitor.on('touchscreenSwipe', fingers, callback);
inputMonitor.off('touchscreenSwipe', fingers, callback);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
import { inputMonitor } from '@kit.InputKit';
import { TouchGestureEvent } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Cancel listening for all callbacks.
let fingers: number = 4;
try {
inputMonitor.on('touchscreenSwipe', fingers, (event: TouchGestureEvent) => {
console.info(`Monitor on success ${JSON.stringify(event)}`);
});
inputMonitor.off('touchscreenSwipe', fingers);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.on('touchscreenPinch')18+
on(type: 'touchscreenPinch', fingers: number, receiver: Callback<TouchGestureEvent>): void
Enables listening for touchscreen pinch events. This API uses an asynchronous callback to return the result.
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 touchscreenPinch. |
| fingers | number | Yes | Number of fingers that trigger the pinch. The value range is [4, 5]. |
| receiver | Callback<TouchGestureEvent> | Yes | Callback used to return touchscreen pinch events asynchronously. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | Caller is not a system application. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { TouchGestureEvent } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
let fingers: number = 4;
try {
inputMonitor.on('touchscreenPinch', fingers, (event: TouchGestureEvent) => {
console.info(`Monitor on success ${JSON.stringify(event)}`);
});
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.off('touchscreenPinch')18+
off(type: 'touchscreenPinch', fingers: number, receiver?: Callback<TouchGestureEvent>): void
Disables listening for touchscreen pinch events. This API uses an asynchronous callback to return the result.
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 touchscreenPinch. |
| fingers | number | Yes | Number of fingers that trigger the pinch. The value range is [4, 5]. |
| receiver | Callback<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. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | Caller is not a system application. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { TouchGestureEvent } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Disable listening for a single callback.
let callback = (event: TouchGestureEvent) => {
console.info(`Monitor on success ${JSON.stringify(event)}`);
};
let fingers: number = 4;
try {
inputMonitor.on('touchscreenPinch', fingers, callback);
inputMonitor.off("touchscreenPinch", fingers, callback);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
import { inputMonitor } from '@kit.InputKit';
import { TouchGestureEvent } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Cancel listening for all callbacks.
let fingers: number = 4;
try {
inputMonitor.on('touchscreenPinch', fingers, (event: TouchGestureEvent) => {
console.info(`Monitor on success ${JSON.stringify(event)}`);
});
inputMonitor.off("touchscreenPinch", fingers);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.on('keyPressed')15+
on(type: 'keyPressed', keys: Array<KeyCode>, receiver: Callback<KeyEvent>): void
Listens for the press and release events of the specified key, which can be the META_LEFT, META_RIGHT, power, or volume key. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.INPUT_MONITORING
System capability: SystemCapability.MultimodalInput.Input.InputMonitor
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. This parameter has a fixed value of keyPressed. |
| keys | Array<KeyCode> | Yes | Key value. The following key values are supported: KEYCODE_META_LEFT, KEYCODE_META_RIGHT, KEYCODE_POWER, KEYCODE_VOLUME_DOWN, and KEYCODE_VOLUME_UP. |
| receiver | Callback<KeyEvent> | Yes | Callback used to receive reported data. |
Error codes
For details about the error codes, see Universal Error Codes and Input Monitor Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | Permission denied, non-system app called system api. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
| 4100001 | Event listening not supported for the key. |
Example
import { inputMonitor, KeyEvent, KeyCode } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
try {
let keys: Array<KeyCode> = [KeyCode.KEYCODE_VOLUME_UP];
inputMonitor.on('keyPressed', keys, (event: KeyEvent ) => {
console.info(`Monitor on success ${JSON.stringify(event)}`);
});
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.off('keyPressed')15+
off(type: 'keyPressed', receiver?: Callback<KeyEvent>): void
Cancels 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'). This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.INPUT_MONITORING
System capability: SystemCapability.MultimodalInput.Input.InputMonitor
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. This parameter has a fixed value of keyPressed. |
| receiver | Callback<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. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | Permission denied, non-system app called system api. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor, KeyEvent, KeyCode } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Disable listening for a single callback.
try {
let callback = (event: KeyEvent) => {
console.info(`Monitor on success ${JSON.stringify(event)}`);
};
let keys: Array<KeyCode> = [KeyCode.KEYCODE_VOLUME_UP];
inputMonitor.on('keyPressed', keys, callback);
inputMonitor.off("keyPressed", callback);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
import { inputMonitor, KeyEvent, KeyCode } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Cancel listening for all callbacks.
try {
let keys: Array<KeyCode> = [KeyCode.KEYCODE_VOLUME_UP];
inputMonitor.on('keyPressed', keys, (event: KeyEvent) => {
console.info(`Monitor on success ${JSON.stringify(event)}`);
});
inputMonitor.off("keyPressed");
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.queryTouchEvents()20+
queryTouchEvents(count: number): Promise<Array<TouchEvent>>
Queries the latest touch events. This API uses a promise to return the result.
Required permissions: ohos.permission.INPUT_MONITORING
System capability: SystemCapability.MultimodalInput.Input.InputMonitor
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| count | number | Yes | Number of touch events to be queried. The value range is [0, 100]. If the value is less than 0, the value 0 is used. If the value is greater than 100, the value 100 is used. If the number of touch events is 30 and the value of this parameter is set to 50, only 30 touch events can be queried. |
Return value
| Type | Description |
|---|---|
| Promise<Array<TouchEvent>> | Promise used to return the touch event. The following valid information is included: - actionTime: timestamp of the touch event, which is measured as the number of microseconds that have elapsed since the Unix epoch. - SourceType: touch source type. - isInject: whether the touch event is an injection event. - pressure: pressure value. The value range is [0.0, 1.0]. The value 0.0 indicates that the pressure is not supported. - tiltX: angle relative to the YZ plane. The value range is [-90, 90]. A positive value indicates a rightward tilt. - tiltY: angle relative to the XZ plane. The value range is [-90, 90]. A positive value indicates a downward tilt. From API version 23, the following additional valid information can be obtained: - Action: touch event type. - screenX: X-coordinate relative to the upper left corner of the screen, in pixels. The value range is [0, screen width], and the value increases rightwards. This parameter can be obtained only by specified applications. - screenY: Y-coordinate relative to the upper left corner of the screen, in pixels. The value range is [0, screen height], and the value increases downwards. This parameter can be obtained only by specified applications. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | Permission denied, non-system app called system api. |
Example
import { inputMonitor, TouchEvent } from '@kit.InputKit'
import { BusinessError } from '@kit.BasicServicesKit';
try {
inputMonitor.queryTouchEvents(10).then((events: Array<TouchEvent>) => {
events.forEach((event, index) => {
console.info(`Touch event ${index}: actionTime=${event.actionTime}, sourceType=${event.sourceType}`);
});
}).catch((error: BusinessError) => {
console.error('queryTouchEvents promise error: ' + JSON.stringify(error));
});
} catch (error) {
const code = (error as BusinessError).code;
const message = (error as BusinessError).message;
console.error(`queryTouchEvents failed, error code: ${code}, message: ${message}.`);
}
inputMonitor.on('swipeInward')12+
on(type: 'swipeInward', receiver: Callback<SwipeInward>): void
Listens for inward swipe events. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.INPUT_MONITORING
System capability: SystemCapability.MultimodalInput.Input.InputMonitor
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Input event type. The value is fixed at SwipeInward. |
| receiver | Callback<SwipeInward> | Yes | Callback function, which returns SwipeInward. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | Permission denied, non-system app called system api. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
try {
inputMonitor.on('swipelnward', (SwipeInward) => {
console.info(`Monitor on success ${JSON.stringify(SwipeInward)}`);
return false;
});
} catch (error) {
console.error(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.off('swipeInward')12+
off(type: 'swipeInward', receiver?: Callback<SwipeInward>): void
Cancels listening for inward swipe events. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.INPUT_MONITORING
System capability: SystemCapability.MultimodalInput.Input.InputMonitor
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Input event type. The value is fixed at SwipeInward. |
| receiver | Callback<SwipeInward> | 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. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | SystemAPI permission error. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor, SwipeInward } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Disable listening for a single callback.
let callback = (swipeInward: SwipeInward) => {
console.info(`Monitor on success ${JSON.stringify(swipeInward)}`);
return false;
};
try {
inputMonitor.on('swipeInward', callback);
inputMonitor.off("swipeInward", callback);
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
import { inputMonitor, SwipeInward } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Cancel listening for all callbacks.
let callback = (swipeInward: SwipeInward) => {
console.info(`Monitor on success ${JSON.stringify(swipeInward)}`);
return false;
};
try {
inputMonitor.on('swipeInward', callback);
inputMonitor.off("swipeInward");
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.on('fingerprint')12+
on(type: 'fingerprint', receiver: Callback<FingerprintEvent>): void
Enables listening for fingerprint gesture input events. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.INPUT_MONITORING
System capability: SystemCapability.MultimodalInput.Input.InputMonitor
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Input event type. The value is unique and is fingerprint. |
| receiver | Callback<FingerprintEvent> | Yes | Callback used to receive reported data. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | Permission denied, non-system app called system api. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
try {
inputMonitor.on('fingerprint', (FingerprintEvent) => {
console.info(`Monitor on success ${JSON.stringify(FingerprintEvent)}`);
return false;
});
} catch (error) {
console.error(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
inputMonitor.off('fingerprint')12+
off(type: 'fingerprint', receiver?: Callback<FingerprintEvent>): void
Disables listening for fingerprint gesture input events. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.INPUT_MONITORING
System capability: SystemCapability.MultimodalInput.Input.InputMonitor
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Input event type. The value is fingerprint. |
| receiver | Callback<FingerprintEvent> | 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. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 202 | SystemAPI permission error. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { inputMonitor } from '@kit.InputKit';
import { FingerprintEvent } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Disable listening for a single callback.
let callback = (fingerprintEvent: FingerprintEvent) => {
console.info(`Monitor on success ${JSON.stringify(fingerprintEvent)}`);
return false;
};
try {
inputMonitor.on('fingerprint', callback);
inputMonitor.off("fingerprint", callback);
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}
import { inputMonitor } from '@kit.InputKit';
import { FingerprintEvent } from '@kit.InputKit';
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
Text()
.onClick(() => {
// Cancel listening for all callbacks.
let callback = (fingerprintEvent: FingerprintEvent) => {
console.info(`Monitor on success ${JSON.stringify(fingerprintEvent)}`);
return false;
};
try {
inputMonitor.on('fingerprint', callback);
inputMonitor.off("fingerprint");
console.info(`Monitor off success`);
} catch (error) {
console.error(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
})
}
}
}