1# @ohos.multimodalawareness.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.MultimodalAwareness.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.MultimodalAwareness.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. An attempt was made to subscribe operatingHandChanged event forbidden by permission: ohos.permission.ACTIVITY_MOTION. | 55| 401 | Parameter error. 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 63import { BusinessError } from '@kit.BasicServicesKit'; 64 65callback(data:motion.OperatingHandStatus) { 66 console.info('callback success' + data); 67} 68 69try { 70 motion.on('operatingHandChanged', this.callback); 71 console.info("on succeeded"); 72} catch (err) { 73 let error = err as BusinessError; 74 console.error("Failed on and err code is " + error.code); 75} 76``` 77 78 79 80## motion.off('operatingHandChanged') 81 82off(type: 'operatingHandChanged', callback?: Callback<OperatingHandStatus>): void; 83 84取消订阅触控操作手感知事件。 85 86**需要权限**:ohos.permission.ACTIVITY_MOTION 87 88**系统能力**:SystemCapability.MultimodalAwareness.Motion 89 90**参数**: 91 92| 参数名 | 类型 | 必填 | 说明 | 93| -------- | -------------------------------- | ---- | ------------------------------------------------------------ | 94| type | string | 是 | 事件类型。type为“operatingHandChanged”,表示操作手状态变化。 | 95| callback | Callback<[OperatingHandStatus](#operatinghandstatus)> | 否 | 回调函数,返回操作手结果。 | 96 97**错误码**: 98 99以下错误码的详细介绍请参见[行为动作感知错误码](errorcode-motion.md)和[通用错误码](../errorcode-universal.md)。 100 101| 错误码ID | 错误信息 | 102| -------- | ------------------------------------------------------------ | 103| 201 | Permission denied. An attempt was made to unsubscribe operatingHandChanged event forbidden by permission: ohos.permission.ACTIVITY_MOTION. | 104| 401 | Parameter error. Parameter verification failed. | 105| 801 | Capability not supported. Function can not work correctly due to limited device capabilities. | 106| 31500001 | Service exception. | 107| 31500003 | Unsubscribe Failed. | 108 109**示例**: 110 111```ts 112import { BusinessError } from '@kit.BasicServicesKit'; 113 114try { 115 motion.off('operatingHandChanged'); 116 console.info("off succeeded"); 117} catch (err) { 118 let error = err as BusinessError; 119 console.error("Failed off and err code is " + error.code); 120} 121``` 122 123 124 125## motion.getRecentOperatingHandStatus() 126 127getRecentOperatingHandStatus(): OperatingHandStatus; 128 129获取最新触控操作手状态。 130 131**需要权限**:ohos.permission.ACTIVITY_MOTION 132 133**系统能力**:SystemCapability.MultimodalAwareness.Motion 134 135**返回值**: 136 137| 类型 | 说明 | 138| ----------------------------- | ------------------------------------ | 139| [OperatingHandStatus](#operatinghandstatus) | 返回触控操作手状态信息。 | 140 141**错误码**: 142 143以下错误码的详细介绍请参见[行为动作感知错误码](errorcode-motion.md)和[通用错误码](../errorcode-universal.md)。 144 145| 错误码ID | 错误信息 | 146| -------- | ------------------------------------------------------------ | 147| 201 | Permission denied. An attempt was made to get the recent operating hand status forbidden by permission: ohos.permission.ACTIVITY_MOTION. | 148| 801 | Capability not supported. Function can not work correctly due to limited device capabilities. | 149| 31500001 | Service exception. | 150 151**示例**: 152 153```ts 154import { BusinessError } from '@kit.BasicServicesKit'; 155 156try { 157 let data:motion.OperatingHandStatus = motion.getRecentOperatingHandStatus(); 158 console.info('get success' + data); 159} catch (err) { 160 let error = err as BusinessError; 161 console.error("Failed get and err code is " + error.code); 162} 163``` 164 165