openharmony 鸿蒙 capi-native-key-event-h

2026-08-25 浏览 (1)

native_key_event.h

Overview

Declares the APIs of NativeKeyEvent.

File to include: <arkui/native_key_event.h>

Library: libace_ndk.z.so

System capability: SystemCapability.ArkUI.ArkUI.Full

Since: 14

Related module: ArkUI_NativeModule

Sample: NdkKeyEvent

Summary

Enums

Nametypedef KeywordDescription
ArkUI_KeyCodeArkUI_KeyCodeEnumerates the key codes for key events.
ArkUI_KeyEventTypeArkUI_KeyEventTypeEnumerates the types of key events.
ArkUI_KeySourceTypeArkUI_KeySourceTypeEnumerates the types of input devices that trigger key events.
ArkUI_KeyIntensionArkUI_KeyIntensionEnumerates the intentions corresponding to key events.

Functions

NameDescription
ArkUI_KeyEventType OH_ArkUI_KeyEvent_GetType(const ArkUI_UIInputEvent* event)Obtains the type of the specified key event.
int32_t OH_ArkUI_KeyEvent_GetKeyCode(const ArkUI_UIInputEvent* event)Obtains the key code from the specified key event.
const char OH_ArkUI_KeyEvent_GetKeyText(const ArkUI_UIInputEvent event)Obtains the key value from the specified key event.
ArkUI_KeySourceType OH_ArkUI_KeyEvent_GetKeySource(const ArkUI_UIInputEvent* event)Obtains the type of input device that triggers the specified key event.
void OH_ArkUI_KeyEvent_StopPropagation(const ArkUI_UIInputEvent* event, bool stopPropagation)Stops the specified key event from bubbling upwards or downwards.
ArkUI_KeyIntension OH_ArkUI_KeyEvent_GetKeyIntensionCode(const ArkUI_UIInputEvent* event)Obtains the intention code associated with the specified key event.
uint32_t OH_ArkUI_KeyEvent_GetUnicode(const ArkUI_UIInputEvent* event)Obtains the Unicode value of the specified key event. Non-space basic Latin characters in the 0x0021-0x007E range are supported. Characters with a value of 0 are not supported. In the case of key combination, this API returns the Unicode value of the key corresponding to the key event.
void OH_ArkUI_KeyEvent_SetConsumed(const ArkUI_UIInputEvent* event, bool isConsumed)Sets whether the specified key event is consumed in the key event callback.
void OH_ArkUI_KeyEvent_Dispatch(ArkUI_NodeHandle node, const ArkUI_UIInputEvent* event)Dispatches the specified key event to a specific node.
ArkUI_ErrorCode OH_ArkUI_KeyEvent_IsNumLockOn(const ArkUI_UIInputEvent* event, bool* state)Obtains the state of the NumLock key when the specified key event occurs.
ArkUI_ErrorCode OH_ArkUI_KeyEvent_IsCapsLockOn(const ArkUI_UIInputEvent* event, bool* state)Obtains the state of the CapsLock key when the specified key event occurs.
ArkUI_ErrorCode OH_ArkUI_KeyEvent_IsScrollLockOn(const ArkUI_UIInputEvent* event, bool* state)Obtains the state of the ScrollLock key when the specified key event occurs.

Enum Description

ArkUI_KeyCode

enum ArkUI_KeyCode

Description

Enumerates the key codes for key events.

Since: 14

ValueDescription
ARKUI_KEYCODE_UNKNOWN = -1Unknown key
ARKUI_KEYCODE_FN = 0Function (Fn) key
ARKUI_KEYCODE_VOLUME_UP = 16Volume Up key
ARKUI_KEYCODE_VOLUME_DOWN = 17Volume Down key
ARKUI_KEYCODE_POWER = 18Power key
ARKUI_KEYCODE_CAMERA = 19Camera key
ARKUI_KEYCODE_VOLUME_MUTE = 22Speaker Mute key
ARKUI_KEYCODE_MUTE = 23Mute key
ARKUI_KEYCODE_BRIGHTNESS_UP = 40Brightness Up key.
ARKUI_KEYCODE_BRIGHTNESS_DOWN = 41Brightness Down key.
ARKUI_KEYCODE_0 = 2000Key 0
ARKUI_KEYCODE_1 = 2001Key 1
ARKUI_KEYCODE_2 = 2002Key 2
ARKUI_KEYCODE_3 = 2003Key 3
ARKUI_KEYCODE_4 = 2004Key 4
ARKUI_KEYCODE_5 = 2005Key 5
ARKUI_KEYCODE_6 = 2006Key 6
ARKUI_KEYCODE_7 = 2007Key 7
ARKUI_KEYCODE_8 = 2008Key 8
ARKUI_KEYCODE_9 = 2009Key 9
ARKUI_KEYCODE_STAR = 2010Key *
ARKUI_KEYCODE_POUND = 2011Key #
ARKUI_KEYCODE_DPAD_UP = 2012Up key on D-pad.
ARKUI_KEYCODE_DPAD_DOWN = 2013Down key on D-pad.
ARKUI_KEYCODE_DPAD_LEFT = 2014Left key on D-pad.
ARKUI_KEYCODE_DPAD_RIGHT = 2015Right key on D-pad.
ARKUI_KEYCODE_DPAD_CENTER = 2016Center key on D-pad.
ARKUI_KEYCODE_A = 2017Key A
ARKUI_KEYCODE_B = 2018Key B
ARKUI_KEYCODE_C = 2019Key C
ARKUI_KEYCODE_D = 2020Key D
ARKUI_KEYCODE_E = 2021Key E
ARKUI_KEYCODE_F = 2022Key F
ARKUI_KEYCODE_G = 2023Key G
ARKUI_KEYCODE_H = 2024Key H
ARKUI_KEYCODE_I = 2025Key I
ARKUI_KEYCODE_J = 2026Key J
ARKUI_KEYCODE_K = 2027Key K
ARKUI_KEYCODE_L = 2028Key L
ARKUI_KEYCODE_M = 2029Key M
ARKUI_KEYCODE_N = 2030Key N
ARKUI_KEYCODE_O = 2031Key O
ARKUI_KEYCODE_P = 2032Key P
ARKUI_KEYCODE_Q = 2033Key Q
ARKUI_KEYCODE_R = 2034Key R
ARKUI_KEYCODE_S = 2035Key S
ARKUI_KEYCODE_T = 2036Key T
ARKUI_KEYCODE_U = 2037Key U
ARKUI_KEYCODE_V = 2038Key V
ARKUI_KEYCODE_W = 2039Key W
ARKUI_KEYCODE_X = 2040Key X
ARKUI_KEYCODE_Y = 2041Key Y
ARKUI_KEYCODE_Z = 2042Key Z
ARKUI_KEYCODE_COMMA = 2043Key ,
ARKUI_KEYCODE_PERIOD = 2044Key .
ARKUI_KEYCODE_ALT_LEFT = 2045Left Alt key
ARKUI_KEYCODE_ALT_RIGHT = 2046Right Alt key
ARKUI_KEYCODE_SHIFT_LEFT = 2047Left Shift key
ARKUI_KEYCODE_SHIFT_RIGHT = 2048Right Shift key
ARKUI_KEYCODE_TAB = 2049Tab key
ARKUI_KEYCODE_SPACE = 2050Space key
ARKUI_KEYCODE_SYM = 2051Symbol key
ARKUI_KEYCODE_EXPLORER = 2052Explorer key, which is used to start the explorer application
ARKUI_KEYCODE_ENVELOPE = 2053Email key, which is used to start the email application
ARKUI_KEYCODE_ENTER = 2054Enter key
ARKUI_KEYCODE_DEL = 2055Delete key
ARKUI_KEYCODE_GRAVE = 2056Key `
ARKUI_KEYCODE_MINUS = 2057Key -
ARKUI_KEYCODE_EQUALS = 2058Key =
ARKUI_KEYCODE_LEFT_BRACKET = 2059Key [
ARKUI_KEYCODE_RIGHT_BRACKET = 2060Key ]
ARKUI_KEYCODE_BACKSLASH = 2061Key \
ARKUI_KEYCODE_SEMICOLON = 2062Key ;
ARKUI_KEYCODE_APOSTROPHE = 2063Key '
ARKUI_KEYCODE_SLASH = 2064Key /
ARKUI_KEYCODE_AT = 2065Key @
ARKUI_KEYCODE_PLUS = 2066Key +
ARKUI_KEYCODE_MENU = 2067Menu key
ARKUI_KEYCODE_PAGE_UP = 2068Page Up key
ARKUI_KEYCODE_PAGE_DOWN = 2069Page Down key
ARKUI_KEYCODE_ESCAPE = 2070ESC key.
ARKUI_KEYCODE_FORWARD_DEL = 2071Forward Delete key
ARKUI_KEYCODE_CTRL_LEFT = 2072Left Ctrl key
ARKUI_KEYCODE_CTRL_RIGHT = 2073Right Ctrl key
ARKUI_KEYCODE_CAPS_LOCK = 2074Caps Lock key
ARKUI_KEYCODE_SCROLL_LOCK = 2075Scroll Lock key
ARKUI_KEYCODE_META_LEFT = 2076Left Meta key
ARKUI_KEYCODE_META_RIGHT = 2077Right Meta key
ARKUI_KEYCODE_FUNCTION = 2078Function key
ARKUI_KEYCODE_SYSRQ = 2079System Request/Print Screen key
ARKUI_KEYCODE_BREAK = 2080Break/Pause key
ARKUI_KEYCODE_MOVE_HOME = 2081Move to Home key
ARKUI_KEYCODE_MOVE_END = 2082Move to End key
ARKUI_KEYCODE_INSERT = 2083Insert key
ARKUI_KEYCODE_FORWARD = 2084Forward key
ARKUI_KEYCODE_MEDIA_PLAY = 2085Play key
ARKUI_KEYCODE_MEDIA_PAUSE = 2086Pause key
ARKUI_KEYCODE_MEDIA_CLOSE = 2087Close key
ARKUI_KEYCODE_MEDIA_EJECT = 2088Eject key
ARKUI_KEYCODE_MEDIA_RECORD = 2089Record key
ARKUI_KEYCODE_F1 = 2090F1 key
ARKUI_KEYCODE_F2 = 2091F2 key
ARKUI_KEYCODE_F3 = 2092F3 key
ARKUI_KEYCODE_F4 = 2093F4 key
ARKUI_KEYCODE_F5 = 2094F5 key
ARKUI_KEYCODE_F6 = 2095F6 key
ARKUI_KEYCODE_F7 = 2096F7 key
ARKUI_KEYCODE_F8 = 2097F8 key
ARKUI_KEYCODE_F9 = 2098F9 key
ARKUI_KEYCODE_F10 = 2099F10 key
ARKUI_KEYCODE_F11 = 2100F11 key
ARKUI_KEYCODE_F12 = 2101F12 key
ARKUI_KEYCODE_NUM_LOCK = 2102Number Lock key on numeric keypad
ARKUI_KEYCODE_NUMPAD_0 = 2103Key 0 on numeric keypad
ARKUI_KEYCODE_NUMPAD_1 = 2104Key 1 on numeric keypad
ARKUI_KEYCODE_NUMPAD_2 = 2105Key 2 on numeric keypad
ARKUI_KEYCODE_NUMPAD_3 = 2106Key 3 on numeric keypad
ARKUI_KEYCODE_NUMPAD_4 = 2107Key 4 on numeric keypad
ARKUI_KEYCODE_NUMPAD_5 = 2108Key 5 on numeric keypad
ARKUI_KEYCODE_NUMPAD_6 = 2109Key 6 on numeric keypad
ARKUI_KEYCODE_NUMPAD_7 = 2110Key 7 on numeric keypad
ARKUI_KEYCODE_NUMPAD_8 = 2111Key 8 on numeric keypad
ARKUI_KEYCODE_NUMPAD_9 = 2112Key 9 on numeric keypad
ARKUI_KEYCODE_NUMPAD_DIVIDE = 2113Key / on numeric keypad
ARKUI_KEYCODE_NUMPAD_MULTIPLY = 2114Key * on numeric keypad
ARKUI_KEYCODE_NUMPAD_SUBTRACT = 2115Key - on numeric keypad
ARKUI_KEYCODE_NUMPAD_ADD = 2116Key + on numeric keypad
ARKUI_KEYCODE_NUMPAD_DOT = 2117Key . on numeric keypad
ARKUI_KEYCODE_NUMPAD_COMMA = 2118Key , on numeric keypad
ARKUI_KEYCODE_NUMPAD_ENTER = 2119Enter key on numeric keypad
ARKUI_KEYCODE_NUMPAD_EQUALS = 2120Key = on numeric keypad
ARKUI_KEYCODE_NUMPAD_LEFT_PAREN = 2121Key ( on numeric keypad
ARKUI_KEYCODE_NUMPAD_RIGHT_PAREN = 2122Key ) on numeric keypad
ARKUI_KEYCODE_BUTTON_A = 2301Joystick key A
Since: 15
ARKUI_KEYCODE_BUTTON_B = 2302Joystick key B
Since: 15
ARKUI_KEYCODE_BUTTON_X = 2304Joystick key X
Since: 15
ARKUI_KEYCODE_BUTTON_Y = 2305Joystick key Y
Since: 15
ARKUI_KEYCODE_BUTTON_L1 = 2307Joystick key L1
Since: 15
ARKUI_KEYCODE_BUTTON_R1 = 2308Joystick key R1
Since: 15
ARKUI_KEYCODE_BUTTON_L2 = 2309Joystick key L2
Since: 15
ARKUI_KEYCODE_BUTTON_R2 = 2310Joystick key R2
Since: 15
ARKUI_KEYCODE_BUTTON_SELECT = 2311Joystick key Select
Since: 15
ARKUI_KEYCODE_BUTTON_START = 2312Joystick key Start
Since: 15
ARKUI_KEYCODE_BUTTON_MODE = 2313Joystick key Mode
Since: 15
ARKUI_KEYCODE_BUTTON_THUMBL = 2314Joystick key THUMBL
Since: 15
ARKUI_KEYCODE_BUTTON_THUMBR = 2315Joystick key THUMBR
Since: 15

ArkUI_KeyEventType

enum ArkUI_KeyEventType

Description

Enumerates the types of key events.

Since: 14

ValueDescription
ARKUI_KEY_EVENT_UNKNOWN = -1Unknown type.
ARKUI_KEY_EVENT_DOWN = 0Key press.
ARKUI_KEY_EVENT_UP = 1Release of a key.
ARKUI_KEY_EVENT_LONG_PRESS = 2Long press of a key.
ARKUI_KEY_EVENT_CLICK = 3Click of a key.

ArkUI_KeySourceType

enum ArkUI_KeySourceType

Description

Enumerates the types of input devices that trigger key events.

Since: 14

ValueDescription
ARKUI_KEY_SOURCE_UNKNOWN = 0Unknown type.
ARKUI_KEY_SOURCE_TYPE_MOUSE = 1Mouse.
ARKUI_KEY_SOURCE_TYPE_KEYBOARD = 4Keyboard.
ARKUI_KEY_SOURCE_TYPE_JOYSTICK = 5Game controller.
Since: 15

ArkUI_KeyIntension

enum ArkUI_KeyIntension

Description

Enumerates the intentions corresponding to key events.

Since: 14

ValueDescription
ARKUI_KEY_INTENSION_UNKNOWN = -1Unknown intention.
ARKUI_KEY_INTENSION_UP = 1Upward.
ARKUI_KEY_INTENSION_DOWN = 2Downward.
ARKUI_KEY_INTENSION_LEFT = 3Leftward.
ARKUI_KEY_INTENSION_RIGHT = 4Rightward.
ARKUI_KEY_INTENSION_SELECT = 5Select.
ARKUI_KEY_INTENSION_ESCAPE = 6Return.
ARKUI_KEY_INTENSION_BACK = 7Back.
ARKUI_KEY_INTENSION_FORWARD = 8Forward.
ARKUI_KEY_INTENSION_MENU = 9Menu.
ARKUI_KEY_INTENSION_HOME = 10Home page.
ARKUI_KEY_INTENSION_PAGE_UP = 11Previous.
ARKUI_KEY_INTENSION_PAGE_DOWN = 12Next.
ARKUI_KEY_INTENSION_ZOOM_OUT = 13Zoom out.
ARKUI_KEY_INTENSION_ZOOM_IN = 14Zoom in.
ARKUI_KEY_INTENTION_MEDIA_PLAY_PAUSE = 100Play.
ARKUI_KEY_INTENTION_MEDIA_FAST_FORWARD = 101Fast-forward.
ARKUI_KEY_INTENTION_MEDIA_FAST_PLAYBACK = 103Fast playback.
ARKUI_KEY_INTENTION_MEDIA_NEXT = 104Play the next media asset.
ARKUI_KEY_INTENTION_MEDIA_PREVIOUS = 105Play the previous media asset.
ARKUI_KEY_INTENTION_MEDIA_MUTE = 106Mute.
ARKUI_KEY_INTENTION_VOLUME_UP = 107Volume up.
ARKUI_KEY_INTENTION_VOLUME_DOWN = 108Volume down.
ARKUI_KEY_INTENTION_CALL = 200Answer a call.
ARKUI_KEY_INTENTION_CAMERA = 300Take a photo.

Function Description

OH_ArkUI_KeyEvent_GetType()

ArkUI_KeyEventType OH_ArkUI_KeyEvent_GetType(const ArkUI_UIInputEvent* event)

Description

Obtains the type of the specified key event.

Since: 14

Parameters

NameDescription
const ArkUI_UIInputEvent* eventPointer to the target ArkUI_UIInputEvent object.

Return value

TypeDescription
ArkUI_KeyEventTypeKey event type.

OH_ArkUI_KeyEvent_GetKeyCode()

int32_t OH_ArkUI_KeyEvent_GetKeyCode(const ArkUI_UIInputEvent* event)

Description

Obtains the key code from the specified key event.

Since: 14

Parameters

NameDescription
const ArkUI_UIInputEvent* eventPointer to the target ArkUI_UIInputEvent object.

Return value

TypeDescription
int32_tKey code.

OH_ArkUI_KeyEvent_GetKeyText()

const char *OH_ArkUI_KeyEvent_GetKeyText(const ArkUI_UIInputEvent* event)

Description

Obtains the key value from the specified key event.

Since: 14

Parameters

NameDescription
const ArkUI_UIInputEvent* eventPointer to the target ArkUI_UIInputEvent object.

Return value

TypeDescription
const char *Key value.

OH_ArkUI_KeyEvent_GetKeySource()

ArkUI_KeySourceType OH_ArkUI_KeyEvent_GetKeySource(const ArkUI_UIInputEvent* event)

Description

Obtains the type of input device that triggers the specified key event.

Since: 14

Parameters

NameDescription
const ArkUI_UIInputEvent* eventPointer to the target ArkUI_UIInputEvent object.

Return value

TypeDescription
ArkUI_KeySourceTypeInput device type.

OH_ArkUI_KeyEvent_StopPropagation()

void OH_ArkUI_KeyEvent_StopPropagation(const ArkUI_UIInputEvent* event, bool stopPropagation)

Description

Stops the specified key event from bubbling upwards or downwards.

Since: 14

Parameters

NameDescription
const ArkUI_UIInputEvent* eventPointer to the target ArkUI_UIInputEvent object.
bool stopPropagationWhether to stop event propagation. The value true means to stop event propagation, and false means the opposite.

OH_ArkUI_KeyEvent_GetKeyIntensionCode()

ArkUI_KeyIntension OH_ArkUI_KeyEvent_GetKeyIntensionCode(const ArkUI_UIInputEvent* event)

Description

Obtains the intention code associated with the specified key event.

Since: 14

Parameters

NameDescription
const ArkUI_UIInputEvent* eventPointer to the target ArkUI_UIInputEvent object.

Return value

TypeDescription
ArkUI_KeyIntensionIntention code associated with the key event.

OH_ArkUI_KeyEvent_GetUnicode()

uint32_t OH_ArkUI_KeyEvent_GetUnicode(const ArkUI_UIInputEvent* event)

Description

Obtains the Unicode value of the specified key event. Non-space basic Latin characters in the 0x0021-0x007E range are supported. Characters with a value of 0 are not supported. In the case of key combination, this API returns the Unicode value of the key corresponding to the key event.

Since: 14

Parameters

NameDescription
const ArkUI_UIInputEvent* eventPointer to the target ArkUI_UIInputEvent object.

Return value

TypeDescription
uint32_tUnicode value.

OH_ArkUI_KeyEvent_SetConsumed()

void OH_ArkUI_KeyEvent_SetConsumed(const ArkUI_UIInputEvent* event, bool isConsumed)

Description

Sets whether the specified key event is consumed in the key event callback.

Since: 14

Parameters

NameDescription
const ArkUI_UIInputEvent* eventPointer to the target ArkUI_UIInputEvent object.
bool isConsumedWhether the key event is consumed by the callback. The value true means that the key event is consumed, and false the opposite.

OH_ArkUI_KeyEvent_Dispatch()

void OH_ArkUI_KeyEvent_Dispatch(ArkUI_NodeHandle node, const ArkUI_UIInputEvent* event)

Description

Dispatches the specified key event to a specific node.

Since: 15

Parameters

NameDescription
ArkUI_NodeHandle nodeTarget node.
const ArkUI_UIInputEvent* eventPointer to the target ArkUI_UIInputEvent object.

OH_ArkUI_KeyEvent_IsNumLockOn()

ArkUI_ErrorCode OH_ArkUI_KeyEvent_IsNumLockOn(const ArkUI_UIInputEvent* event, bool* state)

Description

Obtains the state of the NumLock key when the specified key event occurs.

Since: 19

Parameters

NameDescription
const ArkUI_UIInputEvent* eventPointer to the target ArkUI_UIInputEvent object.
bool* stateOutput parameter that returns the state of the NumLock key. The value true indicates an activated state, and false indicates an inactivated state.

Return value

TypeDescription
ArkUI_ErrorCodeResult code.
Returns ARKUI_ERROR_CODE_NO_ERROR if the operation is successful.
Returns ARKUI_ERROR_CODE_PARAM_INVALID if a parameter error occurs.

OH_ArkUI_KeyEvent_IsCapsLockOn()

ArkUI_ErrorCode OH_ArkUI_KeyEvent_IsCapsLockOn(const ArkUI_UIInputEvent* event, bool* state)

Description

Obtains the state of the CapsLock key when the specified key event occurs.

Since: 19

Parameters

NameDescription
const ArkUI_UIInputEvent* eventPointer to the target ArkUI_UIInputEvent object.
bool* stateOutput parameter that returns the state of the CapsLock key. The value true indicates an activated state, and false indicates an inactivated state.

Return value

TypeDescription
ArkUI_ErrorCodeResult code.
Returns ARKUI_ERROR_CODE_NO_ERROR if the operation is successful.
Returns ARKUI_ERROR_CODE_PARAM_INVALID if a parameter error occurs.

OH_ArkUI_KeyEvent_IsScrollLockOn()

ArkUI_ErrorCode OH_ArkUI_KeyEvent_IsScrollLockOn(const ArkUI_UIInputEvent* event, bool* state)

Description

Obtains the state of the ScrollLock key when the specified key event occurs.

Since: 19

Parameters

NameDescription
const ArkUI_UIInputEvent* eventPointer to the target ArkUI_UIInputEvent object.
bool* stateOutput parameter that returns the state of the ScrollLock key. The value true indicates an activated state, and false indicates an inactivated state.

Return value

TypeDescription
ArkUI_ErrorCodeResult code.
Returns ARKUI_ERROR_CODE_NO_ERROR if the operation is successful.
Returns ARKUI_ERROR_CODE_PARAM_INVALID if a parameter error occurs.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 arkts-apis-uicontext-contextmenucontroller

openharmony 鸿蒙 errorcode-canvas

openharmony 鸿蒙 capi-oh-nativexcomponent-native-xcomponent-oh-nativexcomponent

openharmony 鸿蒙 errorcode-bindSheet

openharmony 鸿蒙 js-apis-arkui-uiExtension-sys

openharmony 鸿蒙 capi-arkui-accessibility-arkui-accessibilityeventinfo

openharmony 鸿蒙 capi-arkui-rendernodeutils

openharmony 鸿蒙 js-apis-arkui-node

openharmony 鸿蒙 capi-native-node-h

openharmony 鸿蒙 capi-arkui-nativemodule-arkui-listitemswipeactionitem

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