js-apis-keyevent.md 2.2 KB
Newer Older
S
shawn_he 已提交
1
# @ohos.multimodalInput.keyEvent
S
shawn_he 已提交
2

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

S
shawn_he 已提交
5
> **NOTE**<br>
S
shawn_he 已提交
6 7 8 9 10
> 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 已提交
11
import {Action, Key, KeyEvent} from '@ohos.multimodalInput.keyEvent';
S
shawn_he 已提交
12 13 14 15 16 17
```

## Action

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

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

## Key

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

S
shawn_he 已提交
28 29 30 31 32
| Name       | Type| Readable| Writable| Description          |
| ----------- | -------- | ---- | ---- | -------------- |
| code        | KeyCode  | Yes  | No  | Keycode.        |
| pressedTime | number   | Yes  | No  | Time when the key is pressed.|
| deviceId    | number   | Yes  | No  | ID of the device to which the key belongs.  |
S
shawn_he 已提交
33 34 35 36 37

## KeyEvent

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

S
shawn_he 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51
| Name       | Type| Readable| Writable| Description                          |
| ----------- | -------- | ---- | ---- | ------------------------------ |
| action      | Action   | Yes  | No  | Key action.                      |
| key         | Key      | Yes  | No  | Key for which the event is reported.            |
| unicodeChar | number   | Yes  | No  | Unicode character corresponding to the key.         |
| keys        | Key[]    | Yes  | No  | List of pressed keys.    |
| ctrlKey     | boolean  | Yes  | No  | Whether ctrlKey is being pressed.   |
| 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.     |
| capsLock    | boolean  | Yes  | No  | Whether capsLock is active.  |
| numLock     | boolean  | Yes  | No  | Whether numLock is active.   |
| scrollLock  | boolean  | Yes  | No  | Whether scrollLock is active.|