1# 输入监听 2 3InputMonitor模块提供了监听全局触摸事件的功能。 4 5>  **说明:** 6> - 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 7> 8> - 本模块接口均为系统接口,三方应用不支持调用。 9 10 11## 导入模块 12 13 14```js 15import inputMonitor from '@ohos.multimodalInput.inputMonitor'; 16``` 17 18 19## 权限 20 21ohos.permission.INPUT_MONITORING 22 23 24## inputMonitor.on 25 26on(type: "touch", receiver: TouchEventReceiver): void 27 28开始监听全局触屏事件。 29 30此接口为系统接口。 31 32**需要权限:**ohos.permission.INPUT_MONITORING 33 34**系统能力:**SystemCapability.MultimodalInput.Input.InputMonitor 35 36 **参数:** 37| 参数 | 类型 | 必填 | 说明 | 38| -------- | ----------------------------------------- | ---- | ------------------------------- | 39| type | string | 是 | 监听输入事件类型,取值“touch”。 | 40| receiver | [TouchEventReceiver](#toucheventreceiver) | 是 | 触摸输入事件回调函数。 | 41 42 **示例:** 43 44```js 45inputMonitor.off("touch", (event) => { 46 // 消费触屏事件 47 return false; 48}); 49``` 50 51## inputMonitor.off 52 53off(type: "touch", receiver?: TouchEventReceiver): void 54 55停止监听全局触屏事件。 56 57此接口为系统接口。 58 59**需要权限:**ohos.permission.INPUT_MONITORING 60 61**系统能力:**SystemCapability.MultimodalInput.Input.InputMonitor 62 63 **参数:** 64| 参数 | 类型 | 必填 | 说明 | 65| -------- | ----------------------------------------- | ---- | ------------------------------- | 66| type | string | 是 | 监听输入事件类型,取值“touch”。 | 67| receiver | [TouchEventReceiver](#toucheventreceiver) | 否 | 触摸输入事件回调函数。 | 68 69 **示例:** 70 71```js 72inputMonitor.off("touch"); 73``` 74 75 76## TouchEventReceiver 77 78触摸输入事件的回调函数。如果返回true,则触摸输入被监听器消耗,系统将执行关闭动作。 79 80此接口为系统接口。 81 82**系统能力:**SystemCapability.MultimodalInput.Input.InputMonitor 83 84 **参数:** 85| 参数 | 类型 | 必填 | 说明 | 86| ---------- | ---------------------------------------- | ---- | ---------------------------------------- | 87| touchEvent | [TouchEvent](../arkui-js/js-components-common-events.md) | 是 | 触摸输入事件回调函数,返回true表示输触事件被监听器消费,false表示输触事件未被监听器消费。 | 88 89 **返回值:** 90| 类型 | 说明 | 91| ------- | -------------------------------------- | 92| Boolean | 返回true表示触摸输入事件被监听器消费,false表示触摸输入事件未被监听器消费。 | 93 94 **示例:** 95 96```js 97inputMonitor.on("touch", (event) => { 98 // 消费触摸输入事件 99 return false; 100}); 101inputMonitor.off("touch"); 102``` 103