1# @ohos.multimodalInput.inputEventClient (Key Injection) 2 3The Key Injection module implements injection of key events. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> - The APIs provided by this module are system APIs. 10 11 12## Modules to Import 13 14 15```js 16import inputEventClient from '@ohos.multimodalInput.inputEventClient'; 17``` 18 19 20## inputEventClient.injectEvent 21 22injectEvent({KeyEvent: KeyEvent}): void 23 24Injects a key event. Currently, key injection is supported only for the **Back** key (key value 2). 25 26**System capability**: SystemCapability.MultimodalInput.Input.InputSimulator 27 28**Parameters** 29 30| Name | Type | Mandatory | Description | 31| -------- | --------------------- | ---- | --------- | 32| KeyEvent | [KeyEvent](#keyevent) | Yes | Information about the key event to inject.| 33 34**Example** 35 36```js 37try { 38 let backKeyDown: inputEventClient.KeyEvent = { 39 isPressed: true, 40 keyCode: 2, 41 keyDownDuration: 0, 42 isIntercepted: false 43 } 44 inputEventClient.injectEvent({ KeyEvent: backKeyDown }); 45 46 let backKeyUp: inputEventClient.KeyEvent = { 47 isPressed: false, 48 keyCode: 2, 49 keyDownDuration: 0, 50 isIntercepted: false 51 }; 52 inputEventClient.injectEvent({ KeyEvent: backKeyUp }); 53} catch (error) { 54 console.log(`Failed to inject KeyEvent, error: ${JSON.stringify(error, [`code`, `message`])}`); 55} 56``` 57 58 59## KeyEvent 60 61Represents information about the key event to inject. 62 63**System capability**: SystemCapability.MultimodalInput.Input.InputSimulator 64 65| Name | Type | Readable | Writable | Description | 66| --------- | ------ | ---- | ---- | ------- | 67| isPressed | boolean | Yes | No| Whether the key is pressed. | 68| keyCode | number | Yes | No| Key value. Currently, only the **Back** key is supported.| 69| keyDownDuration | number | Yes | No| Duration within which the key is pressed. | 70| isIntercepted | boolean | Yes | No| Whether the key can be intercepted. | 71