Ignore Controller Inputs while tabbed out?

Godot Version

Godot 4.6.1-stable

Question

Hey! Is there a way to ignore any controller inputs if the window for the game isn’t focused? I know there are signals to check when the game is focused/off focus, but is there a way to do like, super pseudocode:

func on_tab_out() → void:
    Input.ignore_joypad_input()

Thanks!

You can get signals for the window being focused; but you cannot quickly disable controller specific inputs, you may have to settle for pausing the game

I fear pausing the game wouldn’t work, since it’s an idle game, my players want to play other games on the side and my game captures input even if it’s unfocused.

1 Like

Good news is there is a pull request with great traction adding just this feature as a simple project setting check box. Maybe 4.7 will have it; fingers crossed

1 Like

You could add a global script to track window focusing, then ensure your actions/input functions are only run when the global focus is set. This could be a lot of work if you do have many controller objects, I think UI focus may still be affected too, unsure how to resolve that specifically, maybe release_focus()?

extends Node

var in_focus: bool = true

func _ready() -> void:
	var window := get_window()
	window.focus_entered.connect(_set_focus.bind(true))
	window.focus_exited.connect(_set_focus.bind(false))


func _set_focus(new_focus: bool) -> void:
	in_focus = new_focus

	if new_focus == false:
		var gui_focus: Control = get_window().gui_get_focus_owner()
		if gui_focus:
			gui_focus.release_focus()

Interesting, hoping it gets in soon!

As for your second message, the whole game is UI Buttons so it’s a bit complicated on that end haha. I’m just going to hope for the issue to get in! Thanks for the info!