iOS: can you differ between touch and mouse device input?

With iOS now allowing to use mouse (for the last one or two years, I think) can you recognize whether one uses a mouse device or using touch?
We’ve been hiding our cursor on iOS which is now annoying for those that use a mouse and we are wondering whether to make it an option to show the mouse or whether we can make it work so that the cursor shows when it’s moved via a device.

Since SDL 2.0.10 there’s SDL_HINT_MOUSE_TOUCH_EVENTS and SDL_HINT_TOUCH_MOUSE_EVENTS but I’m not sure if they work in iOS. They also seem to be completely undocumented!

ah yes, I remember those and I will need to experiment with them if I use the user option to toggle the mouse cursor. But whether SDL2 can differ on its own what kind of event is happening is the big question.

Supposedly, if you set both those hints to “0” you will receive only touch events from touch (no synthesized mouse events), and only mouse events from the mouse (no synthesized touch events). If they work, you could enable your cursor whenever there’s a mouse event and disable it whenever there’s a touch event.

Ah, now I understand. Thank you! I’ll play with that

there is also SDL_TOUCH_MOUSEID to identify the pseudo mouse that sends events

I played a bit with these but so far could not find a way to properly use the mouse and have touch events.
To properly use the mouse I needed to set SDL_HINT_TOUCH_MOUSE_EVENTS to 0 when mouse is active. BUT when that is set the touch input device ID is no longer SDL_TOUCH_MOUSEID but something else.
So while I detect the real mouse via “event.motion.which != SDL_TOUCH_MOUSEID” in SDL_MOUSEMOTION, I have to go back to touch input by also using “event.motion.which != SDL_TOUCH_MOUSEID” in SDL_FINGERMOTION. Not ideal, but I can make it work maybe :slight_smile:

My mistake, the ID of fingermotion is NEVER SDL_TOUCH_MOUSEID :slight_smile:

I think there are things that are either buggy in SDL or in our code :slight_smile:

  1. unless I set SDL_HINT_TOUCH_MOUSE_EVENTS to 0 mouse input is at the wrong coordinates (touch input is correct). This is strange IMO as this shouldn’t have an effect.

  2. I cannot differ between mouse and finger input. At least the right button of the mouse is giving me the same values for
    event.tfinger.touchId
    SDL_TOUCH_MOUSEID
    and while event.tfinger.fingerId is different it’s a long number and it changes on each touch or mouse click.

Ok, I filed several issues now. All have in common that a real mouse on iOS in an SDL2 app is somewhat buggy but to be nit-picky, I filed them each on their own.