Kha icon indicating copy to clipboard operation
Kha copied to clipboard

Don't duplicate touch events to mouse

Open dewitters opened this issue 5 years ago • 8 comments

I have a HTML5 game that runs both on desktop and mobile. On mobile I need multi-touch support for controlling both a virtual joystick and buttons. In Javascript you handle mouse and touch events separately, and so you implement both and all works on all devices.

Kha conveniently forwards all touch events to mouse events. This is handy when it should work the same on both desktop and mobile, but very annoying when you need to handle multi-touch separately, since you will get duplicate events coming in at the mouse.

HTML5 doesn't allow detecting if you are working with a touch device, so you cannot just block mouse events on those devices.

My proposed solution is to forward touch events to mouse by default, but once you set touch listeners, Kha assumes you are handling touch yourself and so disables the forwarding.

I will implement this myself and will send a pull request, but just want to check if this is the solution we want or not?

dewitters avatar Jan 14 '20 08:01 dewitters

I like that, me wants it.

RobDangerous avatar Jan 14 '20 08:01 RobDangerous

Hm, that sounds complicated, how about a simpler static bool kha.System.forwardTouchEvents = true; or something that you can manually override?

sh-dave avatar Jan 14 '20 08:01 sh-dave

I prefer dewitter's solution here, it doesn't sound complicated to me.

RobDangerous avatar Jan 14 '20 08:01 RobDangerous

I thought about the bool too, but in my solution the bool is basically touchListener != null.

dewitters avatar Jan 14 '20 10:01 dewitters

@dewitters any progress on this?

Sanva avatar Mar 31 '21 19:03 Sanva

No pressuring of our beautiful contributors, please. Instead ask how you can help 😇 (and thereby build pressure indirectly).

RobDangerous avatar Mar 31 '21 19:03 RobDangerous

It was more like if you aren't working on this anymore I'll give it a try than work, work!! :sweat_smile:

Sanva avatar Apr 01 '21 06:04 Sanva

That's what I hoped 👍

RobDangerous avatar Apr 01 '21 07:04 RobDangerous