openharmony 鸿蒙 js-apis-keyevent

2025-06-12 浏览 (1)

@ohos.multimodalInput.keyEvent (Key Event)

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

import { Action, Key, KeyEvent } from '@kit.InputKit';

Action

Key event type.

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

System capability: SystemCapability.MultimodalInput.Input.Core

NameValueDescription
CANCEL0Cancellation of a key action.
DOWN1Key press.
UP2Key release.

Key

Defines a key.

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

System capability: SystemCapability.MultimodalInput.Input.Core

NameTypeReadableWritableDescription
codeKeyCodeYesNoKeycode.
pressedTimenumberYesNoDuration for pressing a key, in μs.
deviceIdnumberYesNoID of the device to which the key belongs.

KeyEvent

Key event.

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

System capability: SystemCapability.MultimodalInput.Input.Core

NameTypeReadableWritableDescription
actionActionYesNoKey action.
keyKeyYesNoKey for which the event is reported.
unicodeCharnumberYesNoUnicode character corresponding to the key.
keysKey []YesNoList of pressed keys.
ctrlKeybooleanYesNoWhether ctrlKey is being pressed.
The value true indicates that the key is pressed, and the value false indicates the opposite.
altKeybooleanYesNoWhether altKey is being pressed.
The value true indicates that the key is pressed, and the value false indicates the opposite.
shiftKeybooleanYesNoWhether shiftKey is being pressed.
The value true indicates that the key is pressed, and the value false indicates the opposite.
logoKeybooleanYesNoWhether logoKey is being pressed.
The value true indicates that the key is pressed, and the value false indicates the opposite.
fnKeybooleanYesNoWhether fnKey is being pressed.
The value true indicates that the key is pressed, and the value false indicates the opposite.
capsLockbooleanYesNoWhether capsLock is active.
The value true indicates that capsLock is active, and the value false indicates the opposite.
numLockbooleanYesNoWhether numLock is active.
The value true indicates that numLock is active, and the value false indicates the opposite.
scrollLockbooleanYesNoWhether scrollLock is active.
The value true indicates that scrollLock is active, and the value false indicates the opposite.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Input Kit

harmony 鸿蒙Input_DeviceListener

harmony 鸿蒙Input_InterceptorEventCallback

harmony 鸿蒙Input_AxisEvent

harmony 鸿蒙Input_DeviceInfo

harmony 鸿蒙Input_DeviceListener

harmony 鸿蒙Input_Hotkey

harmony 鸿蒙Input_InterceptorEventCallback

harmony 鸿蒙Input_InterceptorOptions

harmony 鸿蒙Input_KeyEvent

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/QDAq4m