How to detect when the game loses and gains focus

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Aaron

How do I detect when the game itself loses or gains focus (user alt-tabbed, user switched to other window, etc.)?

:bust_in_silhouette: Reply From: volzhs
func _notification(what):
	if what == MainLoop.NOTIFICATION_WM_FOCUS_IN:
		print("focus in")
	elif what == MainLoop.NOTIFICATION_WM_FOCUS_OUT:
		print("focus out")

This is not working on the HTML5 exported version of my game.

Any workaround?

dpensky | 2021-04-20 12:09