Detecting touch device (hide mouse cursor)

Started by cat, Fri 16/08/2019 09:53:32

Previous topic - Next topic

cat

Hi!

The game I'm currently working on is intended to be played either on PC or on phone/tablet. It is running nicely on my phone when I copy it to my AGS folder and start it from the AGS app. However, I don't want to show the mouse cursor when running on a touch device.

Is is possible to detect if the game is running on a touch device? Or do I have to provide a second game pack for mobile? Are there compiler switches I can use in combination with ifdev so I don't have to change the code every time I want to build for the other platform?
Or is it best/easiest to build a real apk for my game?

eri0o

You can use System.OperatingSystem'

https://adventuregamestudio.github.io/ags-manual/System.html#operatingsystem

Code: ags

if (System.OperatingSystem == eOSAndroid || System.OperatingSystem == eOSiOS) {
  Display("Running on mobile!");
}
else {
  Display("probably desktop!");
}


I find it easier for testing doing this check only once on game_start and setting a boolean global variable. This allow you being able to change this variable to other value to test something for mobile platform from your computer.

Mouse cursor can then be hidden using mouse.Visible.

https://adventuregamestudio.github.io/ags-manual/Mouse.html?highlight=Mouse#visible

cat

Quote from: eri0o on Fri 16/08/2019 10:14:57
You can use System.OperatingSystem

Very nice! I didn't know this existed. I searched the manual for touch but didn't find anything, of course.

Thanks!

cat

Digging up an old thread - is it possible to figure out if the web build of the game is running on a PC or a touch device?

Crimson Wizard

Quote from: cat on Wed 26/02/2025 20:55:13Digging up an old thread - is it possible to figure out if the web build of the game is running on a PC or a touch device?

Not possible using AGS own script.

cat


cat

I had an idea. It should actually be possible to detect from the mouse movement if it is a touch device. For example, on a touch device, the mouse coordinate will usually jump from one place to another. Of course, jumping can also happen when leaving the window and re-entering at a different position. Also Wacom tablets can have some jumping.
However, on touch devices, when moving the mouse in a continuous way, it must always be with mouse down. So as soon as the mouse coordinate changes without mouse down, it must be a non-touch device.

Has someone tried this already? Any other caveats you can think of? I think I will try to make a POC module for this.

Snarky

That is clever, but if your UI changes depending on touch/mouse platform I would just make it a setting that you can change on startup.

heltenjon

Quote from: cat on Thu 27/02/2025 08:58:07Any other caveats you can think of?

Playing on a laptop with mouse, touchscreen and mousepad all active. (Like the one I'm using now.)

cat

Quote from: Snarky on Thu 27/02/2025 09:08:32That is clever, but if your UI changes depending on touch/mouse platform I would just make it a setting that you can change on startup.
I really don't want to ask the user if they want to show a mouse cursor before they start playing.

Quote from: heltenjon on Thu 27/02/2025 09:13:05Playing on a laptop with mouse, touchscreen and mousepad all active. (Like the one I'm using now.)
The question is: Which of those are you actually using? Would you expect to see a mouse cursor or not?

Crimson Wizard

#10
There was this feature suggestion open:
https://github.com/adventuregamestudio/ags/issues/2682

If someone could specify the list of information that is usually required, maybe we could come up with something in the future versions.

Quote from: cat on Thu 27/02/2025 08:58:07However, on touch devices, when moving the mouse in a continuous way, it must always be with mouse down. So as soon as the mouse coordinate changes without mouse down, it must be a non-touch device.

I think mouse coordinate changes without mouse down also happens with touch-to-mouse emulation, which is enabled by default on mobile devices, but also may be enabled on any other platform.

Quote from: cat on Thu 27/02/2025 09:20:25I really don't want to ask the user if they want to show a mouse cursor before they start playing.

Why not? That's not perfect, but seems like an acceptable trade off in the lack of a proper detection functionality.

cat

Quote from: Crimson Wizard on Thu 27/02/2025 09:25:13I think mouse coordinate changes without mouse down also happens with touch-to-mouse emulation, which is enabled by default on mobile devices, but also may be enabled on any other platform.

I'm not familiar with this and a quick google search didn't help me either. What does this do?

Crimson Wizard

Quote from: cat on Thu 27/02/2025 09:44:14I'm not familiar with this and a quick google search didn't help me either. What does this do?

I did not express this clearly, it's not a device feature but an AGS feature.
This is how it's configured:
https://adventuregamestudio.github.io/ags-manual/DefaultSetup.html#touch

And in config file:
Quote[touch] - touch input options
 - emul_mouse_mode = [string | integer] - touch-to-mouse emulation (whether touch input should emulate the mouse input and how):
   -- off (0) - disabled;
   -- one_finger (1) - one finger maps directly to left click;
   -- two_fingers (2) - tap 1 finger for left click, hold 1st finger and tap 2nd for right click, double tap 1 finger for drag mode.
 - emul_mouse_relative = [0; 1] - enable or disable relative emulated mouse movement.

Snarky

Quote from: Crimson Wizard on Thu 27/02/2025 09:25:13I think mouse coordinate changes without mouse down also happens with touch-to-mouse emulation, which is enabled by default on mobile devices, but also may be enabled on any other platform.

You say it's enabled by default on mobile devices. Can a game be set to not enable it? I mean, it's meant to help control games that are designed for cursor-based interaction; if your game instead adapts to a touch-based UI, you probably don't want this.

Crimson Wizard

Quote from: Snarky on Thu 27/02/2025 10:59:51You say it's enabled by default on mobile devices. Can a game be set to not enable it? I mean, it's meant to help control games that are designed for cursor-based interaction; if your game instead adapts to a touch-based UI, you probably don't want this.

It's enabled by default in configs produced for mobile ports. But it's possible to turn it off in config.

AGS does not have touch api, we are only getting to make one (there are couple draft prs in our repository).
Until it's done, there's no way to make touch-based ui without this emulation, or some plugin.

cat

Ok, so I tried to check for big distances between the coordinates in rep_exec_always but this is not enough. Quick mouse movements also make it look like jumping from one coordinate to another.
Some things I found that will very clearly indicate a non-touch environment are usage of mouse wheel and middle button as well as moving the mouse while the button is not pressed. However, I haven't found a clear indication that it IS a touch device. Maybe waiting for, say, the first two clicks and checking that the mouse was not moved without mouse down in between is enough?

SMF spam blocked by CleanTalk