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.

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()

Proprietà

Array

events

[]

Metodi

String

get_as_text() const

bool

has_valid_event() const

bool

matches_event(event: InputEvent) const


Descrizioni delle proprietà

Array events = [] 🔗

  • void set_events(value: Array)

  • Array get_events()

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

String get_as_text() const 🔗

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.