Make sure to format your scripts when pasting.
No need for your script to be in _process
, it does not need to run every frame. Use _input
and check event.is_action_pressed("fullscreen")
Here’s a slim script that can be placed as a Global as you’ve mentioned
extends Node
func _input(event: InputEvent) -> void:
if event.is_action_pressed("fullscreen"):
var mode := DisplayServer.window_get_mode()
var window: bool = mode != DisplayServer.WINDOW_MODE_FULLSCREEN
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN if window else DisplayServer.WINDOW_MODE_WINDOWED)