The keyEvent module provides key events reported by a device. It is inherited from InputEvent.
Key event type.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.MultimodalInput.Input.Core
| Name | Value | Description |
|---|---|---|
| CANCEL | 0 | Cancellation of a key action. |
| DOWN | 1 | Key press. |
| UP | 2 | Key release. |
Defines a key.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.MultimodalInput.Input.Core
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| code | KeyCode | No | No | Key code. |
| pressedTime | number | No | No | Time when the key is pressed, in microseconds (μs) since the system starts. |
| deviceId | number | No | No | Unique ID of the input device. If a physical device is repeatedly reinstalled or restarted, its ID may change. |
Key event.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.MultimodalInput.Input.Core
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| action | Action | No | No | Key event type. |
| key | Key | No | No | Defines a key. |
| unicodeChar | number | No | No | Unicode character corresponding to the key. |
| keys | Key[] | No | No | List of keys that are currently in the pressed state. |
| ctrlKey | boolean | No | No | Whether ctrlKey is being pressed. The value true indicates that the key is pressed, and the value false indicates the opposite. |
| altKey | boolean | No | No | Whether altKey is being pressed. The value true indicates that the key is pressed, and the value false indicates the opposite. |
| shiftKey | boolean | No | No | Whether shiftKey is being pressed. The value true indicates that the key is pressed, and the value false indicates the opposite. |
| logoKey | boolean | No | No | Whether logoKey is being pressed. The value true indicates that the key is pressed, and the value false indicates the opposite. |
| fnKey | boolean | No | No | Whether fnKey is being pressed. The value true indicates that the key is pressed, and the value false indicates the opposite. |
| capsLock | boolean | No | No | Whether capsLock is enabled. The value true indicates that capsLock is enabled, and the value false indicates the opposite. |
| numLock | boolean | No | No | Whether numLock is enabled. The value true indicates that numLock is enabled, and the value false indicates the opposite. |
| scrollLock | boolean | No | No | Whether scrollLock is enabled. The value true indicates that scrollLock is enabled, and the value false indicates the opposite. |