js-apis-inputeventclient.md 1.4 KB
Newer Older
E
ester.zhou 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
# Input Event Client


> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
>
> - 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.
>
> - The APIs of this module are system APIs and cannot be called by third-party applications.


## Modules to Import


```
import inputEventClient from '@ohos.multimodalInput.inputEventClient';
```


## inputEventClient.injectEvent

injectEvent({KeyEvent: KeyEvent}): void

Injects a key.

**System capability**: SystemCapability.MultimodalInput.Input.InputSimulator

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| KeyEvent | [KeyEvent](#keyevent) | Yes| Information about the key to inject.|

**Example**

```
let keyEvent = {
    isPressed: true,
    keyCode: 2,
    keyDownDuration: 0,
    isIntercepted: false
}
res = inputEventClient.injectEvent({KeyEvent: keyEvent});
```


## KeyEvent

Defines the information about the key to inject.

**System capability**: SystemCapability.MultimodalInput.Input.InputSimulator

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| isPressed | boolean | Yes| Whether the key is pressed.|
| keyCode | Number | Yes| Key code.|
| keyDownDuration | boolean | Yes| Duration for which the key is pressed.|
| isIntercepted | Number | Yes| Whether the key can be intercepted.|