1e41f4b71Sopenharmony_ci# Input Monitor Development 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## When to Use 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciThe **inputMonitor** module provides capabilities such as listening for key events and touchpad gestures. For example, if your application needs to implement a dedicated function when a three-finger swipe-up gesture occurs on the touchpad, you can listen for three-finger swipe-up events to serve that purpose. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci## Modules to Import 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci```js 10e41f4b71Sopenharmony_ciimport { inputMonitor } from '@kit.InputKit'; 11e41f4b71Sopenharmony_ci``` 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## Available APIs 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciThe following table lists the common APIs provided by the **inputMonitor** module. For details, see [ohos.multimodalInput.inputMonitor](../../reference/apis-input-kit/js-apis-inputmonitor-sys.md). 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci| API | Description| 18e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | -------------------------- | 19e41f4b71Sopenharmony_ci| on(type: 'mouse', receiver: Callback<MouseEvent>): void |Listens for mouse events.| 20e41f4b71Sopenharmony_ci| on(type: 'touch', receiver: TouchEventReceiver): void | Listens for touchscreen events.| 21e41f4b71Sopenharmony_ci| on(type: 'pinch', receiver: TouchEventReceiver): void | Listens for pinch events.| 22e41f4b71Sopenharmony_ci| on(type: 'threeFingersSwipe', receiver: Callback<ThreeFingersSwipe>): void | Listens for three-finger swipe-up events.| 23e41f4b71Sopenharmony_ci| on(type: 'threeFingersTap', receiver: Callback<ThreeFingersSwipe>): void | Listens for three-finger tap events.| 24e41f4b71Sopenharmony_ci| on(type: 'fourFingersSwipe', receiver: Callback<FourFingersSwipe>): void | Listens for four-finger swipe events.| 25e41f4b71Sopenharmony_ci| on(type: 'rotate', fingers: number, receiver: Callback<Rotate>): void | Listens for rotation events.| 26e41f4b71Sopenharmony_ci| off(type: 'mouse', receiver: Callback<MouseEvent>): void |Cancels listening for mouse events.| 27e41f4b71Sopenharmony_ci| off(type: 'touch', receiver: TouchEventReceiver): void | Cancels listening for touchscreen events.| 28e41f4b71Sopenharmony_ci| off(type: 'pinch', receiver: TouchEventReceiver): void | Cancels listening for pinch events.| 29e41f4b71Sopenharmony_ci| off(type: 'threeFingersSwipe', receiver: Callback<ThreeFingersSwipe>): void | Cancels listening for three-finger swipe-up events.| 30e41f4b71Sopenharmony_ci| off(type: 'threeFingersTap', receiver: Callback<ThreeFingersSwipe>): void | Cancels listening for three-finger tap events.| 31e41f4b71Sopenharmony_ci| off(type: 'fourFingersSwipe', receiver: Callback<FourFingersSwipe>): void | Cancels listening for four-finger swipe events.| 32e41f4b71Sopenharmony_ci| off(type: 'rotate', fingers: number, receiver: Callback<Rotate>): void | Cancels listening for rotation events.| 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci## How to Develop 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ciThis example assumes that the application needs to change the style based on the mouse button pressing status. Specifically, listen for mouse button events by calling [on](../../reference/apis-input-kit/js-apis-inputmonitor-sys.md#inputmonitoronmouse9), and cancel listening for mouse button events by calling [off](../../reference/apis-input-kit/js-apis-inputmonitor-sys.md#inputmonitoroffmouse9). 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci```js 39e41f4b71Sopenharmony_ciimport { MouseEvent } from '@kit.InputKit'; 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_cilet BUTTON_DOWN = 2; 42e41f4b71Sopenharmony_cilet callback = (mouseEvent: MouseEvent) => { 43e41f4b71Sopenharmony_ci console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`); 44e41f4b71Sopenharmony_ci if(mouseEvent.action = BUTTON_DOWN){ 45e41f4b71Sopenharmony_ci return true;// Callback triggered when the mouse button is pressed. 46e41f4b71Sopenharmony_ci } 47e41f4b71Sopenharmony_ci return false; 48e41f4b71Sopenharmony_ci}; 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_citry { 51e41f4b71Sopenharmony_ci inputMonitor.on('mouse', (mouseEvent: MouseEvent) => {// Start to listen for mouse events. 52e41f4b71Sopenharmony_ci console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`); 53e41f4b71Sopenharmony_ci return false; 54e41f4b71Sopenharmony_ci }); 55e41f4b71Sopenharmony_ci} catch (error) { 56e41f4b71Sopenharmony_ci console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 57e41f4b71Sopenharmony_ci} 58e41f4b71Sopenharmony_ci// Callback triggered when the mouse button is pressed. 59e41f4b71Sopenharmony_citry { 60e41f4b71Sopenharmony_ci inputMonitor.off('mouse', callback);// Cancel listening for mouse events. 61e41f4b71Sopenharmony_ci console.log(`Monitor off success`); 62e41f4b71Sopenharmony_ci} catch (error) { 63e41f4b71Sopenharmony_ci console.log(`Monitor off failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 64e41f4b71Sopenharmony_ci} 65e41f4b71Sopenharmony_ci``` 66