class_input.rst 27 KB

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