js-apis-inputeventclient.md 1.5 KB
Newer Older
S
shawn_he 已提交
1
# Key Injection
E
ester.zhou 已提交
2 3


S
shawn_he 已提交
4
> **NOTE**<br>
E
ester.zhou 已提交
5
>
S
shawn_he 已提交
6
> 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.
E
ester.zhou 已提交
7
>
S
shawn_he 已提交
8
> The APIs of this module are system APIs and cannot be called by third-party applications.
E
ester.zhou 已提交
9 10 11 12 13


## Modules to Import


S
shawn_he 已提交
14
```js
E
ester.zhou 已提交
15 16 17 18 19 20 21 22
import inputEventClient from '@ohos.multimodalInput.inputEventClient';
```


## inputEventClient.injectEvent

injectEvent({KeyEvent: KeyEvent}): void

S
shawn_he 已提交
23
Injects a key event.
E
ester.zhou 已提交
24 25 26 27 28

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

**Parameters**

S
shawn_he 已提交
29 30 31
| Name      | Type                   | Mandatory  | Description       |
| -------- | --------------------- | ---- | --------- |
| KeyEvent | [KeyEvent](#keyevent) | Yes   | Information about the key event to inject.|
E
ester.zhou 已提交
32 33 34

**Example**

S
shawn_he 已提交
35
```js
E
ester.zhou 已提交
36 37 38 39 40 41
let keyEvent = {
    isPressed: true,
    keyCode: 2,
    keyDownDuration: 0,
    isIntercepted: false
}
S
shawn_he 已提交
42
let res = inputEventClient.injectEvent({KeyEvent: keyEvent});
E
ester.zhou 已提交
43 44 45 46 47
```


## KeyEvent

S
shawn_he 已提交
48
Defines the information about the key event to inject.
E
ester.zhou 已提交
49 50 51

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

S
shawn_he 已提交
52 53 54 55 56 57 58 59
**Parameters**

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