Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] 'InputEventScreenTouch' not detected for fast multiple touches #67033

Closed
ehsanngp opened this issue Oct 7, 2022 · 12 comments
Closed

Comments

@ehsanngp
Copy link

ehsanngp commented Oct 7, 2022

Godot version

4.0 Beta 2

System information

Ubuntu 16.04

Issue description

I have used custom code in previous versions (up until 4.0 Beta 1) to detect double-click on touch screen on Android.

I suspected that same code does not work in 4.0 Beta 2. After watching the logs it seems the second touch press is not getting detected if it is fast (less than a second or so).

Steps to reproduce

  1. Create a TextureRect.
  2. Add code to handle _unhandled_input or gui_input.
  3. Test on Android device. Press the touch two times fast enough, and only the first touch gets detected.

Emulate Touch From Mouse is always turned off
The bug occurs either the Emulate Mouse From Touch is turned off or on

Minimal reproduction project

TouchTest.zip

Use your owns keystores, usernames and passwords

@ehsanngp
Copy link
Author

ehsanngp commented Oct 8, 2022

I debugged the problem further,

It seems that even if you disable Emulate Touch From Mouse and Emulate Mouse From Touch, when you double tap on touch screen, the second touch is falsely interpreted as InputEventMouseButton instead of InputEventScreenTouch.

Just use a function similar to this as gui_input receiver, to watch the input event's type:

func _on_TextureRect_gui_input(event):
	print(event.get_class());
	if event is InputEventScreenTouch:
		print(event.pressed)

@RandomShaper
Copy link
Member

I've tracked this down to #65434. Double tap detection specific to Android is giving the user the chance to tap again within some time limit and during that time the subsequent tap is inhibited.

CC @m4gr3d

@m4gr3d
Copy link
Contributor

m4gr3d commented Oct 17, 2022

@RandomShaper @ehsanngp The logic to detect and handle double-click within Godot has now been fixed (was broken before) and so what you're seeing is the correct behavior.

The second double-click is correctly detected and turned into an InputEventMouseButton event with the double-clickattribute set to true.

@ehsanngp You'd want to update your logic to query for that event now.

@m4gr3d m4gr3d closed this as completed Oct 17, 2022
@RandomShaper
Copy link
Member

@m4gr3d, I still think that on Android you can't anymore get quick taps in a row. My game is unplayable now as a result of that (once I rebased my Godot fork on top of the current 3.x branch) and I tracked the issue down to the counterpart of #65434 for 3.x. Removing double tap handling from the newly added Android code does the trick.

@m4gr3d
Copy link
Contributor

m4gr3d commented Oct 17, 2022

@m4gr3d, I still think that on Android you can't anymore get quick taps in a row. My game is unplayable now as a result of that (once I rebased my Godot fork on top of the current 3.x branch) and I tracked the issue down to the counterpart of #65434 for 3.x. Removing double tap handling from the newly added Android code does the trick.

@RandomShaper Quick taps should work as expected, the same logic is used to drive double-click handling in the Godot Android Editor, and double-click using either mouse or finger works as expected regardless of the speed.

The issue with your game may be similar to @ehsanngp's issue. It's likely that you're expecting and parsing a second InputEventScreenTouch event. With the fix, only a InputEventMouseButton event will be sent on the second tap.
This matches the behavior on the other platforms.

@RandomShaper
Copy link
Member

My game is not reacting to mouse but touch. There's a TouchScreenButton that on Windows, with mouse-to-touch emulation enabled, allows quick taps in a row since it receives individual InputEventScreenTouch. Not tested after the rebase, but I'm pretty sure that it still works the same on iOS.

@m4gr3d
Copy link
Contributor

m4gr3d commented Oct 17, 2022

@RandomShaper Then that's another issue; specifically that TouchScreenButton doesn't react to double-click events.

The InputEventScreenTouch event doesn't have a double-click attribute, so when double-click are detected, they're converted to InputEventMouseButton so the double-click can be propagated.
This has been the behavior for quite a while, except that the Android implementation was buggy for tap. The referenced PR fixed that implementation, unveiling this issue.

There's a couple of paths here:

  1. Expand the InputEventScreenTouch event with a double-click attribute. This is right approach, but more complex solution as all locations in the code dealing with double-click events need to be updated to support the expanded InputEventScreenTouch event as well.
  2. Update TouchScreenButton to handle InputEventMouseButton only for double-click... Quick fix, but likely to create more complication.

I'm unfortunately short on time at the moment so I won't be able to get to it for a bit, but would review any proposed PR that addresses option 1.

@RandomShaper
Copy link
Member

I don't see how either of the approaches would fix the issue. We don't need that TouchScreenButton or scripts get awareness of a double click/tap. That would mean missing information. A game needs to react exactly when each tap happens. Getting a delayed notion of 'two taps happened somewhat quickly' is not enough.

@ehsanngp
Copy link
Author

ehsanngp commented Oct 18, 2022

It seems that even if you disable Emulate Touch From Mouse and Emulate Mouse From Touch, when you double tap on touch screen, the second touch is falsely interpreted as InputEventMouseButton instead of InputEventScreenTouch.

@m4gr3d
Thanks for looking into problem,

I think the problem should not have been closed as it is currently working wrong by design.
From what I said before:

It seems that even if you disable Emulate Touch From Mouse and Emulate Mouse From Touch, when you double tap on touch screen, the second touch is falsely interpreted as InputEventMouseButton instead of InputEventScreenTouch.

It seems logically wrong in terms of design that I receive the first InputEventScreenTouch in any case (using any combo of emulation turned on/off), but do not receive the second InputEventScreenTouch in some case.

That said, the problem seems two folded:
1- If I turn off both ways of emulation, specially Emulate Mouse From Touch, then I should NOT receive any InputEventMouseButton event, which I clearly receive now.
2- If I turn on Emulate Mouse From Touch, I should still get the InputEventScreenTouch for second (fast-following) touch, alongside InputEventMouseButton with doubleTap attribute, which I clearly don't receive now.

@ehsanngp
Copy link
Author

@m4gr3d, I still think that on Android you can't anymore get quick taps in a row. My game is unplayable now as a result of that (once I rebased my Godot fork on top of the current 3.x branch) and I tracked the issue down to the counterpart of #65434 for 3.x. Removing double tap handling from the newly added Android code does the trick.

@RandomShaper Quick taps should work as expected, the same logic is used to drive double-click handling in the Godot Android Editor, and double-click using either mouse or finger works as expected regardless of the speed.

The issue with your game may be similar to @ehsanngp's issue. It's likely that you're expecting and parsing a second InputEventScreenTouch event. With the fix, only a InputEventMouseButton event will be sent on the second tap. This matches the behavior on the other platforms.

That is where the design problem lies, ALL InputEventMouseButton should always be propagated immediately regardless of emulation settings.
Also If I am not interested in emulating the mouse from touch, I should not receive any event regarding mouse button!

@ehsanngp
Copy link
Author

ehsanngp commented Oct 18, 2022

I don't see how either of the approaches would fix the issue. We don't need that TouchScreenButton or scripts get awareness of a double click/tap. That would mean missing information. A game needs to react exactly when each tap happens. Getting a delayed notion of 'two taps happened somewhat quickly' is not enough.

I'll second that.

@m4gr3d
Copy link
Contributor

m4gr3d commented Oct 19, 2022

@ehsanngp PR #67607 adds a double_tap attribute to the InputEventScreenTouch event.
As mentioned in #67033 (comment), it addresses the concerns you had, and should allow you to simplify your logic by using the double_tap attribute from the InputEventScreenTouch event instead of using custom code to detect double-clicks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants