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...
Input
Eredita: Object
Un singleton per gestire gli input.
Descrizione
Il singleton Input gestisce la pressione dei tasti, i pulsanti e i movimenti del mouse, i gamepad e le azioni di input. È possibile impostare le azioni e i loro eventi nella scheda Mappa di Input in Progetto > Impostazioni del progetto, oppure con la classe InputMap.
Nota: I metodi di Input riflettono lo stato di input globale e non sono influenzati da Control.accept_event() o Viewport.set_input_as_handled(), poiché tali metodi si occupano solo del modo in cui gli input vengono propagati nello SceneTree.
Tutorial
Proprietà
Metodi
Segnali
joy_connection_changed(device: int, connected: bool) 🔗
Emesso quando un dispositivo joypad è stato collegato o scollegato.
Enumerazioni
enum MouseMode: 🔗
MouseMode MOUSE_MODE_VISIBLE = 0
Rende visibile il cursore del mouse se è nascosto.
Nasconde il cursore del mouse se è visibile.
MouseMode MOUSE_MODE_CAPTURED = 2
Cattura il mouse. Il mouse sarà nascosto e la sua posizione sarà ristretta al centro della finestra del gestore delle finestre.
Nota: Se si desidera elaborare il movimento del mouse in questa modalità, bisogna usare InputEventMouseMotion.relative.
MouseMode MOUSE_MODE_CONFINED = 3
Restringe il cursore del mouse alla finestra del gioco e lo rende visibile.
Restringe il cursore del mouse alla finestra del gioco e lo rende nascosto.
MouseMode MOUSE_MODE_MAX = 5
Valore massimo di MouseMode.
enum CursorShape: 🔗
CursorShape CURSOR_ARROW = 0
Cursore a freccia. Cursore di puntamento standard e predefinito.
CursorShape CURSOR_IBEAM = 1
Cursore a I. Solitamente utilizzato per mostrare dove apparirà il cursore di testo quando si clicca con il mouse.
CursorShape CURSOR_POINTING_HAND = 2
Cursore di mano che punta. Solitamente utilizzato quando il cursore passa sopra un collegamento o un altro elemento interattivo.
CursorShape CURSOR_CROSS = 3
Cursore a croce. Solitamente appare sulle regioni in cui è possibile eseguire un'operazione di disegno, o per le selezioni.
CursorShape CURSOR_WAIT = 4
Cursore di attesa. Indica che l'applicazione è impegnata nell'esecuzione di un'operazione e che non può essere utilizzata durante l'operazione (ad esempio, qualcosa sta bloccando il suo thread principale).
CursorShape CURSOR_BUSY = 5
Cursore occupato. Indica che l'applicazione è impegnata nell'esecuzione di un'operazione e che è ancora utilizzabile durante l'operazione.
CursorShape CURSOR_DRAG = 6
Cursore di trascinamento. Solitamente visualizzato quando si trascina qualcosa.
Nota: Windows non ha un cursore di trascinamento, quindi CURSOR_DRAG è uguale a CURSOR_MOVE per questa piattaforma.
CursorShape CURSOR_CAN_DROP = 7
Cursore di rilascio . Solitamente visualizzato quando si trascina qualcosa per indicare che può essere rilasciato nella posizione attuale.
CursorShape CURSOR_FORBIDDEN = 8
Cursore di divieto. Indica che l'azione attuale è proibita (ad esempio, quando si trascina qualcosa) o che il controllo in una posizione è disabilitato.
CursorShape CURSOR_VSIZE = 9
Cursore del mouse per il ridimensionamento verticale. Una freccia verticale a due punte. Indica all'utente che può ridimensionare la finestra o il pannello verticalmente.
CursorShape CURSOR_HSIZE = 10
Cursore del mouse per il ridimensionamento orizzontale. Una freccia orizzontale a due punte. Indica all'utente che può ridimensionare la finestra o il pannello orizzontalmente.
CursorShape CURSOR_BDIAGSIZE = 11
Cursore del mouse per ridimensionare la finestra. Il cursore è una freccia a due punte che va dal basso a sinistra all'alto a destra. Indica all'utente che può ridimensionare la finestra o il pannello sia orizzontalmente sia verticalmente.
CursorShape CURSOR_FDIAGSIZE = 12
Cursore del mouse per ridimensionare la finestra. Il cursore è una freccia a due punte che va dall'alto a sinistra al basso a destra, l'opposto di CURSOR_BDIAGSIZE. Indica all'utente che può ridimensionare la finestra o il pannello sia orizzontalmente sia verticalmente.
CursorShape CURSOR_MOVE = 13
Cursore di spostamento. Indica che qualcosa può essere spostato.
CursorShape CURSOR_VSPLIT = 14
Cursore di separazione verticale. Su Windows, è identico a CURSOR_VSIZE.
CursorShape CURSOR_HSPLIT = 15
Cursore di separazione orizzontale. Su Windows, è identico a CURSOR_HSIZE.
CursorShape CURSOR_HELP = 16
Cursore di aiuto. Solitamente un punto interrogativo.
Descrizioni delle proprietà
bool emulate_mouse_from_touch 🔗
Se true, invia eventi di input del mouse quando si tocca o si scorre sul touchscreen. Vedi anche ProjectSettings.input_devices/pointing/emulate_mouse_from_touch.
bool emulate_touch_from_mouse 🔗
Se true, invia eventi di input touch quando si clicca o si trascina il mouse. Vedi anche ProjectSettings.input_devices/pointing/emulate_touch_from_mouse.
bool ignore_joypad_on_unfocused_application 🔗
void set_ignore_joypad_on_unfocused_application(value: bool)
bool is_ignoring_joypad_on_unfocused_application()
If true, joypad input (including motion sensors) and LED light changes will be ignored and joypad vibration will be stopped when the application is not focused.
Controlla la modalità del mouse.
Se true, vengono accumulati gli eventi di input simili inviati dal sistema operativo. Quando l'accumulo di input è abilitato, tutti gli eventi di input generati durante un frame verranno uniti ed emessi quando il frame termina il rendering. Pertanto, questo limita il numero di chiamate al metodo di input al secondo al FPS di rendering.
L'accumulo di input può essere disabilitato per ottenere un input leggermente più preciso/reattivo a costo di un maggiore utilizzo della CPU. Nelle applicazioni in cui è necessario disegnare linee a mano libera, l'accumulo di input dovrebbe generalmente essere disabilitato mentre l'utente sta tracciando la linea per ottenere risultati che seguono più accuratamente l'input.
Nota: L'accumulo di input è abilitato per impostazione predefinita.
Descrizioni dei metodi
void action_press(action: StringName, strength: float = 1.0) 🔗
Questo simulerà la pressione dell'azione specificata.
La forza può essere utilizzata per azioni non booleane, è compresa tra 0 e 1 e rappresenta l'intensità dell'azione specificata.
Nota: Questo metodo non causerà alcuna chiamata a Node._input(). È pensato per essere utilizzato con is_action_pressed() e is_action_just_pressed(). Se si desidera simulare _input, usa invece parse_input_event().
void action_release(action: StringName) 🔗
Se l'azione specificata è già premuta, questo la rilascerà.
void add_joy_mapping(mapping: String, update_existing: bool = false) 🔗
Aggiunge una nuova voce di mappatura (in formato SDL2) al database di mappatura. Aggiorna facoltativamente i dispositivi già connessi.
void clear_joy_motion_sensors_calibration(device: int) 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Clears the calibration information for the specified joypad's motion sensors, if it has any and if they were calibrated.
See start_joy_motion_sensors_calibration() for an example on how to use joypad motion sensors and calibration in your games.
Note: This feature is only supported on Windows, Linux, macOS, and iOS.
void flush_buffered_events() 🔗
Invia tutti gli eventi di input che si trovano nel buffer attuale al ciclo di gioco. Questi eventi potrebbero essere stati bufferizzati come risultato di input accumulati (use_accumulated_input) o di uno svuotamento agile degli input (ProjectSettings.input_devices/buffering/agile_event_flushing).
Il motore lo farà già da solo nei punti di esecuzione importanti (almeno una volta per frame). Tuttavia, questo può essere utile in casi avanzati in cui si desidera un controllo preciso sulla tempistica della gestione degli eventi.
Vector3 get_accelerometer() const 🔗
Restituisce l'accelerazione in m/s² del sensore accelerometro del dispositivo, se il dispositivo ne ha uno. Altrimenti, il metodo restituisce Vector3.ZERO.
Nota che questo metodo restituisce un Vector3 vuoto quando viene eseguito dall'editor anche quando il dispositivo ha un accelerometro. È necessario esportare il progetto su un dispositivo supportato per leggere i valori dall'accelerometro.
Nota: Questo metodo funziona solo su Android e iOS. Su altre piattaforme, restituisce sempre Vector3.ZERO.
Nota: Per Android, ProjectSettings.input_devices/sensors/enable_accelerometer deve essere abilitato.
float get_action_raw_strength(action: StringName, exact_match: bool = false) const 🔗
Restituisce un valore compreso tra 0 e 1 che rappresenta l'intensità grezza dell'azione fornita, ignorando la zona morta dell'azione. Nella maggior parte dei casi, dovresti invece usare get_action_strength().
Se exact_match è false, ignora i modificatori aggiuntivi di input per gli eventi InputEventKey e InputEventMouseButton e la direzione per gli eventi InputEventJoypadMotion.
float get_action_strength(action: StringName, exact_match: bool = false) const 🔗
Restituisce un valore compreso tra 0 e 1 che rappresenta l'intensità dell'azione fornita. In un joypad, ad esempio, più l'asse (stick analogici o i grilletti L2, R2) è lontano dalla zona morta, più il valore sarà vicino a 1. Se l'azione è mappata su un controllo che non ha asse, come la tastiera, il valore restituito sarà 0 o 1.
Se exact_match è false, ignora i modificatori aggiuntivi di input per gli eventi InputEventKey e InputEventMouseButton e la direzione per gli eventi InputEventJoypadMotion.
float get_axis(negative_action: StringName, positive_action: StringName) const 🔗
Ottiene l'input dell'asse specificando due azioni, una negativa e una positiva.
Questo è un'abbreviazione per scrivere Input.get_action_strength("positive_action") - Input.get_action_strength("negative_action").
Array[int] get_connected_joypads() 🔗
Returns an Array containing the device IDs of all currently connected joypads.
Note: The order of connected joypads can not be guaranteed to be the same after a project and/or the editor is restarted, because Godot doesn't save the order of joypad connections. Joypads are registered in the order they are discovered by Godot.
CursorShape get_current_cursor_shape() const 🔗
Restituisce la forma del cursore attualmente assegnata.
Restituisce la gravità in m/s² del sensore accelerometro del dispositivo, se il dispositivo ne ha uno. Altrimenti, il metodo restituisce Vector3.ZERO.
Nota: Questo metodo funziona solo su Android e iOS. Su altre piattaforme, restituisce sempre Vector3.ZERO.
Nota: Per Android, ProjectSettings.input_devices/sensors/enable_gravity deve essere abilitato.
Vector3 get_gyroscope() const 🔗
Restituisce la velocità di rotazione (in radianti al secondo) attorno agli assi X, Y e Z del sensore giroscopio di un dispositivo, se il dispositivo ne ha uno. Altrimenti, il metodo restituisce Vector3.ZERO.
Nota: Questo metodo funziona solo su Android e iOS. Su altre piattaforme, restituisce sempre Vector3.ZERO.
Nota: Per Android, ProjectSettings.input_devices/sensors/enable_gyroscope deve essere abilitato.
Vector3 get_joy_accelerometer(device: int) const 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Returns the acceleration, including the force of gravity, in m/s² of the joypad's accelerometer sensor, if the joypad has one and it's currently enabled. Otherwise, the method returns Vector3.ZERO. See also get_joy_gravity() and set_joy_motion_sensors_enabled().
For a joypad held in front of you, the returned axes are defined as follows:
+X ... -X: left ... right;
+Y ... -Y: bottom ... top;
+Z ... -Z: farther ... closer.
The gravity part value is measured as a vector with length of 9.8 away from the center of the Earth, which is a negative Y value.
Note: This feature is only supported on Windows, Linux, and macOS. On iOS, joypad accelerometer sensor reading is not supported due to OS limitations.
float get_joy_axis(device: int, axis: JoyAxis) const 🔗
Restituisce il valore attuale dell'asse del joypad all'indice [param axis).
Vector3 get_joy_gravity(device: int) const 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Returns the gravity in m/s² of the joypad's accelerometer sensor, if the joypad has one and it's currently enabled. Otherwise, the method returns Vector3.ZERO. See also get_joy_accelerometer() and set_joy_motion_sensors_enabled().
For a joypad held in front of you, the returned axes are defined as follows:
+X ... -X: left ... right;
+Y ... -Y: bottom ... top;
+Z ... -Z: farther ... closer.
The gravity part value is measured as a vector with length of 9.8 away from the center of the Earth, which is a negative Y value.
Note: This feature is only supported on Windows, Linux, and macOS. On iOS, joypad accelerometer sensor reading is not supported due to OS limitations.
String get_joy_guid(device: int) const 🔗
Returns an SDL-compatible device GUID on platforms that use gamepad remapping, e.g. 030000004c050000c405000000010000. Returns an empty string if it cannot be found. Godot uses SDL's internal mappings, supplemented by community-contributed mappings, to determine gamepad names and mappings based on this GUID.
On Windows, all XInput joypad GUIDs will be overridden by Godot to __XINPUT_DEVICE__, because their mappings are the same.
Vector3 get_joy_gyroscope(device: int) const 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Returns the rotation rate in rad/s around a joypad's X, Y, and Z axes of the gyroscope sensor, if the joypad has one and it's currently enabled. Otherwise, the method returns Vector3.ZERO. See also set_joy_motion_sensors_enabled().
The rotation is positive in the counter-clockwise direction.
For a joypad held in front of you, the returned axes are defined as follows:
X: Angular speed around the X axis (pitch);
Y: Angular speed around the Y axis (yaw);
Z: Angular speed around the Z axis (roll).
See start_joy_motion_sensors_calibration() for an example on how to use joypad gyroscope and gyroscope calibration in your games.
Note: This feature is only supported on Windows, Linux, macOS, and iOS.
Dictionary get_joy_info(device: int) const 🔗
Restituisce un dizionario con ulteriori informazioni sul dispositivo, specifiche per la piattaforma, ad esempio il nome grezzo del gamepad dal sistema operativo o l'indice per Steam Input.
Su Windows, Linux, macOS e iOS, il dizionario contiene i seguenti campi:
raw_name: Il nome del controller così come è stato fornito dall'OS, prima di essere rinominato dal database dei controller.
vendor_id: L'ID fornitore USB del dispositivo.
product_id: l'ID prodotto USB del dispositivo.
serial_number: Il numero di serie del dispositivo. Questa chiave non sarà presente se il numero di serie non è disponibile.
Il dizionario può includere anche i seguenti campi per alcune piattaforme:
steam_input_index: l'indice Steam Input del gamepad (solo su Windows, Linux e macOS). Se il dispositivo non è un dispositivo Steam Input questa chiave non sarà presente.
xinput_index: l'indice del controller nel sistema XInput (solo su Windows). Questa chiave non sarà presente sui dispositivi non gestiti da XInput.
Nota: Il dizionario restituito è sempre vuoto su Android e Web.
Dictionary get_joy_motion_sensors_calibration(device: int) const 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Returns the calibration information about the specified joypad's motion sensors in the form of a Dictionary, if it has any and if they have been calibrated, otherwise returns an empty Dictionary.
The dictionary contains the following fields:
gyroscope_offset: average offset in gyroscope values from Vector2.ZERO in rad/s.
See start_joy_motion_sensors_calibration() for an example on how to use joypad motion sensors and calibration in your games.
Note: This feature is only supported on Windows, Linux, macOS, and iOS.
float get_joy_motion_sensors_rate(device: int) const 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Returns the joypad's motion sensor rate in Hz, if the joypad has motion sensors and they're currently enabled. See also set_joy_motion_sensors_enabled().
Note: This feature is only supported on Windows, Linux, macOS, and iOS.
String get_joy_name(device: int) 🔗
Restituisce il nome del joypad all'indice del dispositivo specificato, ad esempio ``PS4 Controller ``. Godot utilizza il database dei controller di gioco SDL2 per determinare i nomi dei gamepad.
float get_joy_vibration_duration(device: int) 🔗
Returns the duration of the current vibration effect in seconds.
Note: This method returns the same value that was passed to start_joy_vibration(), and this value does not change when the joypad's vibration runs out, it only gets reset after a call to stop_joy_vibration().
If you want to check if a joypad is still vibrating, use is_joy_vibrating() instead.
float get_joy_vibration_remaining_duration(device: int) 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Returns the remaining duration of the current vibration effect in seconds.
Vector2 get_joy_vibration_strength(device: int) 🔗
Returns the strength of the joypad vibration: x is the strength of the weak motor, and y is the strength of the strong motor.
Note: This method returns the same values that were passed to start_joy_vibration(), and these values do not change when the joypad's vibration runs out, they only get reset after a call to stop_joy_vibration().
If you want to check if a joypad is still vibrating, use is_joy_vibrating() instead.
Vector2 get_last_mouse_screen_velocity() 🔗
Restituisce l'ultima velocità del mouse in coordinate dello schermo. Per fornire una velocità precisa e senza tremolii, la velocità del mouse viene calcolata solo ogni 0,1 secondi. Pertanto, la velocità del mouse sarà in ritardo rispetto ai movimenti del mouse.
Vector2 get_last_mouse_velocity() 🔗
Restituisce l'ultima velocità del mouse. Per fornire una velocità precisa e senza tremolii, la velocità del mouse viene calcolata solo ogni 0,1 secondi. Pertanto, la velocità del mouse sarà in ritardo rispetto ai movimenti del mouse.
Vector3 get_magnetometer() const 🔗
Restituisce l'intensità del campo magnetico in micro-Tesla per tutti gli assi del sensore magnetometrico del dispositivo, se il dispositivo ne ha uno. Altrimenti, il metodo restituisce Vector3.ZERO.
Nota: Questo metodo funziona solo su Android e iOS. Su altre piattaforme, restituisce sempre Vector3.ZERO.
Nota: Per Android, ProjectSettings.input_devices/sensors/enable_magnetometer deve essere abilitato.
BitField[MouseButtonMask] get_mouse_button_mask() const 🔗
Restituisce i pulsanti del mouse come maschera di bit. Se vengono premuti più pulsanti del mouse allo stesso tempo, i bit vengono sommati. Equivale a DisplayServer.mouse_get_button_state().
Vector2 get_vector(negative_x: StringName, positive_x: StringName, negative_y: StringName, positive_y: StringName, deadzone: float = -1.0) const 🔗
Ottiene un vettore di input specificando quattro azioni per gli assi X e Y positivi e negativi.
Questo metodo è utile quando si ottiene un input vettoriale, ad esempio da un joystick, un pad direzionale, frecce o WASD. Il vettore ha una lunghezza limitata a 1 e ha una zona morta circolare, il che lo rende utile per il movimento.
Per impostazione predefinita, la zona morta viene calcolata automaticamente dalla media delle zone morte delle azioni. Tuttavia, è possibile sovrascrivere la zona morta in modo che sia qualsiasi valore si desidera (nell'intervallo da 0 a 1).
bool has_joy_light(device: int) const 🔗
Returns true if the joypad has an LED light that can change colors and/or brightness. See also set_joy_light().
Note: This feature is only supported on Windows, Linux, macOS, and iOS.
bool has_joy_motion_sensors(device: int) const 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Returns true if the joypad has motion sensors (accelerometer and gyroscope).
Note: On iOS, joypad accelerometer sensor reading is not supported due to OS limitations.
Note: This feature is only supported on Windows, Linux, macOS, and iOS.
bool has_joy_vibration(device: int) const 🔗
Returns true if the joypad supports vibration. See also start_joy_vibration().
Note: For macOS, vibration is only supported in macOS 11 and later. When connected via USB, vibration is only supported for major brand controllers (except Xbox One and Xbox Series X/S controllers) due to macOS limitations.
bool is_action_just_pressed(action: StringName, exact_match: bool = false) const 🔗
Returns true when the user has started pressing the action event in the current frame or physics tick. It will only return true on the frame or tick that the user pressed down the button.
This is useful for code that needs to run only once when an action is pressed, instead of every frame while it's pressed.
If exact_match is false, it ignores additional input modifiers for InputEventKey and InputEventMouseButton events, and the direction for InputEventJoypadMotion events.
Note: Returning true does not imply that the action is still pressed. An action can be pressed and released again rapidly, and true will still be returned so as not to miss input.
Note: Due to keyboard ghosting, is_action_just_pressed() may return false even if one of the action's keys is pressed. See Input examples in the documentation for more information.
Note: During input handling (e.g. Node._input()), use InputEvent.is_action_pressed() instead to query the action state of the current event. See also is_action_just_pressed_by_event().
bool is_action_just_pressed_by_event(action: StringName, event: InputEvent, exact_match: bool = false) const 🔗
Restituisce true quando l'utente ha iniziato a premere l'evento d'azione nel frame o nel tick di fisica attuale. Restituirà true solo sul frame o sul tick in cui l'utente ha premuto il pulsante.
Questo è utile per codice che bisogna eseguire solo una volta quando viene premuta un'azione, anziché a ogni frame mentre viene premuta.
Se exact_match è false, ignora i modificatori aggiuntivi di input per gli eventi InputEventKey e InputEventMouseButton e la direzione per gli eventi InputEventJoypadMotion.
Nota: Restituire true non significa che l'azione sia ancora premuta. Un'azione può essere premuta e rilasciata di nuovo rapidamente e true verrà comunque restituito per non perdere gli input.
Nota: A causa di ghosting per le tastiere, is_action_just_pressed() potrebbe restituire false anche se viene premuto uno dei tasti dell'azione. Consulta Esempi di input nella documentazione per maggiori informazioni.
bool is_action_just_released(action: StringName, exact_match: bool = false) const 🔗
Returns true when the user stops pressing the action event in the current frame or physics tick. It will only return true on the frame or tick that the user releases the button.
Note: Returning true does not imply that the action is still not pressed. An action can be released and pressed again rapidly, and true will still be returned so as not to miss input.
If exact_match is false, it ignores additional input modifiers for InputEventKey and InputEventMouseButton events, and the direction for InputEventJoypadMotion events.
Note: During input handling (e.g. Node._input()), use InputEvent.is_action_released() instead to query the action state of the current event. See also is_action_just_released_by_event().
bool is_action_just_released_by_event(action: StringName, event: InputEvent, exact_match: bool = false) const 🔗
Restituisce true quando l'utente ha finito di premere l'evento azione nel frame o nel tick di fisica attuale, e il primo evento che ha attivato il rilascio dell'azione nel frame/tick di fisica attuale è stato event. Restituirà true solo sul frame o sul tick in cui l'utente ha rilasciato il pulsante.
Ciò è utile quando un'azione è elaborata durante la gestione degli input (ad esempio Node._input()).
Nota: Restituire true non significa che l'azione non sia ancora premuta. Un'azione può essere premuta e rilasciata di nuovo rapidamente e true verrà comunque restituito per non perdere gli input.
Se exact_match è false, ignora i modificatori aggiuntivi di input per gli eventi InputEventKey e InputEventMouseButton e la direzione per gli eventi InputEventJoypadMotion.
bool is_action_pressed(action: StringName, exact_match: bool = false) const 🔗
Restituisce true se si preme l'evento d'azione.
Se exact_match è false, ignora i modificatori aggiuntivi di input per gli eventi InputEventKey e InputEventMouseButton e la direzione per gli eventi InputEventJoypadMotion.
Nota: A causa di ghosting per le tastiere, is_action_just_pressed() potrebbe restituire false anche se viene premuto uno dei tasti dell'azione. Consulta Esempi di input nella documentazione per maggiori informazioni.
bool is_anything_pressed() const 🔗
Restituisce true se è premuto una qualsiasi azione, tasto, pulsante del joypad o pulsante del mouse. Restituirà anche true se un'azione è simulata tramite codice chiamando action_press().
bool is_joy_button_pressed(device: int, button: JoyButton) const 🔗
Restituisce true se si sta premendo il pulsante del joypad all'indice button.
Nota: Se vuoi verificare se un pulsante del joypad è stato appena premuto, usa il sistema di azioni di input di Godot con is_action_just_pressed() oppure usa il metodo Node._input() in questo modo:
func _input(event):
if event is InputEventJoypadButton and event.is_pressed() and event.button_index == JOY_BUTTON_A:
pass # Il tuo codice qui.
public override void _Input(InputEvent @event)
{
if (@event is InputEventJoypadButton eventButton && eventButton.Pressed && eventButton.ButtonIndex == JoyButton.A)
{
// Il tuo codice qui.
}
}
bool is_joy_known(device: int) 🔗
Restituisce true se il sistema riconosce il dispositivo specificato. Ciò significa che imposta tutti gli indici dei pulsanti e degli assi. Non è previsto che i joypad sconosciuti corrispondano a queste costanti, ma è comunque possibile recuperare eventi da essi.
bool is_joy_motion_sensors_calibrated(device: int) const 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Returns true if the joypad's motion sensors have been calibrated.
See start_joy_motion_sensors_calibration() for an example on how to use joypad motion sensors and calibration in your games.
Note: This feature is only supported on Windows, Linux, macOS, and iOS.
bool is_joy_motion_sensors_calibrating(device: int) const 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Returns true if the joypad's motion sensors are currently being calibrated.
See start_joy_motion_sensors_calibration() for an example on how to use joypad motion sensors and calibration in your games.
Note: This feature is only supported on Windows, Linux, macOS, and iOS.
bool is_joy_motion_sensors_enabled(device: int) const 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Returns true if the requested joypad has motion sensors (accelerometer and gyroscope) and they are currently enabled. See also set_joy_motion_sensors_enabled() and has_joy_motion_sensors().
See start_joy_motion_sensors_calibration() for an example on how to use joypad motion sensors and calibration in your games.
Note: This feature is only supported on Windows, Linux, macOS, and iOS.
bool is_joy_vibrating(device: int) 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Returns true if the joypad is still vibrating after a call to start_joy_vibration().
Unlike get_joy_vibration_strength() and get_joy_vibration_duration(), this method returns false after the joypad's vibration runs out.
bool is_key_label_pressed(keycode: Key) const 🔗
Returns true if you are pressing the key with the keycode printed on it. You can pass a Key constant or any Unicode character code.
Note: If you want to check if a key was just pressed by using its label, use Godot's input action system with is_action_just_pressed() or use the Node._input() method like this instead:
func _input(event):
if event is InputEventKey and not event.is_echo() and event.is_pressed() and event.key_label == KEY_SPACE:
pass # Your code here.
public override void _Input(InputEvent @event)
{
if (@event is InputEventKey eventKey && !eventKey.IsEcho() && eventKey.Pressed && eventKey.KeyLabel == Key.Space)
{
// Your code here.
}
}
bool is_key_pressed(keycode: Key) const 🔗
Restituisce true se si sta premendo il tasto latino nel layout di tastiera attuale. È possibile passare una costante di Key.
is_key_pressed() è consigliato solo rispetto a is_physical_key_pressed() in applicazioni non di gioco. Ciò garantisce che i tasti di scelta rapida si comportino come previsto a seconda del layout di tastiera dell'utente, poiché i tasti di scelta rapida dipendono generalmente dal layout di tastiera in applicazioni non di gioco. In caso di dubbi, usa is_physical_key_pressed().
Nota: A causa del ghosting delle tastiere, is_action_just_pressed() potrebbe restituire false anche se viene premuto uno dei tasti dell'azione. Consulta Esempi di input nella documentazione per maggiori informazioni.
Nota: Se vuoi verificare se un tasto è stato appena premuto tramite il suo codice di tasto, usa il sistema di azioni di input di Godot con is_action_just_pressed() oppure usa il metodo Node._input() in questo modo:
func _input(event):
if event is InputEventKey and not event.is_echo() and event.is_pressed() and event.keycode == KEY_SPACE:
pass # Il tuo codice qui.
public override void _Input(InputEvent @event)
{
if (@event is InputEventKey eventKey && !eventKey.IsEcho() && eventKey.Pressed && eventKey.Keycode == Key.Space)
{
// Il tuo codice qui.
}
}
bool is_mouse_button_pressed(button: MouseButton) const 🔗
Restituisce true se si sta premendo il pulsante del mouse specificato con MouseButton.
Nota: Se vuoi verificare se un pulsante del mouse è stato appena premuto, usa il sistema di azioni di input di Godot con is_action_just_pressed() oppure usa il metodo Node._input() in questo modo:
func _input(event):
if event is InputEventMouseButton and event.is_pressed() and event.button_index == MOUSE_BUTTON_LEFT:
pass # Il tuo codice qui.
public override void _Input(InputEvent @event)
{
if (@event is InputEventMouseButton eventMouseButton && eventMouseButton.Pressed && eventMouseButton.ButtonIndex == MouseButton.Left)
{
// Il tuo codice qui.
}
}
bool is_physical_key_pressed(keycode: Key) const 🔗
Restituisce true se si sta premendo il tasto nella posizione fisica sulla tastiera QWERTY statunitense a 101/102 tasti. È possibile passare una costante di Key.
is_physical_key_pressed() è consigliato rispetto a is_key_pressed() per le azioni di gioco, poiché farà funzionare i layout W/A/S/D a prescindere dal layout della tastiera dell'utente. is_physical_key_pressed() garantirà inoltre che i tasti numerici della riga superiore funzionino su qualsiasi layout di tastiera. In caso di dubbi, usa is_physical_key_pressed().
Nota: A causa del ghosting delle tastiere, is_action_just_pressed() potrebbe restituire false anche se viene premuto uno dei tasti dell'azione. Consulta Esempi di input nella documentazione per maggiori informazioni.
Nota: Se vuoi verificare se un tasto è stato appena premuto tramite il suo codice di tasto fisico, usa il sistema di azioni di input di Godot con is_action_just_pressed() oppure usa il metodo Node._input() in questo modo:
func _input(event):
if event is InputEventKey and not event.is_echo() and event.is_pressed() and event.physical_keycode == KEY_SPACE:
pass # Il tuo codice qui.
public override void _Input(InputEvent @event)
{
if (@event is InputEventKey eventKey && !eventKey.IsEcho() && eventKey.Pressed && eventKey.PhysicalKeycode == Key.Space)
{
// Il tuo codice qui.
}
}
void parse_input_event(event: InputEvent) 🔗
Fornisce un InputEvent al gioco. Può essere utilizzato per attivare artificialmente eventi di input da codice. Genera anche chiamate a Node._input().
var cancel_event = InputEventAction.new()
cancel_event.action = "ui_cancel"
cancel_event.pressed = true
Input.parse_input_event(cancel_event)
var cancelEvent = new InputEventAction();
cancelEvent.Action = "ui_cancel";
cancelEvent.Pressed = true;
Input.ParseInputEvent(cancelEvent);
Nota: Chiamare questa funzione non influenza il sistema operativo. Ad esempio, l'invio di un InputEventMouseMotion non sposterà il cursore del mouse del sistema operativo nella posizione specificata (usa invece warp_mouse()) e l'invio di Alt/Cmd + Tab come InputEventKey non consentirà di alternare le finestre attive.
void remove_joy_mapping(guid: String) 🔗
Rimuove tutte le mappature dal database interno che corrispondono al GUID specificato. Tutti i joypad attualmente connessi che utilizzano questo GUID diventeranno non mappati.
Su Android, Godot mapperà una mappatura interna di riserva.
void set_accelerometer(value: Vector3) 🔗
Imposta il valore di accelerazione del sensore accelerometro. Può essere utilizzato per il debug su dispositivi senza sensore, ad esempio in un editor su un PC.
Nota: Questo valore può essere immediatamente sovrascritto dal valore del sensore su Android e iOS.
void set_custom_mouse_cursor(image: Resource, shape: CursorShape = 0, hotspot: Vector2 = Vector2(0, 0)) 🔗
Imposta un'immagine personalizzata per il cursore del mouse, visibile solo all'interno della finestra di gioco. È anche possibile specificare il punto dove è centrata l'immagine. Passando null al parametro dell'immagine si reimposta il cursore del sistema.
image può essere Texture2D o Image e la sua dimensione deve essere inferiore o uguale a 256×256. Per evitare problemi di rendering, si consigliano dimensioni inferiori o uguali a 128×128.
hotspot deve essere all'interno della dimensione di image.
Nota: Le AnimatedTexture non sono supportate come cursori del mouse personalizzati. Se si utilizza una AnimatedTexture, verrà visualizzato solo il primo fotogramma.
Nota: Sono consigliate le modalità di compressione Lossless, Lossy o Uncompressed. È possibile utilizzare la modalità di compressione Video RAM, ma sarà decompressa sulla CPU, il che significa che i tempi di caricamento saranno rallentati e memoria non sarà risparmiata rispetto alle modalità lossless.
Nota: Sulla piattaforma web, le dimensioni massime consentite per l'immagine del cursore sono 128×128. Le immagini del cursore più grandi di 32×32 saranno visualizzate solo se l'immagine del cursore del mouse si trova interamente all'interno della pagina per motivi di sicurezza.
void set_default_cursor_shape(shape: CursorShape = 0) 🔗
Imposta la forma predefinita del cursore da utilizzare nella viewport invece di CURSOR_ARROW.
Nota: Se si desidera modificare la forma predefinita del cursore per i nodi Control, usa invece Control.mouse_default_cursor_shape.
Nota: Questo metodo genera un InputEventMouseMotion per aggiornare immediatamente il cursore.
void set_gravity(value: Vector3) 🔗
Imposta il valore di gravità del sensore accelerometro. Può essere utilizzato per il debug su dispositivi senza sensore, ad esempio in un editor su un PC.
Nota: Questo valore può essere immediatamente sovrascritto dal valore del sensore su Android e iOS.
void set_gyroscope(value: Vector3) 🔗
Imposta il valore della velocità di rotazione del sensore giroscopio. Può essere utilizzato per il debug su dispositivi senza sensore, ad esempio in un editor su un PC.
Nota: Questo valore può essere immediatamente sovrascritto dal valore del sensore su Android e iOS.
void set_joy_light(device: int, color: Color) 🔗
Sets the joypad's LED light, if available, to the specified color. See also has_joy_light().
Note: There is no way to get the color of the light from a joypad. If you need to know the assigned color, store it separately.
Note: This feature is only supported on Windows, Linux, macOS, and iOS.
void set_joy_motion_sensors_calibration(device: int, calibration_info: Dictionary) 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Sets the specified joypad's calibration information. See also get_joy_motion_sensors_calibration().
See start_joy_motion_sensors_calibration() for an example on how to use joypad motion sensors and calibration in your games.
Note: This feature is only supported on Windows, Linux, macOS, and iOS.
void set_joy_motion_sensors_enabled(device: int, enable: bool) 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Enables or disables the motion sensors (accelerometer and gyroscope), if available, on the specified joypad.
See start_joy_motion_sensors_calibration() for an example on how to use joypad motion sensors and calibration in your games.
It's recommended to disable the motion sensors when they're no longer being used, because otherwise it might drain the controller battery faster.
Note: This feature is only supported on Windows, Linux, macOS, and iOS.
void set_magnetometer(value: Vector3) 🔗
Imposta il valore del campo magnetico del sensore magnetometro. Può essere utilizzato per il debug su dispositivi senza sensore, ad esempio in un editor su un PC.
Nota: Questo valore può essere immediatamente sovrascritto dal valore del sensore su Android e iOS.
bool should_ignore_device(vendor_id: int, product_id: int) const 🔗
Richiede se un dispositivo di input deve essere ignorato o meno. È possibile ignorare i dispositivi impostando la variabile di ambiente SDL_GAMECONTROLLER_IGNORE_DEVICES. Leggi la documentazione SDL per maggiori informazioni.
Nota: Alcuni strumenti di terze parti possono contribuire all'elenco dei dispositivi ignorati. Ad esempio, SteamInput crea dispositivi virtuali da dispositivi fisici per scopi di rimappatura. Per evitare di gestire lo stesso dispositivo di input due volte, il dispositivo originale è aggiunto all'elenco di quelli ignorati.
void start_joy_motion_sensors_calibration(device: int) 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Starts the process of calibrating the specified joypad's gyroscope, if it has one.
Once a joypad's gyroscope has been calibrated correctly (e.g. laying still on a table without being rotated), get_joy_gyroscope() will return values close or equal to Vector3.ZERO when the joypad is not being rotated.
Here's an example of how to use joypad gyroscope and gyroscope calibration in your games:
const GYRO_SENSITIVITY = 10.0
func _ready():
# In this example we only use the first connected joypad (id 0).
if 0 not in Input.get_connected_joypads():
return
if not Input.has_joy_motion_sensors(0):
return
# We must enable the motion sensors before using them.
Input.set_joy_motion_sensors_enabled(0, true)
# (Tell the users here that they need to put their joypads on a flat surface and wait for confirmation.)
# Start the calibration process.
calibrate_motion()
func _process(delta):
# Only move the object if the joypad motion sensors are calibrated.
if Input.is_joy_motion_sensors_calibrated(0):
move_object(delta)
func calibrate_motion():
Input.start_joy_motion_sensors_calibration(0)
# Wait for some time.
await get_tree().create_timer(1.0).timeout
Input.stop_joy_motion_sensors_calibration(0)
# The joypad is now calibrated.
func move_object(delta):
var node: Node3D = ... # Put your node here.
var gyro := Input.get_joy_gyroscope(0)
node.rotation.x -= -gyro.y * GYRO_SENSITIVITY * delta # Use rotation around the Y axis (yaw) here.
node.rotation.y += -gyro.x * GYRO_SENSITIVITY * delta # Use rotation around the X axis (pitch) here.
private const float GyroSensitivity = 10.0;
public override void _Ready()
{
// In this example we only use the first connected joypad (id 0).
if (!Input.GetConnectedJoypads().Contains(0))
{
return;
}
if (!Input.HasJoyMotionSensors(0))
{
return;
}
// We must enable the accelerometer and the gyroscope before using them.
Input.SetJoyMotionSensorsEnabled(0, true);
// (Tell the users here that they need to put their joypads on a flat surface and wait for confirmation.)
// Start the calibration process.
CalibrateMotion();
}
public override void _Process(double delta)
{
// Only move the object if the joypad motion sensors are calibrated.
if (Input.IsJoyMotionSensorsCalibrated(0))
{
MoveObject(delta);
}
}
private async Task CalibrateMotion()
{
Input.StartJoyMotionSensorsCalibration(0);
// Wait for some time.
await ToSignal(GetTree().CreateTimer(1.0), SceneTreeTimer.SignalName.Timeout);
Input.StopJoyMotionSensorsCalibration(0);
// The joypad is now calibrated.
}
private void MoveObject(double delta)
{
Node3D node = ... ; // Put your object here.
Vector3 gyro = Input.GetJoyGyroscope(0);
Vector3 rotation = node.Rotation;
rotation.X -= -gyro.Y * GyroSensitivity * (float)delta; // Use rotation around the Y axis (yaw) here.
rotation.Y += -gyro.X * GyroSensitivity * (float)delta; // Use rotation around the X axis (pitch) here.
node.Rotation = rotation;
}
Note: Accelerometer sensor doesn't usually require calibration.
Note: This feature is only supported on Windows, Linux, macOS, and iOS.
void start_joy_vibration(device: int, weak_magnitude: float, strong_magnitude: float, duration: float = 0) 🔗
Inizia a far vibrare il joypad. Vedi anche has_joy_vibration() and is_joy_vibrating().
I joypad solitamente sono dotati di due motori di vibrazione, uno forte e uno debole.
weak_magnitude è l'intensità del motore debole (tra 0.0 e 1.0).
strong_magnitude è l'intensità del motore forte (tra 0.0 e 1.0).
duration è la durata dell'effetto in secondi (una durata di 0.0 proverà a riprodurre la vibrazione il più a lungo possibile, ovvero circa 65 secondi).
È possibile interrompere la vibrazione in anticipo chiamando stop_joy_vibration().
Vedi anche get_joy_vibration_strength() and get_joy_vibration_duration().
Nota: Per macOS, la vibrazione è supportata solo a partire da macOS 11. Quando connesso tramite USB, la vibrazione è supportata solo per i controller delle principali marche (ad eccezione dei controller Xbox One e Xbox Series X/S) a causa delle limitazioni di macOS.
void stop_joy_motion_sensors_calibration(device: int) 🔗
Sperimentale: Questo metodo potrebbe essere cambiato o rimosso in versioni future.
Stops the calibration process of the specified joypad's motion sensors.
See start_joy_motion_sensors_calibration() for an example on how to use joypad motion sensors and calibration in your games.
Note: This feature is only supported on Windows, Linux, macOS, and iOS.
void stop_joy_vibration(device: int) 🔗
Arresta la vibrazione del joypad avviata con start_joy_vibration().
void vibrate_handheld(duration_ms: int = 500, amplitude: float = -1.0) 🔗
Vibra il dispositivo portatile per la durata specificata in millisecondi.
amplitude è l'intensità della vibrazione, come valore compreso tra 0.0 e 1.0. Se impostato su -1.0, viene utilizzata l'intensità di vibrazione predefinita del dispositivo.
Nota: Questo metodo è implementato su Android, iOS e Web. Non ha effetto su altre piattaforme.
Nota: Per Android, vibrate_handheld() richiede di abilitare l'autorizzazione VIBRATE nella preimpostazione d'esportazione. Altrimenti, vibrate_handheld() non avrà effetto.
Nota: Per iOS, specificare la durata è supportato solo da iOS 13 in poi.
Nota: Per Web, l'intensità non può essere cambiata.
Nota: Alcuni browser web come Safari e Firefox per Android non supportano vibrate_handheld().
Nota: Le impostazioni del dispositivo, come l'abilitazione della vibrazione, di specifici feedback aptici, o della modalità "Non disturbare" potrebbero impedire l'effetto di vibrate_handheld().
void warp_mouse(position: Vector2) 🔗
Imposta la posizione del mouse sul vettore specificato, fornito in pixel e relativo a un'origine nell'angolo in alto a sinistra della finestra di gioco attualmente focalizzata.
La posizione del mouse viene ritagliata ai limiti della risoluzione dello schermo o ai limiti della finestra di gioco se MouseMode è impostato su MOUSE_MODE_CONFINED o MOUSE_MODE_CONFINED_HIDDEN.
Nota: warp_mouse() è supportato solo su Windows, macOS e Linux. Non ha effetto su Android, iOS e Web.