Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
Shortcut
Eredita: Resource < RefCounted < Object
Una scorciatoia per associare input.
Descrizione
Le scorciatoie (note anche come tasti di scelta rapida) sono contenitori di risorse InputEvent. Sono comunemente utilizzate per interagire con un elemento Control da un InputEvent.
Una scorciatoia può contenere più risorse InputEvent, rendendo possibile attivare un'azione con più input diversi.
Esempio: Cattura la scorciatoia Ctrl + S attraverso una risorsa Shortcut:
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 # Sostituisce Ctrl per Command su 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("Scorciatoia Salva attivata!")
get_viewport().set_input_as_handled()
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, // Sostituisce Ctrl per Command su Mac.
};
_saveShortcut.Events = [keyEvent];
}
public override void _Input(InputEvent @event)
{
if (@event is InputEventKey keyEvent &&
_saveShortcut.MatchesEvent(@event) &&
keyEvent.Pressed && !keyEvent.Echo)
{
GD.Print("Scorciatoia Salva attivata!");
GetViewport().SetInputAsHandled();
}
}
}
Proprietà
|
Metodi
get_as_text() const |
|
has_valid_event() const |
|
matches_event(event: InputEvent) const |
Descrizioni delle proprietà
L'array di InputEvent della scorciatoia.
Generalmente l'InputEvent utilizzato è un InputEventKey, anche se può essere un qualsiasi tipo di InputEvent, incluso un InputEventAction.
Descrizioni dei metodi
Restituisce il primo valido InputEvent della scorciatoia come String.
bool has_valid_event() const 🔗
Restituisce se events contiene un InputEvent valido.
bool matches_event(event: InputEvent) const 🔗
Restituisce se qualunque degli InputEvent in events è uguale a event. Questo utilizza InputEvent.is_match() per confrontare gli eventi.