2
0

class_shortcut.rst 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Shortcut.xml.
  6. .. _class_Shortcut:
  7. Shortcut
  8. ========
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. A shortcut for binding input.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Shortcuts (also known as hotkeys) are containers of :ref:`InputEvent<class_InputEvent>` resources. They are commonly used to interact with a :ref:`Control<class_Control>` element from an :ref:`InputEvent<class_InputEvent>`.
  15. One shortcut can contain multiple :ref:`InputEvent<class_InputEvent>` resources, making it possible to trigger one action with multiple different inputs.
  16. \ **Example:** Capture the :kbd:`Ctrl + S` shortcut using a **Shortcut** resource:
  17. .. tabs::
  18. .. code-tab:: gdscript
  19. extends Node
  20. var save_shortcut = Shortcut.new()
  21. func _ready():
  22. var key_event = InputEventKey.new()
  23. key_event.keycode = KEY_S
  24. key_event.ctrl_pressed = true
  25. key_event.command_or_control_autoremap = true # Swaps Ctrl for Command on Mac.
  26. save_shortcut.events = [key_event]
  27. func _input(event):
  28. if save_shortcut.matches_event(event) and event.is_pressed() and not event.is_echo():
  29. print("Save shortcut pressed!")
  30. get_viewport().set_input_as_handled()
  31. .. code-tab:: csharp
  32. using Godot;
  33. public partial class MyNode : Node
  34. {
  35. private readonly Shortcut _saveShortcut = new Shortcut();
  36. public override void _Ready()
  37. {
  38. InputEventKey keyEvent = new InputEventKey
  39. {
  40. Keycode = Key.S,
  41. CtrlPressed = true,
  42. CommandOrControlAutoremap = true, // Swaps Ctrl for Command on Mac.
  43. };
  44. _saveShortcut.Events = [keyEvent];
  45. }
  46. public override void _Input(InputEvent @event)
  47. {
  48. if (@event is InputEventKey keyEvent &&
  49. _saveShortcut.MatchesEvent(@event) &&
  50. keyEvent.Pressed && !keyEvent.Echo)
  51. {
  52. GD.Print("Save shortcut pressed!");
  53. GetViewport().SetInputAsHandled();
  54. }
  55. }
  56. }
  57. .. rst-class:: classref-reftable-group
  58. Properties
  59. ----------
  60. .. table::
  61. :widths: auto
  62. +---------------------------+-----------------------------------------------+--------+
  63. | :ref:`Array<class_Array>` | :ref:`events<class_Shortcut_property_events>` | ``[]`` |
  64. +---------------------------+-----------------------------------------------+--------+
  65. .. rst-class:: classref-reftable-group
  66. Methods
  67. -------
  68. .. table::
  69. :widths: auto
  70. +-----------------------------+----------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`String<class_String>` | :ref:`get_as_text<class_Shortcut_method_get_as_text>`\ (\ ) |const| |
  72. +-----------------------------+----------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`bool<class_bool>` | :ref:`has_valid_event<class_Shortcut_method_has_valid_event>`\ (\ ) |const| |
  74. +-----------------------------+----------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`bool<class_bool>` | :ref:`matches_event<class_Shortcut_method_matches_event>`\ (\ event\: :ref:`InputEvent<class_InputEvent>`\ ) |const| |
  76. +-----------------------------+----------------------------------------------------------------------------------------------------------------------+
  77. .. rst-class:: classref-section-separator
  78. ----
  79. .. rst-class:: classref-descriptions-group
  80. Property Descriptions
  81. ---------------------
  82. .. _class_Shortcut_property_events:
  83. .. rst-class:: classref-property
  84. :ref:`Array<class_Array>` **events** = ``[]`` :ref:`🔗<class_Shortcut_property_events>`
  85. .. rst-class:: classref-property-setget
  86. - |void| **set_events**\ (\ value\: :ref:`Array<class_Array>`\ )
  87. - :ref:`Array<class_Array>` **get_events**\ (\ )
  88. The shortcut's :ref:`InputEvent<class_InputEvent>` array.
  89. Generally the :ref:`InputEvent<class_InputEvent>` used is an :ref:`InputEventKey<class_InputEventKey>`, though it can be any :ref:`InputEvent<class_InputEvent>`, including an :ref:`InputEventAction<class_InputEventAction>`.
  90. .. rst-class:: classref-section-separator
  91. ----
  92. .. rst-class:: classref-descriptions-group
  93. Method Descriptions
  94. -------------------
  95. .. _class_Shortcut_method_get_as_text:
  96. .. rst-class:: classref-method
  97. :ref:`String<class_String>` **get_as_text**\ (\ ) |const| :ref:`🔗<class_Shortcut_method_get_as_text>`
  98. Returns the shortcut's first valid :ref:`InputEvent<class_InputEvent>` as a :ref:`String<class_String>`.
  99. .. rst-class:: classref-item-separator
  100. ----
  101. .. _class_Shortcut_method_has_valid_event:
  102. .. rst-class:: classref-method
  103. :ref:`bool<class_bool>` **has_valid_event**\ (\ ) |const| :ref:`🔗<class_Shortcut_method_has_valid_event>`
  104. Returns whether :ref:`events<class_Shortcut_property_events>` contains an :ref:`InputEvent<class_InputEvent>` which is valid.
  105. .. rst-class:: classref-item-separator
  106. ----
  107. .. _class_Shortcut_method_matches_event:
  108. .. rst-class:: classref-method
  109. :ref:`bool<class_bool>` **matches_event**\ (\ event\: :ref:`InputEvent<class_InputEvent>`\ ) |const| :ref:`🔗<class_Shortcut_method_matches_event>`
  110. Returns whether any :ref:`InputEvent<class_InputEvent>` in :ref:`events<class_Shortcut_property_events>` equals ``event``. This uses :ref:`InputEvent.is_match()<class_InputEvent_method_is_match>` to compare events.
  111. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  112. .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
  113. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  114. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  115. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  116. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  117. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  118. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  119. .. |void| replace:: :abbr:`void (No return value.)`