How to distinguish between mouse and touch events


#1

I thought it would be easy to distinguish between mouse and touch events using:

MouseEvent e // as an argument to the Component::mouseDown virtual function

e.source.isMouse()
// and
e.source.isTouch()

However, isMouse() always returns true, and isTouch() always false, whether I use a trackpad, stylus, or fingers on the screen. I haven't been able to find a thread about this in the forum. Is there something I need to do during setup to enable touch events?

Some information that may be relevant: This is on a Surface Pro 3, running Windows 8.1, and the component is also an OpenGLRenderer.

Thanks!


#2

IIRC when there's only a single touch, it's treated as a mouse event by Windows, and it's only when you have several touches going that they get labelled as fingers. Can't remember the details, and it might be something that could be improved now, since I originally wrote it when Windows touch input had just been released, and they've improved it since then. I've no time to look at it now, but the place to dig around would be in handleTouchInput() in the windows peer class


#3

Yep, you're right. Multiple fingers will trigger the isTouch function to return true. I'll dig into the peer class to see if I can figure something out, unless it's just a Windows thing that's unavoidable. Thanks!