I caution thinking of it in that way. There are laptops and screen that are touchscreen, like Chromebook. People can connect a controller via Bluetooth to mobile devices. And, you can connect a mouse or keyboard to via USB or Bluetooth to various devices.
You should always go with the last InputType for good UX. For my game, I assume the player is using a Keyboard, then update everything (UI) as soon as the player presses any other input type.
Could I ask why you want to assume the player is on a personal computer opposed to a console or phone?
im trying to make a script that can detect your device
local UIS = game:GetService("UserInputService")
-- PC --
if UIS.MouseEnabled == true and UIS.KeyboardEnabled == true then
local BoolValue = Instance.new("BoolValue")
BoolValue.Name = "IsPC"
BoolValue.Parent = game.ReplicatedStorage
print("PC")
end
-- MOBILE / TABLET --
if UIS.MouseEnabled == false and UIS.KeyboardEnabled == false and UIS.GamepadEnabled == false and UIS.TouchEnabled == true then
local BoolValue = Instance.new("BoolValue")
BoolValue.Name = "IsMobile"
BoolValue.Parent = game.ReplicatedStorage
print("Mobile")
end
-- CONSOLE --
if UIS.MouseEnabled == false and UIS.KeyboardEnabled == false and UIS.TouchEnabled == false and UIS.GamepadEnabled == true then
local BoolValue = Instance.new("BoolValue")
BoolValue.Name = "IsConsole"
BoolValue.Parent = game.ReplicatedStorage
print("Console")
end
Here’s a modified version of what I’m using in my current project:
Open dropdown (click)
local UserInputService = game:GetService("UserInputService")
local UserInputTypeSystemModule = {
gamepadTypeFromNewestInput = "none",
inputTypeThePlayerIsUsing = "KeyboardAndMouse", --keyboard mouse is default
gamepadType = "none", -- "none" by default. Can be "Xbox" or "PlayStation"
}
local mouseInputType = {
Enum.UserInputType.MouseButton1,
Enum.UserInputType.MouseButton2,
Enum.UserInputType.MouseButton3,
Enum.UserInputType.MouseMovement,
Enum.UserInputType.MouseWheel
}
local GamepadInputsList = {
Enum.KeyCode.ButtonA,
Enum.KeyCode.ButtonB,
Enum.KeyCode.ButtonX,
Enum.KeyCode.ButtonY,
Enum.KeyCode.ButtonL1,
Enum.KeyCode.ButtonL2,
Enum.KeyCode.ButtonL3,
Enum.KeyCode.ButtonR1,
Enum.KeyCode.ButtonR2,
Enum.KeyCode.ButtonR3,
Enum.KeyCode.ButtonStart,
Enum.KeyCode.ButtonSelect,
--
Enum.KeyCode.DPadUp,
Enum.KeyCode.DPadDown,
Enum.KeyCode.DPadLeft,
Enum.KeyCode.DPadRight,
Enum.KeyCode.Thumbstick1,
Enum.KeyCode.Thumbstick2,
}
local mobileInputType = Enum.UserInputType.Touch
---
local Xbox_ReturnValues_List = {
"ButtonA", -- KeyCode.ButtonA
"ButtonB", -- KeyCode.ButtonB
"ButtonX", -- KeyCode.ButtonX
"ButtonY", -- KeyCode.ButtonY
"ButtonLB", -- KeyCode.ButtonL1
"ButtonLT", -- KeyCode.ButtonL2
"ButtonLS", -- KeyCode.ButtonL3
"ButtonRB", -- KeyCode.ButtonR1
"ButtonRT", -- KeyCode.ButtonR2
"ButtonRS", -- KeyCode.ButtonR3
"ButtonStart", -- KeyCode.ButtonStart
"ButtonSelect", -- KeyCode.ButtonSelect
}
local PlayStation_ReturnValues_List = {
"ButtonCross", -- KeyCode.ButtonA
"ButtonCircle", -- KeyCode.ButtonB
"ButtonSquare", -- KeyCode.ButtonX
"ButtonTriangle", -- KeyCode.ButtonY
"ButtonL1", -- KeyCode.ButtonL1
"ButtonL2", -- KeyCode.ButtonL2
"ButtonL3", -- KeyCode.ButtonL3
"ButtonR1", -- KeyCode.ButtonR1
"ButtonR2", -- KeyCode.ButtonR2
"ButtonR3", -- KeyCode.ButtonR3
"ButtonOptions", -- KeyCode.ButtonStart
"ButtonTouchpad", -- KeyCode.ButtonSelect
"ButtonShare", -- KeyCode.ButtonSelect
}
-- Note: Directional inputs have the same return value. This means, if a player presses a d-pad input, then the code knows it's a gamepad, but it doesn't know what type of gamepad.
---
UserInputService.InputBegan:Connect(function(input)
--print(input.KeyCode)
-- Keyboard & Mouse Input: --
if input.UserInputType == Enum.UserInputType.Keyboard then -- Keyboard inputs --
if UserInputTypeSystemModule.inputTypeThePlayerIsUsing == "Gamepad" or UserInputTypeSystemModule.inputTypeThePlayerIsUsing == "Touch" then
print("New InputType detected: Keyboard and Mouse")
UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "KeyboardAndMouse"
UserInputService.MouseIconEnabled = true
return
end
end
for i, mouseInputs in pairs (mouseInputType) do -- Mouse inputs --
if input.UserInputType == mouseInputs then
if UserInputTypeSystemModule.inputTypeThePlayerIsUsing ~= "KeyboardAndMouse" then
print("New InputType detected: Keyboard and Mouse")
UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "KeyboardAndMouse"
UserInputService.MouseIconEnabled = true
return
end
end
end
----
-- Gamepad Input: --
for i, gamepadInput in pairs (GamepadInputsList) do -- Controller button inputs --
if input.KeyCode == gamepadInput then
if UserInputTypeSystemModule.inputTypeThePlayerIsUsing ~= "Gamepad" then
print("New InputType detected: Gamepad")
UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "Gamepad"
UserInputService.MouseIconEnabled = false
end
local stringForKeyCodePressed = UserInputService:GetStringForKeyCode(gamepadInput)
for i, retunValue_Xbox in pairs(Xbox_ReturnValues_List) do
if retunValue_Xbox == stringForKeyCodePressed then
--print(retunValue_Xbox,stringForKeyCodePressed)
UserInputTypeSystemModule.gamepadTypeFromNewestInput = "Xbox"
end
end
for i, returnValue_PlayStation in pairs(PlayStation_ReturnValues_List) do
if returnValue_PlayStation == stringForKeyCodePressed then
--print(returnValue_PlayStation,stringForKeyCodePressed)
UserInputTypeSystemModule.gamepadTypeFromNewestInput = "PlayStation"
end
end
if UserInputTypeSystemModule.gamepadTypeFromNewestInput ~= UserInputTypeSystemModule.gamepadType then
-- player is now using a different type of gamepad than before
UserInputTypeSystemModule.gamepadType = UserInputTypeSystemModule.gamepadTypeFromNewestInput
print(UserInputTypeSystemModule.gamepadType)
end
end
end
----
-- Touchscreen input: --
if input.UserInputType == Enum.UserInputType.Touch then
if UserInputTypeSystemModule.inputTypeThePlayerIsUsing ~= "Touch" then -- if not mobile/touch input already, make it.
UserInputTypeSystemModule.gamepadTypeFromNewestInput = "none"
print("New InputType detected: Touch")
UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "Touch"
return
end
end
----
end)
return UserInputTypeSystemModule
Note that there is nothing here about a specific device. There is only stuff about Xbox Controllers, PlayStation Controllers, Touch-input, and Keyboard/Mouse input.
Key takeaway: Never assume inputType = deviceType.
Why would knowing the device matter?
Is it for UI screen size purposes? I assume that’s why anyone would want to check the device. But, that’s a bad way to go about that as Roblox has ways to change the size of UI along with things related to that.