123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- :github_url: hide
- .. DO NOT EDIT THIS FILE!!!
- .. Generated automatically from Godot engine sources.
- .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
- .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/InputEventKey.xml.
- .. _class_InputEventKey:
- InputEventKey
- =============
- **Inherits:** :ref:`InputEventWithModifiers<class_InputEventWithModifiers>` **<** :ref:`InputEventFromWindow<class_InputEventFromWindow>` **<** :ref:`InputEvent<class_InputEvent>` **<** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
- Represents a key on a keyboard being pressed or released.
- .. rst-class:: classref-introduction-group
- Description
- -----------
- An input event for keys on a keyboard. Supports key presses, key releases and :ref:`echo<class_InputEventKey_property_echo>` events. It can also be received in :ref:`Node._unhandled_key_input<class_Node_private_method__unhandled_key_input>`.
- \ **Note:** Events received from the keyboard usually have all properties set. Event mappings should have only one of the :ref:`keycode<class_InputEventKey_property_keycode>`, :ref:`physical_keycode<class_InputEventKey_property_physical_keycode>` or :ref:`unicode<class_InputEventKey_property_unicode>` set.
- When events are compared, properties are checked in the following priority - :ref:`keycode<class_InputEventKey_property_keycode>`, :ref:`physical_keycode<class_InputEventKey_property_physical_keycode>` and :ref:`unicode<class_InputEventKey_property_unicode>`. Events with the first matching value will be considered equal.
- .. rst-class:: classref-introduction-group
- Tutorials
- ---------
- - :doc:`Using InputEvent <../tutorials/inputs/inputevent>`
- .. rst-class:: classref-reftable-group
- Properties
- ----------
- .. table::
- :widths: auto
- +---------------------------------------------------+------------------------------------------------------------------------+-----------+
- | :ref:`bool<class_bool>` | :ref:`echo<class_InputEventKey_property_echo>` | ``false`` |
- +---------------------------------------------------+------------------------------------------------------------------------+-----------+
- | :ref:`Key<enum_@GlobalScope_Key>` | :ref:`key_label<class_InputEventKey_property_key_label>` | ``0`` |
- +---------------------------------------------------+------------------------------------------------------------------------+-----------+
- | :ref:`Key<enum_@GlobalScope_Key>` | :ref:`keycode<class_InputEventKey_property_keycode>` | ``0`` |
- +---------------------------------------------------+------------------------------------------------------------------------+-----------+
- | :ref:`KeyLocation<enum_@GlobalScope_KeyLocation>` | :ref:`location<class_InputEventKey_property_location>` | ``0`` |
- +---------------------------------------------------+------------------------------------------------------------------------+-----------+
- | :ref:`Key<enum_@GlobalScope_Key>` | :ref:`physical_keycode<class_InputEventKey_property_physical_keycode>` | ``0`` |
- +---------------------------------------------------+------------------------------------------------------------------------+-----------+
- | :ref:`bool<class_bool>` | :ref:`pressed<class_InputEventKey_property_pressed>` | ``false`` |
- +---------------------------------------------------+------------------------------------------------------------------------+-----------+
- | :ref:`int<class_int>` | :ref:`unicode<class_InputEventKey_property_unicode>` | ``0`` |
- +---------------------------------------------------+------------------------------------------------------------------------+-----------+
- .. rst-class:: classref-reftable-group
- Methods
- -------
- .. table::
- :widths: auto
- +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
- | :ref:`String<class_String>` | :ref:`as_text_key_label<class_InputEventKey_method_as_text_key_label>`\ (\ ) |const| |
- +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
- | :ref:`String<class_String>` | :ref:`as_text_keycode<class_InputEventKey_method_as_text_keycode>`\ (\ ) |const| |
- +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
- | :ref:`String<class_String>` | :ref:`as_text_location<class_InputEventKey_method_as_text_location>`\ (\ ) |const| |
- +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
- | :ref:`String<class_String>` | :ref:`as_text_physical_keycode<class_InputEventKey_method_as_text_physical_keycode>`\ (\ ) |const| |
- +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Key<enum_@GlobalScope_Key>` | :ref:`get_key_label_with_modifiers<class_InputEventKey_method_get_key_label_with_modifiers>`\ (\ ) |const| |
- +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Key<enum_@GlobalScope_Key>` | :ref:`get_keycode_with_modifiers<class_InputEventKey_method_get_keycode_with_modifiers>`\ (\ ) |const| |
- +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Key<enum_@GlobalScope_Key>` | :ref:`get_physical_keycode_with_modifiers<class_InputEventKey_method_get_physical_keycode_with_modifiers>`\ (\ ) |const| |
- +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Property Descriptions
- ---------------------
- .. _class_InputEventKey_property_echo:
- .. rst-class:: classref-property
- :ref:`bool<class_bool>` **echo** = ``false`` :ref:`🔗<class_InputEventKey_property_echo>`
- .. rst-class:: classref-property-setget
- - |void| **set_echo**\ (\ value\: :ref:`bool<class_bool>`\ )
- - :ref:`bool<class_bool>` **is_echo**\ (\ )
- If ``true``, the key was already pressed before this event. An echo event is a repeated key event sent when the user is holding down the key.
- \ **Note:** The rate at which echo events are sent is typically around 20 events per second (after holding down the key for roughly half a second). However, the key repeat delay/speed can be changed by the user or disabled entirely in the operating system settings. To ensure your project works correctly on all configurations, do not assume the user has a specific key repeat configuration in your project's behavior.
- .. rst-class:: classref-item-separator
- ----
- .. _class_InputEventKey_property_key_label:
- .. rst-class:: classref-property
- :ref:`Key<enum_@GlobalScope_Key>` **key_label** = ``0`` :ref:`🔗<class_InputEventKey_property_key_label>`
- .. rst-class:: classref-property-setget
- - |void| **set_key_label**\ (\ value\: :ref:`Key<enum_@GlobalScope_Key>`\ )
- - :ref:`Key<enum_@GlobalScope_Key>` **get_key_label**\ (\ )
- Represents the localized label printed on the key in the current keyboard layout, which corresponds to one of the :ref:`Key<enum_@GlobalScope_Key>` constants or any valid Unicode character.
- For keyboard layouts with a single label on the key, it is equivalent to :ref:`keycode<class_InputEventKey_property_keycode>`.
- To get a human-readable representation of the **InputEventKey**, use ``OS.get_keycode_string(event.key_label)`` where ``event`` is the **InputEventKey**.
- .. code:: text
- +-----+ +-----+
- | Q | | Q | - "Q" - keycode
- | Й | | ض | - "Й" and "ض" - key_label
- +-----+ +-----+
- .. rst-class:: classref-item-separator
- ----
- .. _class_InputEventKey_property_keycode:
- .. rst-class:: classref-property
- :ref:`Key<enum_@GlobalScope_Key>` **keycode** = ``0`` :ref:`🔗<class_InputEventKey_property_keycode>`
- .. rst-class:: classref-property-setget
- - |void| **set_keycode**\ (\ value\: :ref:`Key<enum_@GlobalScope_Key>`\ )
- - :ref:`Key<enum_@GlobalScope_Key>` **get_keycode**\ (\ )
- Latin label printed on the key in the current keyboard layout, which corresponds to one of the :ref:`Key<enum_@GlobalScope_Key>` constants.
- To get a human-readable representation of the **InputEventKey**, use ``OS.get_keycode_string(event.keycode)`` where ``event`` is the **InputEventKey**.
- .. code:: text
- +-----+ +-----+
- | Q | | Q | - "Q" - keycode
- | Й | | ض | - "Й" and "ض" - key_label
- +-----+ +-----+
- .. rst-class:: classref-item-separator
- ----
- .. _class_InputEventKey_property_location:
- .. rst-class:: classref-property
- :ref:`KeyLocation<enum_@GlobalScope_KeyLocation>` **location** = ``0`` :ref:`🔗<class_InputEventKey_property_location>`
- .. rst-class:: classref-property-setget
- - |void| **set_location**\ (\ value\: :ref:`KeyLocation<enum_@GlobalScope_KeyLocation>`\ )
- - :ref:`KeyLocation<enum_@GlobalScope_KeyLocation>` **get_location**\ (\ )
- Represents the location of a key which has both left and right versions, such as :kbd:`Shift` or :kbd:`Alt`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_InputEventKey_property_physical_keycode:
- .. rst-class:: classref-property
- :ref:`Key<enum_@GlobalScope_Key>` **physical_keycode** = ``0`` :ref:`🔗<class_InputEventKey_property_physical_keycode>`
- .. rst-class:: classref-property-setget
- - |void| **set_physical_keycode**\ (\ value\: :ref:`Key<enum_@GlobalScope_Key>`\ )
- - :ref:`Key<enum_@GlobalScope_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 :ref:`Key<enum_@GlobalScope_Key>` constants.
- To get a human-readable representation of the **InputEventKey**, use :ref:`OS.get_keycode_string<class_OS_method_get_keycode_string>` in combination with :ref:`DisplayServer.keyboard_get_keycode_from_physical<class_DisplayServer_method_keyboard_get_keycode_from_physical>`:
- .. tabs::
- .. code-tab:: gdscript
- func _input(event):
- if event is InputEventKey:
- var keycode = DisplayServer.keyboard_get_keycode_from_physical(event.physical_keycode)
- print(OS.get_keycode_string(keycode))
- .. code-tab:: csharp
- public override void _Input(InputEvent @event)
- {
- if (@event is InputEventKey inputEventKey)
- {
- var keycode = DisplayServer.KeyboardGetKeycodeFromPhysical(inputEventKey.PhysicalKeycode);
- GD.Print(OS.GetKeycodeString(keycode));
- }
- }
- .. rst-class:: classref-item-separator
- ----
- .. _class_InputEventKey_property_pressed:
- .. rst-class:: classref-property
- :ref:`bool<class_bool>` **pressed** = ``false`` :ref:`🔗<class_InputEventKey_property_pressed>`
- .. rst-class:: classref-property-setget
- - |void| **set_pressed**\ (\ value\: :ref:`bool<class_bool>`\ )
- - :ref:`bool<class_bool>` **is_pressed**\ (\ )
- If ``true``, the key's state is pressed. If ``false``, the key's state is released.
- .. rst-class:: classref-item-separator
- ----
- .. _class_InputEventKey_property_unicode:
- .. rst-class:: classref-property
- :ref:`int<class_int>` **unicode** = ``0`` :ref:`🔗<class_InputEventKey_property_unicode>`
- .. rst-class:: classref-property-setget
- - |void| **set_unicode**\ (\ value\: :ref:`int<class_int>`\ )
- - :ref:`int<class_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 :ref:`Window.set_ime_active<class_Window_method_set_ime_active>` for more information.
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Method Descriptions
- -------------------
- .. _class_InputEventKey_method_as_text_key_label:
- .. rst-class:: classref-method
- :ref:`String<class_String>` **as_text_key_label**\ (\ ) |const| :ref:`🔗<class_InputEventKey_method_as_text_key_label>`
- Returns a :ref:`String<class_String>` representation of the event's :ref:`key_label<class_InputEventKey_property_key_label>` and modifiers.
- .. rst-class:: classref-item-separator
- ----
- .. _class_InputEventKey_method_as_text_keycode:
- .. rst-class:: classref-method
- :ref:`String<class_String>` **as_text_keycode**\ (\ ) |const| :ref:`🔗<class_InputEventKey_method_as_text_keycode>`
- Returns a :ref:`String<class_String>` representation of the event's :ref:`keycode<class_InputEventKey_property_keycode>` and modifiers.
- .. rst-class:: classref-item-separator
- ----
- .. _class_InputEventKey_method_as_text_location:
- .. rst-class:: classref-method
- :ref:`String<class_String>` **as_text_location**\ (\ ) |const| :ref:`🔗<class_InputEventKey_method_as_text_location>`
- Returns a :ref:`String<class_String>` representation of the event's :ref:`location<class_InputEventKey_property_location>`. This will be a blank string if the event is not specific to a location.
- .. rst-class:: classref-item-separator
- ----
- .. _class_InputEventKey_method_as_text_physical_keycode:
- .. rst-class:: classref-method
- :ref:`String<class_String>` **as_text_physical_keycode**\ (\ ) |const| :ref:`🔗<class_InputEventKey_method_as_text_physical_keycode>`
- Returns a :ref:`String<class_String>` representation of the event's :ref:`physical_keycode<class_InputEventKey_property_physical_keycode>` and modifiers.
- .. rst-class:: classref-item-separator
- ----
- .. _class_InputEventKey_method_get_key_label_with_modifiers:
- .. rst-class:: classref-method
- :ref:`Key<enum_@GlobalScope_Key>` **get_key_label_with_modifiers**\ (\ ) |const| :ref:`🔗<class_InputEventKey_method_get_key_label_with_modifiers>`
- Returns the localized key label combined with modifier keys such as :kbd:`Shift` or :kbd:`Alt`. See also :ref:`InputEventWithModifiers<class_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**.
- .. rst-class:: classref-item-separator
- ----
- .. _class_InputEventKey_method_get_keycode_with_modifiers:
- .. rst-class:: classref-method
- :ref:`Key<enum_@GlobalScope_Key>` **get_keycode_with_modifiers**\ (\ ) |const| :ref:`🔗<class_InputEventKey_method_get_keycode_with_modifiers>`
- Returns the Latin keycode combined with modifier keys such as :kbd:`Shift` or :kbd:`Alt`. See also :ref:`InputEventWithModifiers<class_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**.
- .. rst-class:: classref-item-separator
- ----
- .. _class_InputEventKey_method_get_physical_keycode_with_modifiers:
- .. rst-class:: classref-method
- :ref:`Key<enum_@GlobalScope_Key>` **get_physical_keycode_with_modifiers**\ (\ ) |const| :ref:`🔗<class_InputEventKey_method_get_physical_keycode_with_modifiers>`
- Returns the physical keycode combined with modifier keys such as :kbd:`Shift` or :kbd:`Alt`. See also :ref:`InputEventWithModifiers<class_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**.
- .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
- .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
- .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
- .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
- .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
- .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
- .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
- .. |void| replace:: :abbr:`void (No return value.)`
|