js-apis-keyevent.md 2.5 KB
Newer Older
S
shawn_he 已提交
1
# @ohos.multimodalInput.keyEvent (Key Event)
S
shawn_he 已提交
2

S
shawn_he 已提交
3
The **keyEvent** module provides key events reported by input devices.
S
shawn_he 已提交
4

S
shawn_he 已提交
5 6
>  **NOTE**
>
S
shawn_he 已提交
7 8 9 10 11
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

## Modules to Import

```js
S
shawn_he 已提交
12
import {Action, Key, KeyEvent} from '@ohos.multimodalInput.keyEvent';
S
shawn_he 已提交
13 14 15 16
```

## Action

S
shawn_he 已提交
17
Key event type.
S
shawn_he 已提交
18

S
shawn_he 已提交
19 20
**System capability**: SystemCapability.MultimodalInput.Input.Core

S
shawn_he 已提交
21 22
| Name  | Value | Description    |
| ------ | ------- | -------- |
S
shawn_he 已提交
23
| CANCEL | 0    | Cancellation of a key action.|
S
shawn_he 已提交
24 25
| DOWN   | 1    | Pressing of a key.|
| UP     | 2    | Release of a key.|
S
shawn_he 已提交
26 27 28

## Key

S
shawn_he 已提交
29 30
Defines a key.

S
shawn_he 已提交
31 32
**System capability**: SystemCapability.MultimodalInput.Input.Core

S
shawn_he 已提交
33 34 35
| Name       | Type| Readable| Writable| Description          |
| ----------- | -------- | ---- | ---- | -------------- |
| code        | KeyCode  | Yes  | No  | Keycode.        |
S
shawn_he 已提交
36
| pressedTime | number   | Yes  | No  | Duration for pressing a key, in μs.|
S
shawn_he 已提交
37
| deviceId    | number   | Yes  | No  | ID of the device to which the key belongs.  |
S
shawn_he 已提交
38 39 40

## KeyEvent

S
shawn_he 已提交
41
Key event.
S
shawn_he 已提交
42

S
shawn_he 已提交
43 44
**System capability**: SystemCapability.MultimodalInput.Input.Core

S
shawn_he 已提交
45 46
| Name       | Type| Readable| Writable| Description                          |
| ----------- | -------- | ---- | ---- | ------------------------------ |
S
shawn_he 已提交
47 48
| action      | [Action](#action)   | Yes  | No  | Key action.                      |
| key         | [Key](#key)      | Yes  | No  | Key for which the event is reported.            |
S
shawn_he 已提交
49 50
| unicodeChar | number   | Yes  | No  | Unicode character corresponding to the key.         |
| keys        | Key[]    | Yes  | No  | List of pressed keys.    |
S
shawn_he 已提交
51
| ctrlKey     | boolean  | Yes  | No  | Whether ctrlKey is being pressed.<br>The value **true** indicates that the key is pressed, and the value **false** indicates the opposite.|
S
shawn_he 已提交
52 53 54 55
| altKey      | boolean  | Yes  | No  | Whether altKey is being pressed.    |
| shiftKey    | boolean  | Yes  | No  | Whether shiftKey is being pressed.  |
| logoKey     | boolean  | Yes  | No  | Whether logoKey is being pressed.   |
| fnKey       | boolean  | Yes  | No  | Whether fnKey is being pressed.     |
S
shawn_he 已提交
56
| capsLock    | boolean  | Yes  | No  | Whether capsLock is active.<br>The value **true** indicates that capsLock is active, and the value **false** indicates the opposite.  |
S
shawn_he 已提交
57 58
| numLock     | boolean  | Yes  | No  | Whether numLock is active.   |
| scrollLock  | boolean  | Yes  | No  | Whether scrollLock is active.|