class_inputeventkey.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/InputEventKey.xml.
  6. .. _class_InputEventKey:
  7. InputEventKey
  8. =============
  9. **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>`
  10. Represents a key on a keyboard being pressed or released.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. 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>`.
  15. \ **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.
  16. 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.
  17. .. rst-class:: classref-introduction-group
  18. Tutorials
  19. ---------
  20. - :doc:`Using InputEvent <../tutorials/inputs/inputevent>`
  21. .. rst-class:: classref-reftable-group
  22. Properties
  23. ----------
  24. .. table::
  25. :widths: auto
  26. +---------------------------------------------------+------------------------------------------------------------------------+-----------+
  27. | :ref:`bool<class_bool>` | :ref:`echo<class_InputEventKey_property_echo>` | ``false`` |
  28. +---------------------------------------------------+------------------------------------------------------------------------+-----------+
  29. | :ref:`Key<enum_@GlobalScope_Key>` | :ref:`key_label<class_InputEventKey_property_key_label>` | ``0`` |
  30. +---------------------------------------------------+------------------------------------------------------------------------+-----------+
  31. | :ref:`Key<enum_@GlobalScope_Key>` | :ref:`keycode<class_InputEventKey_property_keycode>` | ``0`` |
  32. +---------------------------------------------------+------------------------------------------------------------------------+-----------+
  33. | :ref:`KeyLocation<enum_@GlobalScope_KeyLocation>` | :ref:`location<class_InputEventKey_property_location>` | ``0`` |
  34. +---------------------------------------------------+------------------------------------------------------------------------+-----------+
  35. | :ref:`Key<enum_@GlobalScope_Key>` | :ref:`physical_keycode<class_InputEventKey_property_physical_keycode>` | ``0`` |
  36. +---------------------------------------------------+------------------------------------------------------------------------+-----------+
  37. | :ref:`bool<class_bool>` | :ref:`pressed<class_InputEventKey_property_pressed>` | ``false`` |
  38. +---------------------------------------------------+------------------------------------------------------------------------+-----------+
  39. | :ref:`int<class_int>` | :ref:`unicode<class_InputEventKey_property_unicode>` | ``0`` |
  40. +---------------------------------------------------+------------------------------------------------------------------------+-----------+
  41. .. rst-class:: classref-reftable-group
  42. Methods
  43. -------
  44. .. table::
  45. :widths: auto
  46. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`String<class_String>` | :ref:`as_text_key_label<class_InputEventKey_method_as_text_key_label>`\ (\ ) |const| |
  48. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`String<class_String>` | :ref:`as_text_keycode<class_InputEventKey_method_as_text_keycode>`\ (\ ) |const| |
  50. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`String<class_String>` | :ref:`as_text_location<class_InputEventKey_method_as_text_location>`\ (\ ) |const| |
  52. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`String<class_String>` | :ref:`as_text_physical_keycode<class_InputEventKey_method_as_text_physical_keycode>`\ (\ ) |const| |
  54. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Key<enum_@GlobalScope_Key>` | :ref:`get_key_label_with_modifiers<class_InputEventKey_method_get_key_label_with_modifiers>`\ (\ ) |const| |
  56. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`Key<enum_@GlobalScope_Key>` | :ref:`get_keycode_with_modifiers<class_InputEventKey_method_get_keycode_with_modifiers>`\ (\ ) |const| |
  58. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`Key<enum_@GlobalScope_Key>` | :ref:`get_physical_keycode_with_modifiers<class_InputEventKey_method_get_physical_keycode_with_modifiers>`\ (\ ) |const| |
  60. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  61. .. rst-class:: classref-section-separator
  62. ----
  63. .. rst-class:: classref-descriptions-group
  64. Property Descriptions
  65. ---------------------
  66. .. _class_InputEventKey_property_echo:
  67. .. rst-class:: classref-property
  68. :ref:`bool<class_bool>` **echo** = ``false``
  69. .. rst-class:: classref-property-setget
  70. - |void| **set_echo**\ (\ value\: :ref:`bool<class_bool>`\ )
  71. - :ref:`bool<class_bool>` **is_echo**\ (\ )
  72. If ``true``, the key was already pressed before this event. It means the user is holding the key down.
  73. .. rst-class:: classref-item-separator
  74. ----
  75. .. _class_InputEventKey_property_key_label:
  76. .. rst-class:: classref-property
  77. :ref:`Key<enum_@GlobalScope_Key>` **key_label** = ``0``
  78. .. rst-class:: classref-property-setget
  79. - |void| **set_key_label**\ (\ value\: :ref:`Key<enum_@GlobalScope_Key>`\ )
  80. - :ref:`Key<enum_@GlobalScope_Key>` **get_key_label**\ (\ )
  81. 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.
  82. For keyboard layouts with a single label on the key, it is equivalent to :ref:`keycode<class_InputEventKey_property_keycode>`.
  83. To get a human-readable representation of the **InputEventKey**, use ``OS.get_keycode_string(event.key_label)`` where ``event`` is the **InputEventKey**.
  84. .. code:: text
  85. +-----+ +-----+
  86. | Q | | Q | - "Q" - keycode
  87. | Й | | ض | - "Й" and "ض" - key_label
  88. +-----+ +-----+
  89. .. rst-class:: classref-item-separator
  90. ----
  91. .. _class_InputEventKey_property_keycode:
  92. .. rst-class:: classref-property
  93. :ref:`Key<enum_@GlobalScope_Key>` **keycode** = ``0``
  94. .. rst-class:: classref-property-setget
  95. - |void| **set_keycode**\ (\ value\: :ref:`Key<enum_@GlobalScope_Key>`\ )
  96. - :ref:`Key<enum_@GlobalScope_Key>` **get_keycode**\ (\ )
  97. Latin label printed on the key in the current keyboard layout, which corresponds to one of the :ref:`Key<enum_@GlobalScope_Key>` constants.
  98. To get a human-readable representation of the **InputEventKey**, use ``OS.get_keycode_string(event.keycode)`` where ``event`` is the **InputEventKey**.
  99. .. code:: text
  100. +-----+ +-----+
  101. | Q | | Q | - "Q" - keycode
  102. | Й | | ض | - "Й" and "ض" - key_label
  103. +-----+ +-----+
  104. .. rst-class:: classref-item-separator
  105. ----
  106. .. _class_InputEventKey_property_location:
  107. .. rst-class:: classref-property
  108. :ref:`KeyLocation<enum_@GlobalScope_KeyLocation>` **location** = ``0``
  109. .. rst-class:: classref-property-setget
  110. - |void| **set_location**\ (\ value\: :ref:`KeyLocation<enum_@GlobalScope_KeyLocation>`\ )
  111. - :ref:`KeyLocation<enum_@GlobalScope_KeyLocation>` **get_location**\ (\ )
  112. Represents the location of a key which has both left and right versions, such as :kbd:`Shift` or :kbd:`Alt`.
  113. .. rst-class:: classref-item-separator
  114. ----
  115. .. _class_InputEventKey_property_physical_keycode:
  116. .. rst-class:: classref-property
  117. :ref:`Key<enum_@GlobalScope_Key>` **physical_keycode** = ``0``
  118. .. rst-class:: classref-property-setget
  119. - |void| **set_physical_keycode**\ (\ value\: :ref:`Key<enum_@GlobalScope_Key>`\ )
  120. - :ref:`Key<enum_@GlobalScope_Key>` **get_physical_keycode**\ (\ )
  121. 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.
  122. 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>`:
  123. .. tabs::
  124. .. code-tab:: gdscript
  125. func _input(event):
  126. if event is InputEventKey:
  127. var keycode = DisplayServer.keyboard_get_keycode_from_physical(event.physical_keycode)
  128. print(OS.get_keycode_string(keycode))
  129. .. code-tab:: csharp
  130. public override void _Input(InputEvent @event)
  131. {
  132. if (@event is InputEventKey inputEventKey)
  133. {
  134. var keycode = DisplayServer.KeyboardGetKeycodeFromPhysical(inputEventKey.PhysicalKeycode);
  135. GD.Print(OS.GetKeycodeString(keycode));
  136. }
  137. }
  138. .. rst-class:: classref-item-separator
  139. ----
  140. .. _class_InputEventKey_property_pressed:
  141. .. rst-class:: classref-property
  142. :ref:`bool<class_bool>` **pressed** = ``false``
  143. .. rst-class:: classref-property-setget
  144. - |void| **set_pressed**\ (\ value\: :ref:`bool<class_bool>`\ )
  145. - :ref:`bool<class_bool>` **is_pressed**\ (\ )
  146. If ``true``, the key's state is pressed. If ``false``, the key's state is released.
  147. .. rst-class:: classref-item-separator
  148. ----
  149. .. _class_InputEventKey_property_unicode:
  150. .. rst-class:: classref-property
  151. :ref:`int<class_int>` **unicode** = ``0``
  152. .. rst-class:: classref-property-setget
  153. - |void| **set_unicode**\ (\ value\: :ref:`int<class_int>`\ )
  154. - :ref:`int<class_int>` **get_unicode**\ (\ )
  155. 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.
  156. .. rst-class:: classref-section-separator
  157. ----
  158. .. rst-class:: classref-descriptions-group
  159. Method Descriptions
  160. -------------------
  161. .. _class_InputEventKey_method_as_text_key_label:
  162. .. rst-class:: classref-method
  163. :ref:`String<class_String>` **as_text_key_label**\ (\ ) |const|
  164. Returns a :ref:`String<class_String>` representation of the event's :ref:`key_label<class_InputEventKey_property_key_label>` and modifiers.
  165. .. rst-class:: classref-item-separator
  166. ----
  167. .. _class_InputEventKey_method_as_text_keycode:
  168. .. rst-class:: classref-method
  169. :ref:`String<class_String>` **as_text_keycode**\ (\ ) |const|
  170. Returns a :ref:`String<class_String>` representation of the event's :ref:`keycode<class_InputEventKey_property_keycode>` and modifiers.
  171. .. rst-class:: classref-item-separator
  172. ----
  173. .. _class_InputEventKey_method_as_text_location:
  174. .. rst-class:: classref-method
  175. :ref:`String<class_String>` **as_text_location**\ (\ ) |const|
  176. 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.
  177. .. rst-class:: classref-item-separator
  178. ----
  179. .. _class_InputEventKey_method_as_text_physical_keycode:
  180. .. rst-class:: classref-method
  181. :ref:`String<class_String>` **as_text_physical_keycode**\ (\ ) |const|
  182. Returns a :ref:`String<class_String>` representation of the event's :ref:`physical_keycode<class_InputEventKey_property_physical_keycode>` and modifiers.
  183. .. rst-class:: classref-item-separator
  184. ----
  185. .. _class_InputEventKey_method_get_key_label_with_modifiers:
  186. .. rst-class:: classref-method
  187. :ref:`Key<enum_@GlobalScope_Key>` **get_key_label_with_modifiers**\ (\ ) |const|
  188. Returns the localized key label combined with modifier keys such as :kbd:`Shift` or :kbd:`Alt`. See also :ref:`InputEventWithModifiers<class_InputEventWithModifiers>`.
  189. 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**.
  190. .. rst-class:: classref-item-separator
  191. ----
  192. .. _class_InputEventKey_method_get_keycode_with_modifiers:
  193. .. rst-class:: classref-method
  194. :ref:`Key<enum_@GlobalScope_Key>` **get_keycode_with_modifiers**\ (\ ) |const|
  195. Returns the Latin keycode combined with modifier keys such as :kbd:`Shift` or :kbd:`Alt`. See also :ref:`InputEventWithModifiers<class_InputEventWithModifiers>`.
  196. 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**.
  197. .. rst-class:: classref-item-separator
  198. ----
  199. .. _class_InputEventKey_method_get_physical_keycode_with_modifiers:
  200. .. rst-class:: classref-method
  201. :ref:`Key<enum_@GlobalScope_Key>` **get_physical_keycode_with_modifiers**\ (\ ) |const|
  202. Returns the physical keycode combined with modifier keys such as :kbd:`Shift` or :kbd:`Alt`. See also :ref:`InputEventWithModifiers<class_InputEventWithModifiers>`.
  203. 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**.
  204. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  205. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  206. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  207. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  208. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  209. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  210. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  211. .. |void| replace:: :abbr:`void (No return value.)`