1
0
Fork 0
ExampleProject/FullscreenToggler.gd

30 lines
1.4 KiB
GDScript3
Raw Normal View History

2024-03-14 11:50:53 +00:00
extends Node
# Called when the node enters the scene tree for the first time.
func _ready():
#InputMap.action_get_events()
var hotkey = ProjectSettings.get_setting("input/HotKey_ToggleFullscreen")
#print(InputMap.action_get_events("character_forwards"))
#print(InputMap.action_get_events("HotKey_ToggleFullscreen"))
2024-03-14 11:50:53 +00:00
if hotkey == null:
print("PLEASE GO Project->Project Settings... , Input Map, and add HotKey_ToggleFullscreen")
InputMap.add_action("HotKey_ToggleFullscreen")
#InputMap.action_add_event()
#print(hotkey)
2024-03-14 11:50:53 +00:00
var temporal_deadzone : float = 0
2024-03-14 11:50:53 +00:00
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if temporal_deadzone > 0.0:
temporal_deadzone -= delta
func _input(event: InputEvent) -> void:
2024-03-14 11:50:53 +00:00
#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 event.is_action_pressed("HotKey_ToggleFullscreen") and temporal_deadzone <= 0.0:
2024-03-14 11:50:53 +00:00
if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
else:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
temporal_deadzone = 0.5