How to toggle fullscreen and manage multiple key presses

I want to use alt+enter keyboard combination to toggle on or off fullscreen mode. Is it possible to check two key presses at the same time? And how would I change from windowed to fullscreen mode?

1 Like

I think you can add like alt as func1 and enter as func2 and in the script if the player presses them at the same time … then toggles on or off ! :slight_smile:

You mean, I should create 2 key bindings in the game.input_binding file for alt and enter keys? That’s the easy part.
How do I check for key presses at the same time? Doesn’t the message system fires for each key press separately?

Yes … I meant that , but it sure cannot be absolutely on the same time … there can be for say 2-5 seconds between the two presses .

function on_input(self, action_id, action)
	if action_id and action.pressed then
		print(action_id)
		local now = socket.gettime()
		if now - self.last_input_time > 0.35 then
			self.actions = {}
		end
		self.last_input_time = now
		table.insert(self.actions, action_id)

		local attack = find_attack(self.actions)
		if attack then
			label.set_text("/attack#label", attack.name)
			play_animation(self, attack.anim)
		end
	end
end

This code is from a public example , but im sure you can rewrite it to fit your problem !

Thanks, that gave me some ideas. I’ve come with this solution for multiple key presses :

function set_fullscreen(self)
	print(tostring(self.is_fullscreen))
	self.is_fullscreen = not self.is_fullscreen
end

function init(self)
	msg.post(".", "acquire_input_focus")
	self.alt_is_pressed = false
	self.is_fullscreen = false
end

function on_input(self, action_id, action)
	if action_id == hash("alt") then
		if action.released then
			self.alt_is_pressed = false
		else
			self.alt_is_pressed = true
		end
	end
	if action_id == hash("enter") and self.alt_is_pressed then
		set_fullscreen(self)
	end
end

However, I’ve got no idea how to set the game in fullscreen mode.

You’ll want to take a look at DefOS.

2 Likes

Good advice. Thanks. So, there is no feature in Defold natively?

As far as I am aware, no, but I could be wrong.