class_input.rst 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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:`int<class_int>` shape=0, :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. .. _class_Input_joy_connection_changed:
  89. - **joy_connection_changed** **(** :ref:`int<class_int>` index, :ref:`bool<class_bool>` connected **)**
  90. Emitted when a joypad device has been connected or disconnected
  91. Enums
  92. -----
  93. .. _enum_Input_MouseMode:
  94. enum **MouseMode**
  95. - **MOUSE_MODE_VISIBLE** = **0** --- Makes the mouse cursor visible if it is hidden.
  96. - **MOUSE_MODE_HIDDEN** = **1** --- Makes the mouse cursor hidden if it is visible.
  97. - **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.
  98. - **MOUSE_MODE_CONFINED** = **3**
  99. .. _enum_Input_CursorShape:
  100. enum **CursorShape**
  101. - **CURSOR_ARROW** = **0**
  102. - **CURSOR_IBEAM** = **1**
  103. - **CURSOR_POINTING_HAND** = **2**
  104. - **CURSOR_CROSS** = **3**
  105. - **CURSOR_WAIT** = **4**
  106. - **CURSOR_BUSY** = **5**
  107. - **CURSOR_DRAG** = **6**
  108. - **CURSOR_CAN_DROP** = **7**
  109. - **CURSOR_FORBIDDEN** = **8**
  110. - **CURSOR_VSIZE** = **9**
  111. - **CURSOR_HSIZE** = **10**
  112. - **CURSOR_BDIAGSIZE** = **11**
  113. - **CURSOR_FDIAGSIZE** = **12**
  114. - **CURSOR_MOVE** = **13**
  115. - **CURSOR_VSPLIT** = **14**
  116. - **CURSOR_HSPLIT** = **15**
  117. - **CURSOR_HELP** = **16**
  118. Description
  119. -----------
  120. A Singleton that deals with inputs. This includes key presses, mouse buttons and movement, joypads, and input actions. Actions and their events can be set in the Project Settings / Input Map tab. Or be set with :ref:`InputMap<class_inputmap>`.
  121. Member Function Description
  122. ---------------------------
  123. .. _class_Input_action_press:
  124. - void **action_press** **(** :ref:`String<class_string>` action **)**
  125. This will simulate pressing the specificed action.
  126. .. _class_Input_action_release:
  127. - void **action_release** **(** :ref:`String<class_string>` action **)**
  128. If the specified action is already pressed, this will release it.
  129. .. _class_Input_add_joy_mapping:
  130. - void **add_joy_mapping** **(** :ref:`String<class_string>` mapping, :ref:`bool<class_bool>` update_existing=false **)**
  131. Add a new mapping entry (in SDL2 format) to the mapping database. Optionally update already connected devices.
  132. .. _class_Input_get_accelerometer:
  133. - :ref:`Vector3<class_vector3>` **get_accelerometer** **(** **)** const
  134. If the device has an accelerometer, this will return the movement.
  135. .. _class_Input_get_connected_joypads:
  136. - :ref:`Array<class_array>` **get_connected_joypads** **(** **)**
  137. Returns an :ref:`Array<class_array>` containing the device IDs of all currently connected joypads.
  138. .. _class_Input_get_gravity:
  139. - :ref:`Vector3<class_vector3>` **get_gravity** **(** **)** const
  140. .. _class_Input_get_gyroscope:
  141. - :ref:`Vector3<class_vector3>` **get_gyroscope** **(** **)** const
  142. 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.
  143. .. _class_Input_get_joy_axis:
  144. - :ref:`float<class_float>` **get_joy_axis** **(** :ref:`int<class_int>` device, :ref:`int<class_int>` axis **)** const
  145. Returns the current value of the joypad axis at given index (see ``JOY\_\*`` constants in :ref:`@GlobalScope<class_@globalscope>`)
  146. .. _class_Input_get_joy_axis_index_from_string:
  147. - :ref:`int<class_int>` **get_joy_axis_index_from_string** **(** :ref:`String<class_string>` axis **)**
  148. .. _class_Input_get_joy_axis_string:
  149. - :ref:`String<class_string>` **get_joy_axis_string** **(** :ref:`int<class_int>` axis_index **)**
  150. .. _class_Input_get_joy_button_index_from_string:
  151. - :ref:`int<class_int>` **get_joy_button_index_from_string** **(** :ref:`String<class_string>` button **)**
  152. .. _class_Input_get_joy_button_string:
  153. - :ref:`String<class_string>` **get_joy_button_string** **(** :ref:`int<class_int>` button_index **)**
  154. .. _class_Input_get_joy_guid:
  155. - :ref:`String<class_string>` **get_joy_guid** **(** :ref:`int<class_int>` device **)** const
  156. Returns a SDL2 compatible device guid on platforms that use gamepad remapping. Returns "Default Gamepad" otherwise.
  157. .. _class_Input_get_joy_name:
  158. - :ref:`String<class_string>` **get_joy_name** **(** :ref:`int<class_int>` device **)**
  159. Returns the name of the joypad at the specified device index
  160. .. _class_Input_get_joy_vibration_duration:
  161. - :ref:`float<class_float>` **get_joy_vibration_duration** **(** :ref:`int<class_int>` device **)**
  162. Returns the duration of the current vibration effect in seconds.
  163. .. _class_Input_get_joy_vibration_strength:
  164. - :ref:`Vector2<class_vector2>` **get_joy_vibration_strength** **(** :ref:`int<class_int>` device **)**
  165. Returns the strength of the joypad vibration: x is the strength of the weak motor, and y is the strength of the strong motor.
  166. .. _class_Input_get_last_mouse_speed:
  167. - :ref:`Vector2<class_vector2>` **get_last_mouse_speed** **(** **)** const
  168. 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.
  169. .. _class_Input_get_magnetometer:
  170. - :ref:`Vector3<class_vector3>` **get_magnetometer** **(** **)** const
  171. If the device has a magnetometer, this will return the magnetic field strength in micro-Tesla for all axes.
  172. .. _class_Input_get_mouse_button_mask:
  173. - :ref:`int<class_int>` **get_mouse_button_mask** **(** **)** const
  174. Returns mouse buttons as a bitmask. If multiple mouse buttons are pressed at the same time the bits are added together.
  175. .. _class_Input_get_mouse_mode:
  176. - :ref:`int<class_int>` **get_mouse_mode** **(** **)** const
  177. Return the mouse mode. See the constants for more information.
  178. .. _class_Input_is_action_just_pressed:
  179. - :ref:`bool<class_bool>` **is_action_just_pressed** **(** :ref:`String<class_string>` action **)** const
  180. Returns ``true`` when you start pressing the action event.
  181. .. _class_Input_is_action_just_released:
  182. - :ref:`bool<class_bool>` **is_action_just_released** **(** :ref:`String<class_string>` action **)** const
  183. Returns ``true`` when you stop pressing the action event.
  184. .. _class_Input_is_action_pressed:
  185. - :ref:`bool<class_bool>` **is_action_pressed** **(** :ref:`String<class_string>` action **)** const
  186. Returns ``true`` if you are pressing the action event.
  187. .. _class_Input_is_joy_button_pressed:
  188. - :ref:`bool<class_bool>` **is_joy_button_pressed** **(** :ref:`int<class_int>` device, :ref:`int<class_int>` button **)** const
  189. Returns ``true`` if you are pressing the joypad button. (see ``JOY\_\*`` constants in :ref:`@GlobalScope<class_@globalscope>`)
  190. .. _class_Input_is_joy_known:
  191. - :ref:`bool<class_bool>` **is_joy_known** **(** :ref:`int<class_int>` device **)**
  192. Returns ``true`` if the system knows the specified device. This means that it sets all button and axis indices exactly as defined in the ``JOY\_\*`` constants (see :ref:`@GlobalScope<class_@globalscope>`). Unknown joypads are not expected to match these constants, but you can still retrieve events from them.
  193. .. _class_Input_is_key_pressed:
  194. - :ref:`bool<class_bool>` **is_key_pressed** **(** :ref:`int<class_int>` scancode **)** const
  195. Returns ``true`` if you are pressing the key. You can pass ``KEY\_\*``, which are pre-defined constants listed in :ref:`@GlobalScope<class_@globalscope>`.
  196. .. _class_Input_is_mouse_button_pressed:
  197. - :ref:`bool<class_bool>` **is_mouse_button_pressed** **(** :ref:`int<class_int>` button **)** const
  198. Returns ``true`` if you are pressing the mouse button. You can pass ``BUTTON\_\*``, which are pre-defined constants listed in :ref:`@GlobalScope<class_@globalscope>`.
  199. .. _class_Input_joy_connection_changed:
  200. - void **joy_connection_changed** **(** :ref:`int<class_int>` device, :ref:`bool<class_bool>` connected, :ref:`String<class_string>` name, :ref:`String<class_string>` guid **)**
  201. .. _class_Input_parse_input_event:
  202. - void **parse_input_event** **(** :ref:`InputEvent<class_inputevent>` event **)**
  203. .. _class_Input_remove_joy_mapping:
  204. - void **remove_joy_mapping** **(** :ref:`String<class_string>` guid **)**
  205. Removes all mappings from the internal db that match the given uid.
  206. .. _class_Input_set_custom_mouse_cursor:
  207. - void **set_custom_mouse_cursor** **(** :ref:`Resource<class_resource>` image, :ref:`int<class_int>` shape=0, :ref:`Vector2<class_vector2>` hotspot=Vector2( 0, 0 ) **)**
  208. Set a custom mouse cursor image, which is only visible inside the game window. The hotspot can also be specified. See enum ``CURSOR\_\*`` for the list of shapes.
  209. .. _class_Input_set_mouse_mode:
  210. - void **set_mouse_mode** **(** :ref:`int<class_int>` mode **)**
  211. Set the mouse mode. See the constants for more information.
  212. .. _class_Input_start_joy_vibration:
  213. - 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 **)**
  214. 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).
  215. 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.
  216. .. _class_Input_stop_joy_vibration:
  217. - void **stop_joy_vibration** **(** :ref:`int<class_int>` device **)**
  218. Stops the vibration of the joypad.
  219. .. _class_Input_warp_mouse_position:
  220. - void **warp_mouse_position** **(** :ref:`Vector2<class_vector2>` to **)**
  221. Sets the mouse position to the specified vector.