mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2025-12-31 09:49:22 +03:00
179 lines
7.8 KiB
ReStructuredText
179 lines
7.8 KiB
ReStructuredText
:github_url: hide
|
||
|
||
.. _class_Shortcut:
|
||
|
||
Shortcut
|
||
========
|
||
|
||
**Наследует:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
|
||
|
||
Сочетание клавиш для привязки ввода.
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
Описание
|
||
----------------
|
||
|
||
Сочетания клавиш (также известные как горячие клавиши) — это контейнеры ресурсов :ref:`InputEvent<class_InputEvent>`. Они обычно используются для взаимодействия с элементом :ref:`Control<class_Control>` из :ref:`InputEvent<class_InputEvent>`.
|
||
|
||
Один ярлык может содержать несколько ресурсов :ref:`InputEvent<class_InputEvent>`, что позволяет запускать одно действие с несколькими различными входами.
|
||
|
||
\ **Пример:** Захватите сочетание клавиш :kbd:`Ctrl + S` с помощью ресурса **Shortcut**:
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
extends Node
|
||
|
||
var save_shortcut = Shortcut.new()
|
||
func _ready():
|
||
var key_event = InputEventKey.new()
|
||
key_event.keycode = KEY_S
|
||
key_event.ctrl_pressed = true
|
||
key_event.command_or_control_autoremap = true # Заменяет Ctrl на Command на Mac.
|
||
save_shortcut.events = [key_event]
|
||
|
||
func _input(event):
|
||
if save_shortcut.matches_event(event) and event.is_pressed() and not event.is_echo():
|
||
print("Save shortcut pressed!")
|
||
get_viewport().set_input_as_handled()
|
||
|
||
.. code-tab:: csharp
|
||
|
||
using Godot;
|
||
|
||
public partial class MyNode : Node
|
||
{
|
||
private readonly Shortcut _saveShortcut = new Shortcut();
|
||
|
||
public override void _Ready()
|
||
{
|
||
InputEventKey keyEvent = new InputEventKey
|
||
{
|
||
Keycode = Key.S,
|
||
CtrlPressed = true,
|
||
CommandOrControlAutoremap = true, // Заменяет Ctrl на Command на Mac.
|
||
};
|
||
|
||
_saveShortcut.Events = [keyEvent];
|
||
}
|
||
|
||
public override void _Input(InputEvent @event)
|
||
{
|
||
if (@event is InputEventKey keyEvent &&
|
||
_saveShortcut.MatchesEvent(@event) &&
|
||
keyEvent.Pressed && !keyEvent.Echo)
|
||
{
|
||
GD.Print("Save shortcut pressed!");
|
||
GetViewport().SetInputAsHandled();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
Свойства
|
||
----------------
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+---------------------------+-----------------------------------------------+--------+
|
||
| :ref:`Array<class_Array>` | :ref:`events<class_Shortcut_property_events>` | ``[]`` |
|
||
+---------------------------+-----------------------------------------------+--------+
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
Методы
|
||
------------
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+-----------------------------+----------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`get_as_text<class_Shortcut_method_get_as_text>`\ (\ ) |const| |
|
||
+-----------------------------+----------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`has_valid_event<class_Shortcut_method_has_valid_event>`\ (\ ) |const| |
|
||
+-----------------------------+----------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`matches_event<class_Shortcut_method_matches_event>`\ (\ event\: :ref:`InputEvent<class_InputEvent>`\ ) |const| |
|
||
+-----------------------------+----------------------------------------------------------------------------------------------------------------------+
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
Описания свойств
|
||
--------------------------------
|
||
|
||
.. _class_Shortcut_property_events:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`Array<class_Array>` **events** = ``[]`` :ref:`🔗<class_Shortcut_property_events>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- |void| **set_events**\ (\ value\: :ref:`Array<class_Array>`\ )
|
||
- :ref:`Array<class_Array>` **get_events**\ (\ )
|
||
|
||
Массив :ref:`InputEvent<class_InputEvent>` ярлыка.
|
||
|
||
Обычно используемый :ref:`InputEvent<class_InputEvent>` — это :ref:`InputEventKey<class_InputEventKey>`, хотя это может быть любой :ref:`InputEvent<class_InputEvent>`, включая :ref:`InputEventAction<class_InputEventAction>`.
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
Описания метода
|
||
------------------------------
|
||
|
||
.. _class_Shortcut_method_get_as_text:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **get_as_text**\ (\ ) |const| :ref:`🔗<class_Shortcut_method_get_as_text>`
|
||
|
||
Возвращает первое допустимое :ref:`InputEvent<class_InputEvent>` сочетания клавиш в виде :ref:`String<class_String>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Shortcut_method_has_valid_event:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **has_valid_event**\ (\ ) |const| :ref:`🔗<class_Shortcut_method_has_valid_event>`
|
||
|
||
Возвращает, содержит ли :ref:`events<class_Shortcut_property_events>` допустимое :ref:`InputEvent<class_InputEvent>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Shortcut_method_matches_event:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **matches_event**\ (\ event\: :ref:`InputEvent<class_InputEvent>`\ ) |const| :ref:`🔗<class_Shortcut_method_matches_event>`
|
||
|
||
Возвращает, равен ли :ref:`InputEvent<class_InputEvent>` в :ref:`events<class_Shortcut_property_events>` этому ``event``. Для сравнения событий используется :ref:`InputEvent.is_match()<class_InputEvent_method_is_match>`.
|
||
|
||
.. |virtual| replace:: :abbr:`virtual (Этот метод обычно должен быть переопределен пользователем, чтобы иметь какой-либо эффект.)`
|
||
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
|
||
.. |const| replace:: :abbr:`const (Этот метод не имеет побочных эффектов. Он не изменяет ни одну из переменных-членов экземпляра.)`
|
||
.. |vararg| replace:: :abbr:`vararg (Этот метод принимает любое количество аргументов после описанных здесь.)`
|
||
.. |constructor| replace:: :abbr:`constructor (Этот метод используется для создания типа.)`
|
||
.. |static| replace:: :abbr:`static (Этот метод не нуждается в вызове экземпляра, поэтому его можно вызвать напрямую, используя имя класса.)`
|
||
.. |operator| replace:: :abbr:`operator (Этот метод описывает допустимый оператор для использования с этим типом в качестве левого операнда.)`
|
||
.. |bitfield| replace:: :abbr:`BitField (Это значение является целым числом, составленным как битовая маска следующих флагов.)`
|
||
.. |void| replace:: :abbr:`void (Нет возвращаемого значения.)`
|