class_input.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. | :ref:`bool<class_bool>` | :ref:`is_key_pressed<class_Input_is_key_pressed>` **(** :ref:`int<class_int>` scancode **)** |
  16. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  17. | :ref:`bool<class_bool>` | :ref:`is_mouse_button_pressed<class_Input_is_mouse_button_pressed>` **(** :ref:`int<class_int>` button **)** |
  18. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  19. | :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 **)** |
  20. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`bool<class_bool>` | :ref:`is_action_pressed<class_Input_is_action_pressed>` **(** :ref:`String<class_string>` action **)** |
  22. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | void | :ref:`add_joy_mapping<class_Input_add_joy_mapping>` **(** :ref:`String<class_string>` mapping, :ref:`bool<class_bool>` update_existing=false **)** |
  24. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | void | :ref:`remove_joy_mapping<class_Input_remove_joy_mapping>` **(** :ref:`String<class_string>` guid **)** |
  26. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`bool<class_bool>` | :ref:`is_joy_known<class_Input_is_joy_known>` **(** :ref:`int<class_int>` device **)** |
  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:`String<class_string>` | :ref:`get_joy_name<class_Input_get_joy_name>` **(** :ref:`int<class_int>` device **)** |
  32. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`String<class_string>` | :ref:`get_joy_guid<class_Input_get_joy_guid>` **(** :ref:`int<class_int>` device **)** const |
  34. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Vector3<class_vector3>` | :ref:`get_accelerometer<class_Input_get_accelerometer>` **(** **)** |
  36. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Vector2<class_vector2>` | :ref:`get_mouse_speed<class_Input_get_mouse_speed>` **(** **)** const |
  38. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`int<class_int>` | :ref:`get_mouse_button_mask<class_Input_get_mouse_button_mask>` **(** **)** const |
  40. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | void | :ref:`set_mouse_mode<class_Input_set_mouse_mode>` **(** :ref:`int<class_int>` mode **)** |
  42. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`int<class_int>` | :ref:`get_mouse_mode<class_Input_get_mouse_mode>` **(** **)** const |
  44. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`warp_mouse_pos<class_Input_warp_mouse_pos>` **(** :ref:`Vector2<class_vector2>` to **)** |
  46. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`action_press<class_Input_action_press>` **(** :ref:`String<class_string>` action **)** |
  48. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`action_release<class_Input_action_release>` **(** :ref:`String<class_string>` action **)** |
  50. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | 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) **)** |
  52. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. Signals
  54. -------
  55. - **joy_connection_changed** **(** :ref:`int<class_int>` index, :ref:`bool<class_bool>` connected **)**
  56. Numeric Constants
  57. -----------------
  58. - **MOUSE_MODE_VISIBLE** = **0** --- Makes the mouse cursor visible if it is hidden.
  59. - **MOUSE_MODE_HIDDEN** = **1** --- Makes the mouse cursor hidden if it is visible.
  60. - **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.
  61. Description
  62. -----------
  63. A Singleton that deals with inputs. This includes key presses, mouse buttons and movement, joysticks, and input actions.
  64. Member Function Description
  65. ---------------------------
  66. .. _class_Input_is_key_pressed:
  67. - :ref:`bool<class_bool>` **is_key_pressed** **(** :ref:`int<class_int>` scancode **)**
  68. 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>`.
  69. .. _class_Input_is_mouse_button_pressed:
  70. - :ref:`bool<class_bool>` **is_mouse_button_pressed** **(** :ref:`int<class_int>` button **)**
  71. 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>`.
  72. .. _class_Input_is_joy_button_pressed:
  73. - :ref:`bool<class_bool>` **is_joy_button_pressed** **(** :ref:`int<class_int>` device, :ref:`int<class_int>` button **)**
  74. Returns if the joystick button at the given index is currently pressed. (see JOY\_\* constants in :ref:`@Global Scope<class_@global scope>`)
  75. .. _class_Input_is_action_pressed:
  76. - :ref:`bool<class_bool>` **is_action_pressed** **(** :ref:`String<class_string>` action **)**
  77. 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>`.
  78. .. _class_Input_add_joy_mapping:
  79. - void **add_joy_mapping** **(** :ref:`String<class_string>` mapping, :ref:`bool<class_bool>` update_existing=false **)**
  80. Add a new mapping entry (in SDL2 format) to the mapping database. Optionally update already connected devices.
  81. .. _class_Input_remove_joy_mapping:
  82. - void **remove_joy_mapping** **(** :ref:`String<class_string>` guid **)**
  83. Removes all mappings from the internal db that match the given uid.
  84. .. _class_Input_is_joy_known:
  85. - :ref:`bool<class_bool>` **is_joy_known** **(** :ref:`int<class_int>` device **)**
  86. 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.
  87. .. _class_Input_get_joy_axis:
  88. - :ref:`float<class_float>` **get_joy_axis** **(** :ref:`int<class_int>` device, :ref:`int<class_int>` axis **)**
  89. Returns the current value of the joystick axis at given index (see JOY\_\* constants in :ref:`@Global Scope<class_@global scope>`)
  90. .. _class_Input_get_joy_name:
  91. - :ref:`String<class_string>` **get_joy_name** **(** :ref:`int<class_int>` device **)**
  92. Returns the name of the joystick at the specified device index
  93. .. _class_Input_get_joy_guid:
  94. - :ref:`String<class_string>` **get_joy_guid** **(** :ref:`int<class_int>` device **)** const
  95. Returns a SDL2 compatible device guid on platforms that use gamepad remapping. Returns "Default Gamepad" otherwise.
  96. .. _class_Input_get_accelerometer:
  97. - :ref:`Vector3<class_vector3>` **get_accelerometer** **(** **)**
  98. If the device has an accelerometer, this will return the movement.
  99. .. _class_Input_get_mouse_speed:
  100. - :ref:`Vector2<class_vector2>` **get_mouse_speed** **(** **)** const
  101. Returns the mouse speed.
  102. .. _class_Input_get_mouse_button_mask:
  103. - :ref:`int<class_int>` **get_mouse_button_mask** **(** **)** const
  104. Returns mouse buttons as a bitmask. If multiple mouse buttons are pressed at the same time the bits are added together.
  105. .. _class_Input_set_mouse_mode:
  106. - void **set_mouse_mode** **(** :ref:`int<class_int>` mode **)**
  107. Set the mouse mode. See the constants for more information.
  108. .. _class_Input_get_mouse_mode:
  109. - :ref:`int<class_int>` **get_mouse_mode** **(** **)** const
  110. Return the mouse mode. See the constants for more information.
  111. .. _class_Input_warp_mouse_pos:
  112. - void **warp_mouse_pos** **(** :ref:`Vector2<class_vector2>` to **)**
  113. Sets the mouse position to the specified vector.
  114. .. _class_Input_action_press:
  115. - void **action_press** **(** :ref:`String<class_string>` action **)**
  116. This will simulate pressing the specificed action.
  117. .. _class_Input_action_release:
  118. - void **action_release** **(** :ref:`String<class_string>` action **)**
  119. If the specified action is already pressed, this will release it.
  120. .. _class_Input_set_custom_mouse_cursor:
  121. - void **set_custom_mouse_cursor** **(** :ref:`Texture<class_texture>` image, :ref:`Vector2<class_vector2>` hotspot=Vector2(0,0) **)**
  122. Set a custom mouse cursor image, which is only visible inside the game window. The hotspot can also be specified.