Determining Preferred Input Method: Modernized

Many roblox games today determine the method of input for UI applications using UserInputService.TouchEnabled. On the surface, it seems correct: it is true that most devices for which this value is true are mobile, but it is not complete. Consider an edge case: a player with a hyrbid device, for instance, a laptop with touchscreen, will be incorrectly labelled as mobile if TouchEnabled alone is used.

I write this today because my primary device is a laptop with touchscreen, and though it is true that I can (and often do) temporarily disable my touchscreen to circumvent the issues with TouchEnabled loading mobile UI, it is impractical and frankly tedious. Our job as developers is to consider the quality of life of all players, and though the hyrbid device community is small, we exist, and we play your games.

Roblox offers a modern, easy to implement method for reliably determining preferred input. It is UserInputService.PreferredInput, and should be used in place of outdated TouchEnabled checks.

Let’s take a look at some code samples:

What NOT to do:

local UserInputService = game:GetService("UserInputService")
local function isMobile()
 if UserInputService.TouchEnabled then
  return true
 end
 return false
end
isMobile()

What TO do:

local UserInputService = game:GetService("UserInputService")
local preferredInput: Enum.PreferredInput = UserInputService.PreferredInput
warn("INPUT TYPE:", preferredInput)

Here are the results from in-studio emulations that demonstrate that this works for correctly determining the preferred input method of hybrid devices. My touchscreen was enabled during this test:

Using my regular laptop with no device emulation. Touchscreen was enabled.
image

Using in-studio mobile device emulator
image

Using in-studio gamepad device emulator

As you can see, this approach is very simple, and would extend the reach and quality of your game. I apologize if the tone of this forum post comes off as hostile, but it becomes frustrating when something like this is ignored by developers for this long.

Have a great day, and if you have questions, comments, or concerns, please leave them below!

1 Like