diff --git a/zh-cn/application-dev/reference/apis-input-kit/js-apis-inputmonitor-sys.md b/zh-cn/application-dev/reference/apis-input-kit/js-apis-inputmonitor-sys.md index 57afebbb5f1f33216e6742a50a12e4ef97125c4d..d0a6df8a69270325fcbda9cfb25ec38f6221eace 100644 --- a/zh-cn/application-dev/reference/apis-input-kit/js-apis-inputmonitor-sys.md +++ b/zh-cn/application-dev/reference/apis-input-kit/js-apis-inputmonitor-sys.md @@ -1687,3 +1687,55 @@ struct Index { } } ``` + +## inputMonitor.queryTouchEvents()20+ + +queryTouchEvents(count: number): Promise<Array<TouchEvent>> + +查询最近的触屏事件,最多支持查询 100 条事件,使用Promise异步回调。 + +**需要权限:** ohos.permission.INPUT_MONITORING + +**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| count | number | 是 | 要查询的触屏事件数量。取值范围为1-100的整数。 | + +**返回值:** + +| 类型 | 说明 | +| :------------ | :---------------------------------- | +| Promise<Array<[TouchEvent](js-apis-touchevent-sys.md#touchevent)>> | Promise对象,返回查询到的触屏事件。包含以下有效信息:
- actionTime:触屏事件发生的时间,表示从1970.1.1 00:00:00 GMT逝去的微秒数。
- [SourceType](js-apis-touchevent.md#sourcetype):触摸来源的设备类型。
- [isInject](js-apis-touchevent-sys.md#touchevent):表示该触屏事件是否为注入事件。
- pressure:压力值,取值范围是[0.0, 1.0],0.0表示不支持。
- tiltX:相对YZ平面的角度,取值的范围[-90, 90],其中正值是向右倾斜。
- tiltY:相对XZ平面的角度,取值的范围[-90, 90],其中正值是向下倾斜。 | + +**错误码**: + +以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 + +| 错误码ID | 错误信息 | +| -------- | ------------------------------------------------------------ | +| 201 | Permission denied. | +| 202 | Permission denied, non-system app called system api. | + +**示例:** + +```js +import { inputMonitor, TouchEvent } from '@kit.InputKit' +import { BusinessError } from '@kit.BasicServicesKit'; + +try { + inputMonitor.queryTouchEvents(10).then((events: Array) => { + 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}.`); +} +``` \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis-input-kit/js-apis-touchevent-sys.md b/zh-cn/application-dev/reference/apis-input-kit/js-apis-touchevent-sys.md index 6ce6212f6bec30c01523484ed5483809ede79a2a..b9837575cdffa31a35989ffdd1c316aab5e34b39 100644 --- a/zh-cn/application-dev/reference/apis-input-kit/js-apis-touchevent-sys.md +++ b/zh-cn/application-dev/reference/apis-input-kit/js-apis-touchevent-sys.md @@ -51,3 +51,4 @@ import { FixedMode, Touch, TouchEvent } from '@kit.InputKit'; | 名称 | 类型 | 只读 | 可选 | 说明 | | ---------- | ---------- | ---- | ---- | --------- | | fixedMode | [FixedMode](#fixedmode) | 否 | 是 | 修正坐标的模式。
**说明**:该接口仅在手机设备上生效。| +| isInject20+ | boolean | 否 | 是 | 表示该触屏事件是否为注入事件。注入事件详细介绍可参考[@ohos.multimodalInput.inputEventClient](js-apis-inputeventclient-sys.md)。
**说明**:该接口仅在手机设备上生效。|