1e41f4b71Sopenharmony_ci# Event Injection Development
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## When to Use
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciThe **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.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci## Modules to Import
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci```js
10e41f4b71Sopenharmony_ciimport { inputEventClient } from '@kit.InputKit';
11e41f4b71Sopenharmony_ci```
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## Available APIs
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ciThe 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).
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci| API | Description|
18e41f4b71Sopenharmony_ci| -------------------------------------------- | -------------------------- |
19e41f4b71Sopenharmony_ci| injectEvent({KeyEvent: KeyEvent}): void |Injects keys (including single keys and combination keys).|
20e41f4b71Sopenharmony_ci| injectMouseEvent(mouseEvent: MouseEventData): void |Injects a mouse/touchpad event.|
21e41f4b71Sopenharmony_ci| injectTouchEvent(touchEvent: TouchEventData): void |Injects a touchscreen event.|
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci## How to Develop
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ciAssume 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.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci```js
28e41f4b71Sopenharmony_citry {
29e41f4b71Sopenharmony_ci  let backKeyDown: inputEventClient.KeyEvent = {
30e41f4b71Sopenharmony_ci    isPressed: true,
31e41f4b71Sopenharmony_ci    keyCode: 2,
32e41f4b71Sopenharmony_ci    keyDownDuration: 0,
33e41f4b71Sopenharmony_ci    isIntercepted: false
34e41f4b71Sopenharmony_ci  }// Home key pressing event
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci  class EventDown {
37e41f4b71Sopenharmony_ci    KeyEvent: inputEventClient.KeyEvent | null = null
38e41f4b71Sopenharmony_ci  }
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci  let eventDown: EventDown = { KeyEvent: backKeyDown }
41e41f4b71Sopenharmony_ci  inputEventClient.injectEvent(eventDown);// Inject the Home key pressing event.
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci  let backKeyUp: inputEventClient.KeyEvent = {
44e41f4b71Sopenharmony_ci    isPressed: false,
45e41f4b71Sopenharmony_ci    keyCode: 2,
46e41f4b71Sopenharmony_ci    keyDownDuration: 0,
47e41f4b71Sopenharmony_ci    isIntercepted: false
48e41f4b71Sopenharmony_ci  };// Home key release event.
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci  class EventUp {
51e41f4b71Sopenharmony_ci    KeyEvent: inputEventClient.KeyEvent | null = null
52e41f4b71Sopenharmony_ci  }
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci  let eventUp: EventUp = { KeyEvent: backKeyUp }
55e41f4b71Sopenharmony_ci  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.
56e41f4b71Sopenharmony_ci} catch (error) {
57e41f4b71Sopenharmony_ci  console.log(`Failed to inject KeyEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
58e41f4b71Sopenharmony_ci}
59e41f4b71Sopenharmony_ci```
60