We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
ReferencesSystemBasic FunctionsInput KitArkTS APIs@ohos.multimodalInput.keyEvent (Key Event)

@ohos.multimodalInput.keyEvent (Key Event)

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

The keyEvent module provides key events reported by a device. It is inherited from InputEvent.

NOTE
  • 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

Collapse
Word wrap
Dark theme
Copy code
  1. import { Action, Key, KeyEvent } from '@kit.InputKit';

Action

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

Key event type.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.MultimodalInput.Input.Core

Expand
Name Value Description
CANCEL 0 Cancellation of a key action.
DOWN 1 Key press.
UP 2 Key release.

Key

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

Defines a key.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.MultimodalInput.Input.Core

Expand
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.

KeyEvent

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

Key event.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.MultimodalInput.Input.Core

Expand
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 pressed keys.
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.