class_input.rst 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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>` **(** **)** |
  22. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`Array<class_array>` | :ref:`get_connected_joysticks<class_Input_get_connected_joysticks>` **(** **)** |
  24. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`Vector3<class_vector3>` | :ref:`get_gravity<class_Input_get_gravity>` **(** **)** |
  26. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`Vector3<class_vector3>` | :ref:`get_gyroscope<class_Input_get_gyroscope>` **(** **)** |
  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 **)** |
  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:`Vector3<class_vector3>` | :ref:`get_magnetometer<class_Input_get_magnetometer>` **(** **)** |
  48. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`int<class_int>` | :ref:`get_mouse_button_mask<class_Input_get_mouse_button_mask>` **(** **)** const |
  50. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`int<class_int>` | :ref:`get_mouse_mode<class_Input_get_mouse_mode>` **(** **)** const |
  52. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`Vector2<class_vector2>` | :ref:`get_mouse_speed<class_Input_get_mouse_speed>` **(** **)** const |
  54. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`bool<class_bool>` | :ref:`is_action_pressed<class_Input_is_action_pressed>` **(** :ref:`String<class_string>` action **)** |
  56. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :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 **)** |
  58. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`bool<class_bool>` | :ref:`is_joy_known<class_Input_is_joy_known>` **(** :ref:`int<class_int>` device **)** |
  60. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`bool<class_bool>` | :ref:`is_key_pressed<class_Input_is_key_pressed>` **(** :ref:`int<class_int>` scancode **)** |
  62. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`bool<class_bool>` | :ref:`is_mouse_button_pressed<class_Input_is_mouse_button_pressed>` **(** :ref:`int<class_int>` button **)** |
  64. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`parse_input_event<class_Input_parse_input_event>` **(** :ref:`InputEvent<class_inputevent>` event **)** |
  66. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`remove_joy_mapping<class_Input_remove_joy_mapping>` **(** :ref:`String<class_string>` guid **)** |
  68. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | 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) **)** |
  70. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`set_mouse_mode<class_Input_set_mouse_mode>` **(** :ref:`int<class_int>` mode **)** |
  72. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | 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 **)** |
  74. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`stop_joy_vibration<class_Input_stop_joy_vibration>` **(** :ref:`int<class_int>` device **)** |
  76. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | void | :ref:`warp_mouse_pos<class_Input_warp_mouse_pos>` **(** :ref:`Vector2<class_vector2>` to **)** |
  78. +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. Signals
  80. -------
  81. - **joy_connection_changed** **(** :ref:`int<class_int>` index, :ref:`bool<class_bool>` connected **)**
  82. Emitted when a joystick device has been connected or disconnected
  83. Numeric Constants
  84. -----------------
  85. - **MOUSE_MODE_VISIBLE** = **0** --- Makes the mouse cursor visible if it is hidden.
  86. - **MOUSE_MODE_HIDDEN** = **1** --- Makes the mouse cursor hidden if it is visible.
  87. - **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.
  88. Description
  89. -----------
  90. A Singleton that deals with inputs. This includes key presses, mouse buttons and movement, joysticks, and input actions.
  91. Member Function Description
  92. ---------------------------
  93. .. _class_Input_action_press:
  94. - void **action_press** **(** :ref:`String<class_string>` action **)**
  95. This will simulate pressing the specificed action.
  96. .. _class_Input_action_release:
  97. - void **action_release** **(** :ref:`String<class_string>` action **)**
  98. If the specified action is already pressed, this will release it.
  99. .. _class_Input_add_joy_mapping:
  100. - void **add_joy_mapping** **(** :ref:`String<class_string>` mapping, :ref:`bool<class_bool>` update_existing=false **)**
  101. Add a new mapping entry (in SDL2 format) to the mapping database. Optionally update already connected devices.
  102. .. _class_Input_get_accelerometer:
  103. - :ref:`Vector3<class_vector3>` **get_accelerometer** **(** **)**
  104. If the device has an accelerometer, this will return the movement.
  105. .. _class_Input_get_connected_joysticks:
  106. - :ref:`Array<class_array>` **get_connected_joysticks** **(** **)**
  107. Returns an :ref:`Array<class_array>` containing the device IDs of all currently connected joysticks.
  108. .. _class_Input_get_gravity:
  109. - :ref:`Vector3<class_vector3>` **get_gravity** **(** **)**
  110. .. _class_Input_get_gyroscope:
  111. - :ref:`Vector3<class_vector3>` **get_gyroscope** **(** **)**
  112. 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.
  113. .. _class_Input_get_joy_axis:
  114. - :ref:`float<class_float>` **get_joy_axis** **(** :ref:`int<class_int>` device, :ref:`int<class_int>` axis **)**
  115. Returns the current value of the joystick axis at given index (see JOY\_\* constants in :ref:`@Global Scope<class_@global scope>`)
  116. .. _class_Input_get_joy_axis_index_from_string:
  117. - :ref:`int<class_int>` **get_joy_axis_index_from_string** **(** :ref:`String<class_string>` axis **)**
  118. .. _class_Input_get_joy_axis_string:
  119. - :ref:`String<class_string>` **get_joy_axis_string** **(** :ref:`int<class_int>` axis_index **)**
  120. .. _class_Input_get_joy_button_index_from_string:
  121. - :ref:`int<class_int>` **get_joy_button_index_from_string** **(** :ref:`String<class_string>` button **)**
  122. .. _class_Input_get_joy_button_string:
  123. - :ref:`String<class_string>` **get_joy_button_string** **(** :ref:`int<class_int>` button_index **)**
  124. .. _class_Input_get_joy_guid:
  125. - :ref:`String<class_string>` **get_joy_guid** **(** :ref:`int<class_int>` device **)** const
  126. Returns a SDL2 compatible device guid on platforms that use gamepad remapping. Returns "Default Gamepad" otherwise.
  127. .. _class_Input_get_joy_name:
  128. - :ref:`String<class_string>` **get_joy_name** **(** :ref:`int<class_int>` device **)**
  129. Returns the name of the joystick at the specified device index
  130. .. _class_Input_get_joy_vibration_duration:
  131. - :ref:`float<class_float>` **get_joy_vibration_duration** **(** :ref:`int<class_int>` device **)**
  132. Returns the duration of the current vibration effect in seconds.
  133. .. _class_Input_get_joy_vibration_strength:
  134. - :ref:`Vector2<class_vector2>` **get_joy_vibration_strength** **(** :ref:`int<class_int>` device **)**
  135. Returns the strength of the joystick vibration: x is the strength of the weak motor, and y is the strength of the strong motor.
  136. .. _class_Input_get_magnetometer:
  137. - :ref:`Vector3<class_vector3>` **get_magnetometer** **(** **)**
  138. If the device has a magnetometer, this will return the magnetic field strength in micro-Tesla for all axes.
  139. .. _class_Input_get_mouse_button_mask:
  140. - :ref:`int<class_int>` **get_mouse_button_mask** **(** **)** const
  141. Returns mouse buttons as a bitmask. If multiple mouse buttons are pressed at the same time the bits are added together.
  142. .. _class_Input_get_mouse_mode:
  143. - :ref:`int<class_int>` **get_mouse_mode** **(** **)** const
  144. Return the mouse mode. See the constants for more information.
  145. .. _class_Input_get_mouse_speed:
  146. - :ref:`Vector2<class_vector2>` **get_mouse_speed** **(** **)** const
  147. 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.
  148. .. _class_Input_is_action_pressed:
  149. - :ref:`bool<class_bool>` **is_action_pressed** **(** :ref:`String<class_string>` action **)**
  150. 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>`.
  151. .. _class_Input_is_joy_button_pressed:
  152. - :ref:`bool<class_bool>` **is_joy_button_pressed** **(** :ref:`int<class_int>` device, :ref:`int<class_int>` button **)**
  153. Returns if the joystick button at the given index is currently pressed. (see JOY\_\* constants in :ref:`@Global Scope<class_@global scope>`)
  154. .. _class_Input_is_joy_known:
  155. - :ref:`bool<class_bool>` **is_joy_known** **(** :ref:`int<class_int>` device **)**
  156. 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 joysticks are not expected to match these constants, but you can still retrieve events from them.
  157. .. _class_Input_is_key_pressed:
  158. - :ref:`bool<class_bool>` **is_key_pressed** **(** :ref:`int<class_int>` scancode **)**
  159. 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>`.
  160. .. _class_Input_is_mouse_button_pressed:
  161. - :ref:`bool<class_bool>` **is_mouse_button_pressed** **(** :ref:`int<class_int>` button **)**
  162. 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>`.
  163. .. _class_Input_parse_input_event:
  164. - void **parse_input_event** **(** :ref:`InputEvent<class_inputevent>` event **)**
  165. .. _class_Input_remove_joy_mapping:
  166. - void **remove_joy_mapping** **(** :ref:`String<class_string>` guid **)**
  167. Removes all mappings from the internal db that match the given uid.
  168. .. _class_Input_set_custom_mouse_cursor:
  169. - void **set_custom_mouse_cursor** **(** :ref:`Texture<class_texture>` image, :ref:`Vector2<class_vector2>` hotspot=Vector2(0, 0) **)**
  170. Set a custom mouse cursor image, which is only visible inside the game window. The hotspot can also be specified.
  171. .. _class_Input_set_mouse_mode:
  172. - void **set_mouse_mode** **(** :ref:`int<class_int>` mode **)**
  173. Set the mouse mode. See the constants for more information.
  174. .. _class_Input_start_joy_vibration:
  175. - 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 **)**
  176. Starts to vibrate the joystick. Joysticks 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).
  177. 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.
  178. .. _class_Input_stop_joy_vibration:
  179. - void **stop_joy_vibration** **(** :ref:`int<class_int>` device **)**
  180. Stops the vibration of the joystick.
  181. .. _class_Input_warp_mouse_pos:
  182. - void **warp_mouse_pos** **(** :ref:`Vector2<class_vector2>` to **)**
  183. Sets the mouse position to the specified vector.