Detecting multi-touch, mouse, and/or keyboard (or gamepad)

Hello,

Is there a way to programmatically detect whether or not the system my game is running on is using multi-touch or a mouse? Or, whether or not a keyboard is plugged in?

I understand I can get the OS with: sys.get_sys_info().system_name

In the case that the system_name is HTML5, I would like to run the application differently on tablets and desktop browsers.

For example, a twin stick shooter might use two virtual-analog sticks on a tablet, but on a desktop I would want to use WASD / Mouse.

If I can detect the presence of a keyboard or mouse, I could run the application in “Desktop” mode.

Taking it one step further: if it’s on a tablet OR desktop with a gamepad, I would prefer to use the gamepad twin-stick controls.

Thanks!

It’s tricky with the hybrid computers/tablets.

When I made Fast Food Rampage, a shooter, I switched to twin stick on screen controls if a touch was detected, and mouse + keyboard if a mouse hover or key were detected.

That worked well, because the game had menus before the game started, so by the time they got to the game one of the methods had already been chosen.

5 Likes

Great solution, I’ll give that a shot. Thanks!

1 Like

You could also go with this solution. Worked for me.

1 Like

So, this works well for you? I’ve read up a bit on this and didn’t dare going this way, having read threads like these for instance: javascript - Detecting a mobile browser - Stack Overflow. So, I use the same solution as @totebo does to switch mobile controls on/off in my html app.

It worked fine, though it wouldn’t be a big deal if it misidentified the device. I did want the information before any kind of input from the user, though.

There’s a different text right at the beginning (“tap to continue” vs. “click to continue”), different button behaviour for touchscreen (triggered on press vs. on release with mouse) and I replaced a fake fingerprint scanner with a fake retina scanner for the desktop version. None of these were too important, just nice to have.

1 Like

Ah, good to know it worked, too. Thank you!

Yes, that is the downside of the solution that needs to wait for the first input.

Fancy stuff :slightly_smiling_face:

1 Like