1# Event Injection Development 2 3## When to Use 4 5The **inputEventClient** module provides the function of injecting input events, such as mouse click events and combination key events. For example, if you need to verify the combination key function of an application, you can listen for combination key events to serve that purpose. 6 7## Modules to Import 8 9```js 10import { inputEventClient } from '@kit.InputKit'; 11``` 12 13## Available APIs 14 15The following table lists the common APIs provided by the **inputEventClient** module. For details, see [ohos.multimodalInput.inputEventClient](../../reference/apis-input-kit/js-apis-inputeventclient-sys.md). 16 17| API | Description| 18| -------------------------------------------- | -------------------------- | 19| injectEvent({KeyEvent: KeyEvent}): void |Injects keys (including single keys and combination keys).| 20| injectMouseEvent(mouseEvent: MouseEventData): void |Injects a mouse/touchpad event.| 21| injectTouchEvent(touchEvent: TouchEventData): void |Injects a touchscreen event.| 22 23## How to Develop 24 25Assume that an application calls the Home key to return to the home screen. When the Home key is pressed, check whether [injectEvent](../../reference/apis-input-kit/js-apis-inputeventclient-sys.md#inputeventclientinjectevent) is called to inject the Home key to determine if the Home key takes effect. 26 27```js 28try { 29 let backKeyDown: inputEventClient.KeyEvent = { 30 isPressed: true, 31 keyCode: 2, 32 keyDownDuration: 0, 33 isIntercepted: false 34 }// Home key pressing event 35 36 class EventDown { 37 KeyEvent: inputEventClient.KeyEvent | null = null 38 } 39 40 let eventDown: EventDown = { KeyEvent: backKeyDown } 41 inputEventClient.injectEvent(eventDown);// Inject the Home key pressing event. 42 43 let backKeyUp: inputEventClient.KeyEvent = { 44 isPressed: false, 45 keyCode: 2, 46 keyDownDuration: 0, 47 isIntercepted: false 48 };// Home key release event. 49 50 class EventUp { 51 KeyEvent: inputEventClient.KeyEvent | null = null 52 } 53 54 let eventUp: EventUp = { KeyEvent: backKeyUp } 55 inputEventClient.injectEvent(eventUp);// Inject the Home key release event and check whether the Home key function takes effect and whether the application returns to the home screen. 56} catch (error) { 57 console.log(`Failed to inject KeyEvent, error: ${JSON.stringify(error, [`code`, `message`])}`); 58} 59``` 60