I want to determine if the device currently in use is a touch screen

Godot Version

v4.3.stable.steam [77dcf97d8]

Question

I want to determine if the device currently in use is a touch screen device in my script to perform some business operations. How can I achieve this? My node is just a regular Node2D node. I tried using the InputEventScreenTouch event to implement it, but that requires a click to determine. I hope to know whether it’s a touch screen device as soon as the game starts.

Try this:

if OS.get_model_name() == "GenericDevice":
   print("This device does not support touch screen")
else:
   print("This device support touch screen")
1 Like

@KingGD
How reliable would you say that was? Does it rely on a list of device types somewhere?

I always thought this would be impossible to get right 100% of the time and just giving the user a choice of controls type was a better option.

1 Like

This might be better (cannot find GenericDevice in the docs, I think this is when a device is not recognized).

if OS.get_name() == "Android" or OS.get_name() == "iOS":
    print("Touch screen likely supported")
else:
    print("Touch screen not likely supported")

PS Still think it is better just to ask or get the user to indicate a preference.

PPS You could do a big button and say “Click or touch here to continue”. Then detect both clicks and touches. Then you would know for sure it is a touch screen if they touch. If they click it could still ‘possibly’ be or not.

1 Like

You could use

DisplayServer.is_touchscreen_available()

It only works for Android / iOS tho

Returns true if touch events are available (Android or iOS), the capability is detected on the Web platform or if ProjectSettings.input_devices/pointing/emulate_touch_from_mouse is true.

2 Likes

You misterunderstood my codes, I used OS.get_model_name() that returns only android or ios model name else generic device like pc, etc, you can find this in OS docs. Your codes is long and as well as same.

2 Likes

@KingGD

Yes you are right, I found it on a second look:

2 Likes