class_inputevent.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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/InputEvent.xml.
  6. .. _class_InputEvent:
  7. InputEvent
  8. ==========
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`InputEventAction<class_InputEventAction>`, :ref:`InputEventFromWindow<class_InputEventFromWindow>`, :ref:`InputEventJoypadButton<class_InputEventJoypadButton>`, :ref:`InputEventJoypadMotion<class_InputEventJoypadMotion>`, :ref:`InputEventMIDI<class_InputEventMIDI>`, :ref:`InputEventShortcut<class_InputEventShortcut>`
  11. Abstract base class for input events.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. Abstract base class of all types of input events. See :ref:`Node._input<class_Node_private_method__input>`.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - :doc:`Using InputEvent <../tutorials/inputs/inputevent>`
  20. - :doc:`Viewport and canvas transforms <../tutorials/2d/2d_transforms>`
  21. - `2D Dodge The Creeps Demo <https://godotengine.org/asset-library/asset/515>`__
  22. - `3D Voxel Demo <https://godotengine.org/asset-library/asset/676>`__
  23. .. rst-class:: classref-reftable-group
  24. Properties
  25. ----------
  26. .. table::
  27. :widths: auto
  28. +-----------------------+-------------------------------------------------+-------+
  29. | :ref:`int<class_int>` | :ref:`device<class_InputEvent_property_device>` | ``0`` |
  30. +-----------------------+-------------------------------------------------+-------+
  31. .. rst-class:: classref-reftable-group
  32. Methods
  33. -------
  34. .. table::
  35. :widths: auto
  36. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`bool<class_bool>` | :ref:`accumulate<class_InputEvent_method_accumulate>` **(** :ref:`InputEvent<class_InputEvent>` with_event **)** |
  38. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`String<class_String>` | :ref:`as_text<class_InputEvent_method_as_text>` **(** **)** |const| |
  40. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`float<class_float>` | :ref:`get_action_strength<class_InputEvent_method_get_action_strength>` **(** :ref:`StringName<class_StringName>` action, :ref:`bool<class_bool>` exact_match=false **)** |const| |
  42. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`is_action<class_InputEvent_method_is_action>` **(** :ref:`StringName<class_StringName>` action, :ref:`bool<class_bool>` exact_match=false **)** |const| |
  44. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`bool<class_bool>` | :ref:`is_action_pressed<class_InputEvent_method_is_action_pressed>` **(** :ref:`StringName<class_StringName>` action, :ref:`bool<class_bool>` allow_echo=false, :ref:`bool<class_bool>` exact_match=false **)** |const| |
  46. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`is_action_released<class_InputEvent_method_is_action_released>` **(** :ref:`StringName<class_StringName>` action, :ref:`bool<class_bool>` exact_match=false **)** |const| |
  48. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`bool<class_bool>` | :ref:`is_action_type<class_InputEvent_method_is_action_type>` **(** **)** |const| |
  50. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`bool<class_bool>` | :ref:`is_canceled<class_InputEvent_method_is_canceled>` **(** **)** |const| |
  52. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`bool<class_bool>` | :ref:`is_echo<class_InputEvent_method_is_echo>` **(** **)** |const| |
  54. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`bool<class_bool>` | :ref:`is_match<class_InputEvent_method_is_match>` **(** :ref:`InputEvent<class_InputEvent>` event, :ref:`bool<class_bool>` exact_match=true **)** |const| |
  56. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`bool<class_bool>` | :ref:`is_pressed<class_InputEvent_method_is_pressed>` **(** **)** |const| |
  58. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`bool<class_bool>` | :ref:`is_released<class_InputEvent_method_is_released>` **(** **)** |const| |
  60. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`InputEvent<class_InputEvent>` | :ref:`xformed_by<class_InputEvent_method_xformed_by>` **(** :ref:`Transform2D<class_Transform2D>` xform, :ref:`Vector2<class_Vector2>` local_ofs=Vector2(0, 0) **)** |const| |
  62. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. .. rst-class:: classref-section-separator
  64. ----
  65. .. rst-class:: classref-descriptions-group
  66. Property Descriptions
  67. ---------------------
  68. .. _class_InputEvent_property_device:
  69. .. rst-class:: classref-property
  70. :ref:`int<class_int>` **device** = ``0``
  71. .. rst-class:: classref-property-setget
  72. - void **set_device** **(** :ref:`int<class_int>` value **)**
  73. - :ref:`int<class_int>` **get_device** **(** **)**
  74. The event's device ID.
  75. \ **Note:** This device ID will always be ``-1`` for emulated mouse input from a touchscreen. This can be used to distinguish emulated mouse input from physical mouse input.
  76. .. rst-class:: classref-section-separator
  77. ----
  78. .. rst-class:: classref-descriptions-group
  79. Method Descriptions
  80. -------------------
  81. .. _class_InputEvent_method_accumulate:
  82. .. rst-class:: classref-method
  83. :ref:`bool<class_bool>` **accumulate** **(** :ref:`InputEvent<class_InputEvent>` with_event **)**
  84. Returns ``true`` if the given input event and this input event can be added together (only for events of type :ref:`InputEventMouseMotion<class_InputEventMouseMotion>`).
  85. The given input event's position, global position and speed will be copied. The resulting ``relative`` is a sum of both events. Both events' modifiers have to be identical.
  86. .. rst-class:: classref-item-separator
  87. ----
  88. .. _class_InputEvent_method_as_text:
  89. .. rst-class:: classref-method
  90. :ref:`String<class_String>` **as_text** **(** **)** |const|
  91. Returns a :ref:`String<class_String>` representation of the event.
  92. .. rst-class:: classref-item-separator
  93. ----
  94. .. _class_InputEvent_method_get_action_strength:
  95. .. rst-class:: classref-method
  96. :ref:`float<class_float>` **get_action_strength** **(** :ref:`StringName<class_StringName>` action, :ref:`bool<class_bool>` exact_match=false **)** |const|
  97. Returns a value between 0.0 and 1.0 depending on the given actions' state. Useful for getting the value of events of type :ref:`InputEventJoypadMotion<class_InputEventJoypadMotion>`.
  98. If ``exact_match`` is ``false``, it ignores additional input modifiers for :ref:`InputEventKey<class_InputEventKey>` and :ref:`InputEventMouseButton<class_InputEventMouseButton>` events, and the direction for :ref:`InputEventJoypadMotion<class_InputEventJoypadMotion>` events.
  99. .. rst-class:: classref-item-separator
  100. ----
  101. .. _class_InputEvent_method_is_action:
  102. .. rst-class:: classref-method
  103. :ref:`bool<class_bool>` **is_action** **(** :ref:`StringName<class_StringName>` action, :ref:`bool<class_bool>` exact_match=false **)** |const|
  104. Returns ``true`` if this input event matches a pre-defined action of any type.
  105. If ``exact_match`` is ``false``, it ignores additional input modifiers for :ref:`InputEventKey<class_InputEventKey>` and :ref:`InputEventMouseButton<class_InputEventMouseButton>` events, and the direction for :ref:`InputEventJoypadMotion<class_InputEventJoypadMotion>` events.
  106. .. rst-class:: classref-item-separator
  107. ----
  108. .. _class_InputEvent_method_is_action_pressed:
  109. .. rst-class:: classref-method
  110. :ref:`bool<class_bool>` **is_action_pressed** **(** :ref:`StringName<class_StringName>` action, :ref:`bool<class_bool>` allow_echo=false, :ref:`bool<class_bool>` exact_match=false **)** |const|
  111. Returns ``true`` if the given action is being pressed (and is not an echo event for :ref:`InputEventKey<class_InputEventKey>` events, unless ``allow_echo`` is ``true``). Not relevant for events of type :ref:`InputEventMouseMotion<class_InputEventMouseMotion>` or :ref:`InputEventScreenDrag<class_InputEventScreenDrag>`.
  112. If ``exact_match`` is ``false``, it ignores additional input modifiers for :ref:`InputEventKey<class_InputEventKey>` and :ref:`InputEventMouseButton<class_InputEventMouseButton>` events, and the direction for :ref:`InputEventJoypadMotion<class_InputEventJoypadMotion>` events.
  113. \ **Note:** Due to keyboard ghosting, :ref:`is_action_pressed<class_InputEvent_method_is_action_pressed>` may return ``false`` even if one of the action's keys is pressed. See `Input examples <../tutorials/inputs/input_examples.html#keyboard-events>`__ in the documentation for more information.
  114. .. rst-class:: classref-item-separator
  115. ----
  116. .. _class_InputEvent_method_is_action_released:
  117. .. rst-class:: classref-method
  118. :ref:`bool<class_bool>` **is_action_released** **(** :ref:`StringName<class_StringName>` action, :ref:`bool<class_bool>` exact_match=false **)** |const|
  119. Returns ``true`` if the given action is released (i.e. not pressed). Not relevant for events of type :ref:`InputEventMouseMotion<class_InputEventMouseMotion>` or :ref:`InputEventScreenDrag<class_InputEventScreenDrag>`.
  120. If ``exact_match`` is ``false``, it ignores additional input modifiers for :ref:`InputEventKey<class_InputEventKey>` and :ref:`InputEventMouseButton<class_InputEventMouseButton>` events, and the direction for :ref:`InputEventJoypadMotion<class_InputEventJoypadMotion>` events.
  121. .. rst-class:: classref-item-separator
  122. ----
  123. .. _class_InputEvent_method_is_action_type:
  124. .. rst-class:: classref-method
  125. :ref:`bool<class_bool>` **is_action_type** **(** **)** |const|
  126. Returns ``true`` if this input event's type is one that can be assigned to an input action.
  127. .. rst-class:: classref-item-separator
  128. ----
  129. .. _class_InputEvent_method_is_canceled:
  130. .. rst-class:: classref-method
  131. :ref:`bool<class_bool>` **is_canceled** **(** **)** |const|
  132. Returns ``true`` if this input event has been canceled.
  133. .. rst-class:: classref-item-separator
  134. ----
  135. .. _class_InputEvent_method_is_echo:
  136. .. rst-class:: classref-method
  137. :ref:`bool<class_bool>` **is_echo** **(** **)** |const|
  138. Returns ``true`` if this input event is an echo event (only for events of type :ref:`InputEventKey<class_InputEventKey>`). Any other event type returns ``false``.
  139. .. rst-class:: classref-item-separator
  140. ----
  141. .. _class_InputEvent_method_is_match:
  142. .. rst-class:: classref-method
  143. :ref:`bool<class_bool>` **is_match** **(** :ref:`InputEvent<class_InputEvent>` event, :ref:`bool<class_bool>` exact_match=true **)** |const|
  144. Returns ``true`` if the specified ``event`` matches this event. Only valid for action events i.e key (:ref:`InputEventKey<class_InputEventKey>`), button (:ref:`InputEventMouseButton<class_InputEventMouseButton>` or :ref:`InputEventJoypadButton<class_InputEventJoypadButton>`), axis :ref:`InputEventJoypadMotion<class_InputEventJoypadMotion>` or action (:ref:`InputEventAction<class_InputEventAction>`) events.
  145. If ``exact_match`` is ``false``, it ignores additional input modifiers for :ref:`InputEventKey<class_InputEventKey>` and :ref:`InputEventMouseButton<class_InputEventMouseButton>` events, and the direction for :ref:`InputEventJoypadMotion<class_InputEventJoypadMotion>` events.
  146. .. rst-class:: classref-item-separator
  147. ----
  148. .. _class_InputEvent_method_is_pressed:
  149. .. rst-class:: classref-method
  150. :ref:`bool<class_bool>` **is_pressed** **(** **)** |const|
  151. Returns ``true`` if this input event is pressed. Not relevant for events of type :ref:`InputEventMouseMotion<class_InputEventMouseMotion>` or :ref:`InputEventScreenDrag<class_InputEventScreenDrag>`.
  152. \ **Note:** Due to keyboard ghosting, :ref:`is_pressed<class_InputEvent_method_is_pressed>` may return ``false`` even if one of the action's keys is pressed. See `Input examples <../tutorials/inputs/input_examples.html#keyboard-events>`__ in the documentation for more information.
  153. .. rst-class:: classref-item-separator
  154. ----
  155. .. _class_InputEvent_method_is_released:
  156. .. rst-class:: classref-method
  157. :ref:`bool<class_bool>` **is_released** **(** **)** |const|
  158. Returns ``true`` if this input event is released. Not relevant for events of type :ref:`InputEventMouseMotion<class_InputEventMouseMotion>` or :ref:`InputEventScreenDrag<class_InputEventScreenDrag>`.
  159. .. rst-class:: classref-item-separator
  160. ----
  161. .. _class_InputEvent_method_xformed_by:
  162. .. rst-class:: classref-method
  163. :ref:`InputEvent<class_InputEvent>` **xformed_by** **(** :ref:`Transform2D<class_Transform2D>` xform, :ref:`Vector2<class_Vector2>` local_ofs=Vector2(0, 0) **)** |const|
  164. Returns a copy of the given input event which has been offset by ``local_ofs`` and transformed by ``xform``. Relevant for events of type :ref:`InputEventMouseButton<class_InputEventMouseButton>`, :ref:`InputEventMouseMotion<class_InputEventMouseMotion>`, :ref:`InputEventScreenTouch<class_InputEventScreenTouch>`, :ref:`InputEventScreenDrag<class_InputEventScreenDrag>`, :ref:`InputEventMagnifyGesture<class_InputEventMagnifyGesture>` and :ref:`InputEventPanGesture<class_InputEventPanGesture>`.
  165. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  166. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  167. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  168. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  169. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  170. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  171. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`