Getting number of mouse devices


I'm working on a portable cross-platform GUI button, and I want to detect if it's being pressed. I know I can use device_mouse_check_button to check if a certain mouse device is being pressed. But in order to detect if any mouse is currently being pressed in the button, I need to loop through every mouse device. This would be a simple for loop, except for one thing: in the documentation for Device Input, there's little to no information about how I would find how many mouse devices there are. Though it does reference 2-3 mouse devices on "low end Android devices", and up to 10 mouse devices on UWP devices, it does not give me an upper bound on how many mouse devices there may be, nor any programmatic way to find the number of mouse devices.

Is there a function that returns the number of mouse devices?

Barring that, is there a maximum number of mouse devices that I need to support? Will it be sufficient to check 100 mouse devices? 32? 10?


If you need to write your own multitouch system, you can just set a max. A google search seems to indicate that 10 is the max most devices support and as a matter of practice it is hard to see how more than ten would be useful. I'm not even sure ten would be useful in most cases. Practically it seems highly unlikely that you would have more than 2-3 unless your game was designed to make people use a lot.


After an hour of research to answer my own question, I've made a small table.

Operating SystemNumber of touches
iOS17 (rather shoddy reference)
Fire2 (Wikipedia reference)
*Viewsonic seems to sell touchscreens with up to 20 touch points, usable on Windows computers.
**It seems possible to use xinput to create an unbounded number of mouse cursors. However, in most cases, multiple mouse inputs is caused by a touchscreen, which means it's usually limited to the number of touch inputs the touchscreen can have, of which 20 seems to be a reasonable maximum.
***Android actually has an API call that can be used to detect the number of current active touch points (in MotionEvent), and provides a second API that can distinguish between devices with at least 1 touch input, at least 2 touch inputs, and at least 5 touch inputs.

iOS (in Swift)
let touchCount = event?.touches(for: self)?.count
Android: See MotionEvent#GetPointerCount

Windows: GetSystemMetrics(SM_MAXIMUMTOUCHES)

Obviously, it's within the realm of possibility for YoYo to make a function that gets an upper bound on the number of active touch points/mouse cursors. I'll go make a feature request. Sorry, I'm currently sleep-deprived and may not be at optimum politeness. I mean to say, "it appears plausible that creating a function to get an upper bound on the number of active touch points/mouse cursors is possible, and that YoYo might be interested in creating such a function. I'll make a feature request."
Last edited: