class_input.rst 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
  3. .. _class_Input:
  4. Input
  5. =====
  6. **Inherits:** :ref:`Object<class_object>`
  7. **Inherited By:** :ref:`InputDefault<class_inputdefault>`
  8. **Category:** Core
  9. Brief Description
  10. -----------------
  11. A Singleton that deals with inputs.
  12. Member Functions
  13. ----------------
  14. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  15. | void | :ref:`action_press<class_Input_action_press>` **(** :ref:`String<class_string>` action **)** |
  16. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  17. | void | :ref:`action_release<class_Input_action_release>` **(** :ref:`String<class_string>` action **)** |
  18. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  19. | void | :ref:`add_joy_mapping<class_Input_add_joy_mapping>` **(** :ref:`String<class_string>` mapping, :ref:`bool<class_bool>` update_existing=false **)** |
  20. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`Vector3<class_vector3>` | :ref:`get_accelerometer<class_Input_get_accelerometer>` **(** **)** const |
  22. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`Array<class_array>` | :ref:`get_connected_joypads<class_Input_get_connected_joypads>` **(** **)** |
  24. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`Vector3<class_vector3>` | :ref:`get_gravity<class_Input_get_gravity>` **(** **)** const |
  26. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`Vector3<class_vector3>` | :ref:`get_gyroscope<class_Input_get_gyroscope>` **(** **)** const |
  28. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`float<class_float>` | :ref:`get_joy_axis<class_Input_get_joy_axis>` **(** :ref:`int<class_int>` device, :ref:`int<class_int>` axis **)** const |
  30. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`int<class_int>` | :ref:`get_joy_axis_index_from_string<class_Input_get_joy_axis_index_from_string>` **(** :ref:`String<class_string>` axis **)** |
  32. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`String<class_string>` | :ref:`get_joy_axis_string<class_Input_get_joy_axis_string>` **(** :ref:`int<class_int>` axis_index **)** |
  34. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`int<class_int>` | :ref:`get_joy_button_index_from_string<class_Input_get_joy_button_index_from_string>` **(** :ref:`String<class_string>` button **)** |
  36. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`String<class_string>` | :ref:`get_joy_button_string<class_Input_get_joy_button_string>` **(** :ref:`int<class_int>` button_index **)** |
  38. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`String<class_string>` | :ref:`get_joy_guid<class_Input_get_joy_guid>` **(** :ref:`int<class_int>` device **)** const |
  40. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`String<class_string>` | :ref:`get_joy_name<class_Input_get_joy_name>` **(** :ref:`int<class_int>` device **)** |
  42. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`float<class_float>` | :ref:`get_joy_vibration_duration<class_Input_get_joy_vibration_duration>` **(** :ref:`int<class_int>` device **)** |
  44. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Vector2<class_vector2>` | :ref:`get_joy_vibration_strength<class_Input_get_joy_vibration_strength>` **(** :ref:`int<class_int>` device **)** |
  46. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Vector2<class_vector2>` | :ref:`get_last_mouse_speed<class_Input_get_last_mouse_speed>` **(** **)** const |
  48. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Vector3<class_vector3>` | :ref:`get_magnetometer<class_Input_get_magnetometer>` **(** **)** const |
  50. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`int<class_int>` | :ref:`get_mouse_button_mask<class_Input_get_mouse_button_mask>` **(** **)** const |
  52. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`int<class_int>` | :ref:`get_mouse_mode<class_Input_get_mouse_mode>` **(** **)** const |
  54. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`bool<class_bool>` | :ref:`is_action_just_pressed<class_Input_is_action_just_pressed>` **(** :ref:`String<class_string>` action **)** const |
  56. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`bool<class_bool>` | :ref:`is_action_just_released<class_Input_is_action_just_released>` **(** :ref:`String<class_string>` action **)** const |
  58. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`bool<class_bool>` | :ref:`is_action_pressed<class_Input_is_action_pressed>` **(** :ref:`String<class_string>` action **)** const |
  60. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`bool<class_bool>` | :ref:`is_joy_button_pressed<class_Input_is_joy_button_pressed>` **(** :ref:`int<class_int>` device, :ref:`int<class_int>` button **)** const |
  62. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`bool<class_bool>` | :ref:`is_joy_known<class_Input_is_joy_known>` **(** :ref:`int<class_int>` device **)** |
  64. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`bool<class_bool>` | :ref:`is_key_pressed<class_Input_is_key_pressed>` **(** :ref:`int<class_int>` scancode **)** const |
  66. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`bool<class_bool>` | :ref:`is_mouse_button_pressed<class_Input_is_mouse_button_pressed>` **(** :ref:`int<class_int>` button **)** const |
  68. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`parse_input_event<class_Input_parse_input_event>` **(** :ref:`Object<class_object>` event **)** |
  70. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`remove_joy_mapping<class_Input_remove_joy_mapping>` **(** :ref:`String<class_string>` guid **)** |
  72. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`set_custom_mouse_cursor<class_Input_set_custom_mouse_cursor>` **(** :ref:`Texture<class_texture>` image, :ref:`Vector2<class_vector2>` hotspot=Vector2(0, 0) **)** |
  74. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`set_mouse_mode<class_Input_set_mouse_mode>` **(** :ref:`int<class_int>` mode **)** |
  76. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | void | :ref:`start_joy_vibration<class_Input_start_joy_vibration>` **(** :ref:`int<class_int>` device, :ref:`float<class_float>` weak_magnitude, :ref:`float<class_float>` strong_magnitude, :ref:`float<class_float>` duration=0 **)** |
  78. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | void | :ref:`stop_joy_vibration<class_Input_stop_joy_vibration>` **(** :ref:`int<class_int>` device **)** |
  80. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | void | :ref:`warp_mouse_pos<class_Input_warp_mouse_pos>` **(** :ref:`Vector2<class_vector2>` to **)** |
  82. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. Signals
  84. -------
  85. - **joy_connection_changed** **(** :ref:`int<class_int>` index, :ref:`bool<class_bool>` connected **)**
  86. Emitted when a joypad device has been connected or disconnected
  87. Numeric Constants
  88. -----------------
  89. - **MOUSE_MODE_VISIBLE** = **0** --- Makes the mouse cursor visible if it is hidden.
  90. - **MOUSE_MODE_HIDDEN** = **1** --- Makes the mouse cursor hidden if it is visible.
  91. - **MOUSE_MODE_CAPTURED** = **2** --- Captures the mouse. The mouse will be hidden and unable to leave the game window. But it will still register movement and mouse button presses.
  92. - **MOUSE_MODE_CONFINED** = **3**
  93. Description
  94. -----------
  95. A Singleton that deals with inputs. This includes key presses, mouse buttons and movement, joypads, and input actions.
  96. Member Function Description
  97. ---------------------------
  98. .. _class_Input_action_press:
  99. - void **action_press** **(** :ref:`String<class_string>` action **)**
  100. This will simulate pressing the specificed action.
  101. .. _class_Input_action_release:
  102. - void **action_release** **(** :ref:`String<class_string>` action **)**
  103. If the specified action is already pressed, this will release it.
  104. .. _class_Input_add_joy_mapping:
  105. - void **add_joy_mapping** **(** :ref:`String<class_string>` mapping, :ref:`bool<class_bool>` update_existing=false **)**
  106. Add a new mapping entry (in SDL2 format) to the mapping database. Optionally update already connected devices.
  107. .. _class_Input_get_accelerometer:
  108. - :ref:`Vector3<class_vector3>` **get_accelerometer** **(** **)** const
  109. If the device has an accelerometer, this will return the movement.
  110. .. _class_Input_get_connected_joypads:
  111. - :ref:`Array<class_array>` **get_connected_joypads** **(** **)**
  112. Returns an :ref:`Array<class_array>` containing the device IDs of all currently connected joypads.
  113. .. _class_Input_get_gravity:
  114. - :ref:`Vector3<class_vector3>` **get_gravity** **(** **)** const
  115. .. _class_Input_get_gyroscope:
  116. - :ref:`Vector3<class_vector3>` **get_gyroscope** **(** **)** const
  117. If the device has a gyroscope, this will return the rate of rotation in rad/s around a device's x, y, and z axis.
  118. .. _class_Input_get_joy_axis:
  119. - :ref:`float<class_float>` **get_joy_axis** **(** :ref:`int<class_int>` device, :ref:`int<class_int>` axis **)** const
  120. Returns the current value of the joypad axis at given index (see JOY\_\* constants in :ref:`@Global Scope<class_@global scope>`)
  121. .. _class_Input_get_joy_axis_index_from_string:
  122. - :ref:`int<class_int>` **get_joy_axis_index_from_string** **(** :ref:`String<class_string>` axis **)**
  123. .. _class_Input_get_joy_axis_string:
  124. - :ref:`String<class_string>` **get_joy_axis_string** **(** :ref:`int<class_int>` axis_index **)**
  125. .. _class_Input_get_joy_button_index_from_string:
  126. - :ref:`int<class_int>` **get_joy_button_index_from_string** **(** :ref:`String<class_string>` button **)**
  127. .. _class_Input_get_joy_button_string:
  128. - :ref:`String<class_string>` **get_joy_button_string** **(** :ref:`int<class_int>` button_index **)**
  129. .. _class_Input_get_joy_guid:
  130. - :ref:`String<class_string>` **get_joy_guid** **(** :ref:`int<class_int>` device **)** const
  131. Returns a SDL2 compatible device guid on platforms that use gamepad remapping. Returns "Default Gamepad" otherwise.
  132. .. _class_Input_get_joy_name:
  133. - :ref:`String<class_string>` **get_joy_name** **(** :ref:`int<class_int>` device **)**
  134. Returns the name of the joypad at the specified device index
  135. .. _class_Input_get_joy_vibration_duration:
  136. - :ref:`float<class_float>` **get_joy_vibration_duration** **(** :ref:`int<class_int>` device **)**
  137. Returns the duration of the current vibration effect in seconds.
  138. .. _class_Input_get_joy_vibration_strength:
  139. - :ref:`Vector2<class_vector2>` **get_joy_vibration_strength** **(** :ref:`int<class_int>` device **)**
  140. Returns the strength of the joypad vibration: x is the strength of the weak motor, and y is the strength of the strong motor.
  141. .. _class_Input_get_last_mouse_speed:
  142. - :ref:`Vector2<class_vector2>` **get_last_mouse_speed** **(** **)** const
  143. Returns the mouse speed for the last time the cursor was moved, and this until the next frame where the mouse moves. This means that even if the mouse is not moving, this function will still return the value of the last motion.
  144. .. _class_Input_get_magnetometer:
  145. - :ref:`Vector3<class_vector3>` **get_magnetometer** **(** **)** const
  146. If the device has a magnetometer, this will return the magnetic field strength in micro-Tesla for all axes.
  147. .. _class_Input_get_mouse_button_mask:
  148. - :ref:`int<class_int>` **get_mouse_button_mask** **(** **)** const
  149. Returns mouse buttons as a bitmask. If multiple mouse buttons are pressed at the same time the bits are added together.
  150. .. _class_Input_get_mouse_mode:
  151. - :ref:`int<class_int>` **get_mouse_mode** **(** **)** const
  152. Return the mouse mode. See the constants for more information.
  153. .. _class_Input_is_action_just_pressed:
  154. - :ref:`bool<class_bool>` **is_action_just_pressed** **(** :ref:`String<class_string>` action **)** const
  155. .. _class_Input_is_action_just_released:
  156. - :ref:`bool<class_bool>` **is_action_just_released** **(** :ref:`String<class_string>` action **)** const
  157. .. _class_Input_is_action_pressed:
  158. - :ref:`bool<class_bool>` **is_action_pressed** **(** :ref:`String<class_string>` action **)** const
  159. Returns true or false depending on whether the action event is pressed. Actions and their events can be set in the Project Settings / Input Map tab. Or be set with :ref:`InputMap<class_inputmap>`.
  160. .. _class_Input_is_joy_button_pressed:
  161. - :ref:`bool<class_bool>` **is_joy_button_pressed** **(** :ref:`int<class_int>` device, :ref:`int<class_int>` button **)** const
  162. Returns if the joypad button at the given index is currently pressed. (see JOY\_\* constants in :ref:`@Global Scope<class_@global scope>`)
  163. .. _class_Input_is_joy_known:
  164. - :ref:`bool<class_bool>` **is_joy_known** **(** :ref:`int<class_int>` device **)**
  165. Returns if the specified device is known by the system. This means that it sets all button and axis indices exactly as defined in the JOY\_\* constants (see :ref:`@Global Scope<class_@global scope>`). Unknown joypads are not expected to match these constants, but you can still retrieve events from them.
  166. .. _class_Input_is_key_pressed:
  167. - :ref:`bool<class_bool>` **is_key_pressed** **(** :ref:`int<class_int>` scancode **)** const
  168. Returns true or false depending on whether the key is pressed or not. You can pass KEY\_\*, which are pre-defined constants listed in :ref:`@Global Scope<class_@global scope>`.
  169. .. _class_Input_is_mouse_button_pressed:
  170. - :ref:`bool<class_bool>` **is_mouse_button_pressed** **(** :ref:`int<class_int>` button **)** const
  171. Returns true or false depending on whether mouse button is pressed or not. You can pass BUTTON\_\*, which are pre-defined constants listed in :ref:`@Global Scope<class_@global scope>`.
  172. .. _class_Input_parse_input_event:
  173. - void **parse_input_event** **(** :ref:`Object<class_object>` event **)**
  174. .. _class_Input_remove_joy_mapping:
  175. - void **remove_joy_mapping** **(** :ref:`String<class_string>` guid **)**
  176. Removes all mappings from the internal db that match the given uid.
  177. .. _class_Input_set_custom_mouse_cursor:
  178. - void **set_custom_mouse_cursor** **(** :ref:`Texture<class_texture>` image, :ref:`Vector2<class_vector2>` hotspot=Vector2(0, 0) **)**
  179. Set a custom mouse cursor image, which is only visible inside the game window. The hotspot can also be specified.
  180. .. _class_Input_set_mouse_mode:
  181. - void **set_mouse_mode** **(** :ref:`int<class_int>` mode **)**
  182. Set the mouse mode. See the constants for more information.
  183. .. _class_Input_start_joy_vibration:
  184. - void **start_joy_vibration** **(** :ref:`int<class_int>` device, :ref:`float<class_float>` weak_magnitude, :ref:`float<class_float>` strong_magnitude, :ref:`float<class_float>` duration=0 **)**
  185. Starts to vibrate the joypad. Joypads usually come with two rumble motors, a strong and a weak one. weak_magnitude is the strength of the weak motor (between 0 and 1) and strong_magnitude is the strength of the strong motor (between 0 and 1). duration is the duration of the effect in seconds (a duration of 0 will try to play the vibration indefinitely).
  186. Note that not every hardware is compatible with long effect durations, it is recommended to restart an effect if in need to play it for more than a few seconds.
  187. .. _class_Input_stop_joy_vibration:
  188. - void **stop_joy_vibration** **(** :ref:`int<class_int>` device **)**
  189. Stops the vibration of the joypad.
  190. .. _class_Input_warp_mouse_pos:
  191. - void **warp_mouse_pos** **(** :ref:`Vector2<class_vector2>` to **)**
  192. Sets the mouse position to the specified vector.