1# Motion Awareness Development 2 3## When to Use 4 5An application can call the motion module to identify user actions, for example, whether the user is operating the device screen with the left hand or the right hand. 6 7For details about the APIs, see [Motion API Reference](../../reference/apis-multimodalawareness-kit/js-apis-awareness-motion.md). 8 9## Available APIs 10 11| API | Description | 12| ------------------------------------------------------------ | -------------------------------------- | 13| on(type:'operatingHandChanged',callback:Callback<OperatingHandStatus>):void; | Subscribes to operating hand change events. This API uses a callback to return the result.| 14| off(type: 'operatingHandChanged', callback?: Callback<OperatingHandStatus>): void; | Unsubscribes from operating hand change events. | 15| getRecentOperatingHandStatus(): OperatingHandStatus; | Obtains the latest operating hand status. | 16 17## Constraints 18 19 - The device must support the touchscreen and be compatible with specific chips. 20 21 - Knuckle operations are not categorized as hand operations. 22 23 - Multi-finger operations are not supported in window rotation scenarios. 24 25 - The effective range does not include the area within 8 mm from the screen edge. 26 27 28 29 30## How to Develop 31 321. Import the related modules. 33 34 ```ts 35 import { motion } from '@kit.MultimodalAwarenessKit'; 36 import { BusinessError } from '@kit.BasicServicesKit'; 37 ``` 38 392. Define a callback to receive operating hand change results. 40 41 ``` 42 callback(data:motion.OperatingHandStatus) { 43 console.info('callback success' + data); 44 } 45 ``` 46 473. Subscribe to operating hand change results. 48 49 ``` 50 try { 51 motion.on('operatingHandChanged', this.callback); 52 console.info("on succeeded"); 53 } catch (err) { 54 let error = err as BusinessError; 55 console.error("Failed on and err code is " + error.code); 56 } 57 ``` 58 594. Unsubscribe from operating hand change events. 60 61 ``` 62 try { 63 motion.off('operatingHandChanged'); 64 console.info("off succeeded"); 65 } catch (err) { 66 let error = err as BusinessError; 67 console.error("Failed off and err code is " + error.code); 68 } 69 ``` 70 715. Obtain the latest operating hand status. 72 73 ``` 74 try { 75 let data:motion.OperatingHandStatus = motion.getRecentOperatingHandStatus(); 76 console.info('get success' + data); 77 } catch (err) { 78 let error = err as BusinessError; 79 console.error("Failed get and err code is " + error.code); 80 } 81 ``` 82 83 84