Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

InputEventKey

Inherits: InputEventWithModifiers < InputEventFromWindow < InputEvent < Resource < RefCounted < Object

Represents a key on a keyboard being pressed or released.

描述

An input event for keys on a keyboard. Supports key presses, key releases and echo events. It can also be received in Node._unhandled_key_input.

Note: Events received from the keyboard usually have all properties set. Event mappings should have only one of the keycode, physical_keycode or unicode set.

When events are compared, properties are checked in the following priority - keycode, physical_keycode and unicode. Events with the first matching value will be considered equal.

教程

属性

bool

echo

false

Key

key_label

0

Key

keycode

0

Key

physical_keycode

0

bool

pressed

false

int

unicode

0

Methods

String

as_text_key_label ( ) const

String

as_text_keycode ( ) const

String

as_text_physical_keycode ( ) const

Key

get_key_label_with_modifiers ( ) const

Key

get_keycode_with_modifiers ( ) const

Key

get_physical_keycode_with_modifiers ( ) const


Property Descriptions

bool echo = false

  • void set_echo ( bool value )

  • bool is_echo ( )

If true, the key was already pressed before this event. It means the user is holding the key down.


Key key_label = 0

  • void set_key_label ( Key value )

  • Key get_key_label ( )

Represents the localized label printed on the key in the current keyboard layout, which corresponds to one of the Key constants or any valid Unicode character.

For keyboard layouts with a single label on the key, it is equivalent to keycode.

To get a human-readable representation of the InputEventKey, use OS.get_keycode_string(event.key_label) where event is the InputEventKey.

+-----+ +-----+
| Q   | | Q   | - "Q" - keycode
|   Й | |  ض | - "Й" and "ض" - key_label
+-----+ +-----+

Key keycode = 0

  • void set_keycode ( Key value )

  • Key get_keycode ( )

Latin label printed on the key in the current keyboard layout, which corresponds to one of the Key constants.

To get a human-readable representation of the InputEventKey, use OS.get_keycode_string(event.keycode) where event is the InputEventKey.

+-----+ +-----+
| Q   | | Q   | - "Q" - keycode
|   Й | |  ض | - "Й" and "ض" - key_label
+-----+ +-----+

Key physical_keycode = 0

  • void set_physical_keycode ( Key value )

  • Key get_physical_keycode ( )

Represents the physical location of a key on the 101/102-key US QWERTY keyboard, which corresponds to one of the Key constants.

To get a human-readable representation of the InputEventKey, use OS.get_keycode_string(event.keycode) where event is the InputEventKey.


bool pressed = false

  • void set_pressed ( bool value )

  • bool is_pressed ( )

If true, the key's state is pressed. If false, the key's state is released.


int unicode = 0

  • void set_unicode ( int value )

  • int get_unicode ( )

The key Unicode character code (when relevant), shifted by modifier keys. Unicode character codes for composite characters and complex scripts may not be available unless IME input mode is active. See Window.set_ime_active for more information.


Method Descriptions

String as_text_key_label ( ) const

Returns a String representation of the event's key_label and modifiers.


String as_text_keycode ( ) const

Returns a String representation of the event's keycode and modifiers.


String as_text_physical_keycode ( ) const

Returns a String representation of the event's physical_keycode and modifiers.


Key get_key_label_with_modifiers ( ) const

Returns the localized key label combined with modifier keys such as Shift or Alt. See also InputEventWithModifiers.

To get a human-readable representation of the InputEventKey with modifiers, use OS.get_keycode_string(event.get_key_label_with_modifiers()) where event is the InputEventKey.


Key get_keycode_with_modifiers ( ) const

Returns the Latin keycode combined with modifier keys such as Shift or Alt. See also InputEventWithModifiers.

To get a human-readable representation of the InputEventKey with modifiers, use OS.get_keycode_string(event.get_keycode_with_modifiers()) where event is the InputEventKey.


Key get_physical_keycode_with_modifiers ( ) const

Returns the physical keycode combined with modifier keys such as Shift or Alt. See also InputEventWithModifiers.

To get a human-readable representation of the InputEventKey with modifiers, use OS.get_keycode_string(event.get_physical_keycode_with_modifiers()) where event is the InputEventKey.