1# @ohos.mulitmodalawareness.motion (动作感知) 2 3本模块,提供对用户行为、动作的感知能力,包括用户的手势、动作等。 4 5> **说明:** 6> 7> 本模块首批接口从API version 15开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8 9 10## 导入模块 11 12```ts 13import { motion } from '@kit.MultimodalAwarenessKit'; 14``` 15 16## OperatingHandStatus 17 18触控操作手状态信息。 19 20**系统能力**:SystemCapability.MultimodalAwarness.Motion 21 22| 名称 | 值 | 说明 | 23| ------------------- | ---- | ---------------------- | 24| UNKNOWN_STATUS | 0 | 表示未识别。 | 25| LEFT_HAND_OPERATED | 1 | 表示触控操作手是左手。 | 26| RIGHT_HAND_OPERATED | 2 | 表示触控操作手是右手。 | 27 28 29 30 31## motion.on('operatingHandChanged') 32 33 on(type: 'operatingHandChanged', callback: Callback<OperatingHandStatus>): void; 34 35订阅触控操作手感知事件。 36 37**需要权限**:ohos.permission.ACTIVITY_MOTION 38 39**系统能力**:SystemCapability.MultimodalAwarness.Motion 40 41**参数**: 42 43| 参数名 | 类型 | 必填 | 说明 | 44| -------- | -------------------------------- | ---- | ------------------------------------------------------------ | 45| type | string | 是 | 事件类型。type为“operatingHandChanged”,表示操作手状态变化。 | 46| callback | Callback<[OperatingHandStatus](#operatinghandstatus)> | 是 | 回调函数,返回操作手状态。 | 47 48**错误码**: 49 50以下错误码的详细介绍请参见[行为动作感知错误码](errorcode-motion.md)和[通用错误码](../errorcode-universal.md)。 51 52| 错误码ID | 错误信息 | 53| -------- | ------------------------------------------------------------ | 54| 201 | Permission denied. | 55| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 56| 801 | Capability not supported.Function can not work correctly due to limited device capabilities. | 57| 31500001 | Service exception. | 58| 31500002 | Subscribe Failed. | 59 60**示例**: 61 62```ts 63motion.on('operatingHandChanged', (data:motion.OperatingHandStatus) => { 64 console.info('on success' + data); 65}) 66``` 67 68 69 70## motion.off('operatingHandChanged') 71 72off(type: 'operatingHandChanged', callback?: Callback<OperatingHandStatus>): void; 73 74取消订阅触控操作手感知事件。 75 76**需要权限**:ohos.permission.ACTIVITY_MOTION 77 78**系统能力**:SystemCapability.MultimodalAwarness.Motion 79 80**参数**: 81 82| 参数名 | 类型 | 必填 | 说明 | 83| -------- | -------------------------------- | ---- | ------------------------------------------------------------ | 84| type | string | 是 | 事件类型。type为“operatingHandChanged”,表示操作手状态变化。 | 85| callback | Callback<[OperatingHandStatus](#operatinghandstatus)> | 否 | 回调函数,返回操作手状态。 | 86 87**错误码**: 88 89以下错误码的详细介绍请参见[行为动作感知错误码](errorcode-motion.md)和[通用错误码](../errorcode-universal.md)。 90 91| 错误码ID | 错误信息 | 92| -------- | ------------------------------------------------------------ | 93| 201 | Permission denied. | 94| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 95| 801 | Capability not supported.Function can not work correctly due to limited device capabilities. | 96| 31500001 | Service exception. | 97| 31500003 | UnSubscribe Failed. | 98 99**示例**: 100 101```ts 102motion.off('operatingHandChanged', (data:motion.OperatingHandStatus) => { 103 console.info('off success' + data); 104}) 105``` 106 107 108 109## motion.getRecentOperatingHandStatus() 110 111getRecentOperatingHandStatus(): OperatingHandStatus; 112 113获取最新触控操作手状态。 114 115**需要权限**:ohos.permission.ACTIVITY_MOTION 116 117**系统能力**:SystemCapability.MultimodalAwarness.Motion 118 119**返回值**: 120 121| 类型 | 说明 | 122| ----------------------------- | ------------------------------------ | 123| [OperatingHandStatus](#operatinghandstatus) | 返回触控操作手状态信息。 | 124 125**错误码**: 126 127以下错误码的详细介绍请参见[行为动作感知错误码](errorcode-motion.md)和[通用错误码](../errorcode-universal.md)。 128 129| 错误码ID | 错误信息 | 130| -------- | ------------------------------------------------------------ | 131| 201 | Permission denied. | 132| 801 | Capability not supported.Function can not work correctly due to limited device capabilities. | 133| 31500001 | Service exception. | 134 135**示例**: 136 137```ts 138let data:motion.OperatingHandStatus = motion.getRecentOperatingHandStatus(); 139console.info('get success' + data); 140``` 141 142