Hi,

At first I was using InputEventMouseButton and is_pressed / not is_pressed to detect mouse down and mouse up events, but since I want my game to work on touch screens, I started using InputEventScreenTouch, but then I can detect is_pressed to know if the user is touching the screen, equivalent to mouse down, what do I do in order to detect a "mouse up"? or in other words, is there a way (better to check it constantly on a frame enter event) to know when the user had stopped touching the screen?

I don't know why it didn't work for me before, but this code is working:

func _unhandled_input(event):
	if event is InputEventScreenTouch:
		
		if event.is_pressed():  # touch down.
			mouse_button_pressed = true
			new_mouse_pos = event.get_position()
			new_mouse_original_pos = event.get_position()
		elif not event.is_pressed():  # touch released.
			mouse_button_pressed = false
			if new_mouse_original_pos.distance_to (event.get_position()) < 10:
				new_mouse_click = true;
3 years later

This might come a bit late for you, but we have all been there when we come to an old question and no one replied but we need it. So for any future references, here is an answer I found after having a similar problem:
The problem is that the _unhandled_input(event) function only gets triggered when there actually is any input.
Also
if event is InputEventScreenTouch:
filters out any other events, so
elif not event.is_pressed(): # touch released.
can never be triggered because it would require being pressed to even get there.

The solution I found is the following:
Go to Project settings -> Input Devices -> Pointing
"Emulate Mouse From Touch" should be checked here. If its not, check it.
Now every touchscreen action is also a mouse action. This doesnt always mean you can just make mouse actions and expect touchscreens to work with it, but sometimes it does. And even if it cant solve your entire problem, it can help with it.
For something to be reliably triggered every frame, it needs to be in func _process(delta):
So you can go there and add a check that sees if the left mousebutton is up (like if not Input.is_mouse_button_pressed(1):) and then proceed from there in whatever way you want to.

8 months later