Something like this:
func _input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cancel"):
get_tree().quit() # Quits the game
if event.is_action_pressed("change_mouse_input"):
match Input.get_mouse_mode():
Input.MOUSE_MODE_CAPTURED:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
Input.MOUSE_MODE_VISIBLE:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
if event.is_action_pressed("window_toggle_fullscreen"):
match get_window().mode:
Window.MODE_WINDOWED:
get_window().mode = Window.MODE_FULLSCREEN
Window.MODE_FULLSCREEN:
get_window().mode = Window.MODE_WINDOWED
Window.MODE_EXCLUSIVE_FULLSCREEN:
#This mode is implemented on Windows only.
#On other platforms, it is equivalent to MODE_FULLSCREEN.
get_window().mode = Window.MODE_WINDOWED
This is currently not taking the 'borderless' setting in project settings/window into account. May or may not be relevant. Also better naming scheme for the action so it would be more in line with the built-in actions would have been "wm_toggle_fullscreen"
but I figured it would be clearer for the example so I'll leave it as is above. Keys to use could be for an example F11
, Enter
& KP Enter