how to make game pause if mouse outside viewport or game screen?

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

how to make game pause if mouse outside viewport or game screen? i try to use this
but keep get return value everytime i move my mouse.
NOTIFICATIONWMMOUSE_ENTER
NOTIFICATIONWMMOUSE_EXIT

this my current code. work and not work because need to - 1 pixel or more.

func _ready() -> void:
	global_position = get_viewport().size/2

func _input(event: InputEvent) -> void:
	if get_global_mouse_position().x > 1270 or get_global_mouse_position().x < 10 or get_global_mouse_position().y < 10 or get_global_mouse_position().y > 710:
		get_tree().paused = true
		
	global_position = lerp((get_viewport().get_mouse_position()),global_position,0.6)
:bust_in_silhouette: Reply From: AiTechEye
func _notification(what):
	if what == MainLoop.NOTIFICATION_WM_MOUSE_ENTER:
		print("Mouse inside")
		get_tree().paused = false
	elif what == MainLoop.NOTIFICATION_WM_MOUSE_EXIT:
		print("Mouse outside")
		get_tree().paused = true
	if what == MainLoop.NOTIFICATION_WM_FOCUS_IN:
		print("focus in")
	elif what == MainLoop.NOTIFICATION_WM_FOCUS_OUT:
		print("focus out")
		pause_mode = true