I think an API that returns the user’s device type (i.e. PC, Xbox, etc.) would be awesome.
2 Likes
Get ready for 666 everybody!! Watch out for Devilblox!
exception while signaling: Debugger can be attached to a script or module script
1 Like
Everyone has been asking for this for years, but we never got it.
This is what I did (requires FastSignal - A consistent signal library):
--< Services >--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
--< Assets >--
local Modules = ReplicatedStorage.Modules
local Components = Modules.Components
--< Components >--
local Signal = require(Components.FastSignal)
--< Constants >--
local COMPUTER_INPUTS = {
Enum.UserInputType.MouseButton1,
Enum.UserInputType.MouseButton2,
Enum.UserInputType.MouseButton3,
Enum.UserInputType.MouseWheel,
Enum.UserInputType.MouseMovement,
Enum.UserInputType.Keyboard
}
local GAMEPAD_INPUTS = {
Enum.UserInputType.Gamepad1,
Enum.UserInputType.Gamepad2,
Enum.UserInputType.Gamepad3,
Enum.UserInputType.Gamepad4,
Enum.UserInputType.Gamepad5,
Enum.UserInputType.Gamepad6,
Enum.UserInputType.Gamepad7,
Enum.UserInputType.Gamepad8
}
local TOUCH_INPUTS = {
Enum.UserInputType.Touch,
Enum.UserInputType.Gyro,
Enum.UserInputType.Accelerometer
}
--< Controller >--
local Controller = {}
Controller.Computer = false :: boolean
Controller.ComputerChanged = Signal.new() :: Signal.ScriptSignal<boolean>
Controller.Console = false :: boolean
Controller.ConsoleChanged = Signal.new() :: Signal.ScriptSignal<boolean>
Controller.Mobile = false :: boolean
Controller.MobileChanged = Signal.new() :: Signal.ScriptSignal<boolean>
function Controller.Start()
UserInputService.LastInputTypeChanged:Connect(Controller.LastInputTypeChanged)
Controller.LastInputTypeChanged(UserInputService:GetLastInputType())
UserInputService.InputChanged:Connect(function(Input)
Controller.LastInputTypeChanged(Input.UserInputType)
end)
UserInputService.InputBegan:Connect(function(Input)
Controller.LastInputTypeChanged(Input.UserInputType)
end)
UserInputService.InputEnded:Connect(function(Input)
Controller.LastInputTypeChanged(Input.UserInputType)
end)
end
function Controller.LastInputTypeChanged(Input: Enum.UserInputType)
local OnComputer = table.find(COMPUTER_INPUTS, Input) ~= nil
local OnConsole = table.find(GAMEPAD_INPUTS, Input) ~= nil
local OnMobile =
table.find(TOUCH_INPUTS, Input) ~= nil
and UserInputService.TouchEnabled
and not OnComputer
and not OnConsole
if Controller.Computer ~= OnComputer then
Controller.Computer = OnComputer
end
Controller.ComputerChanged:Fire(OnComputer)
if Controller.Console ~= OnConsole then
Controller.Console = OnConsole
end
Controller.ConsoleChanged:Fire(OnConsole)
if Controller.Mobile ~= OnMobile then
Controller.Mobile = OnMobile
end
Controller.MobileChanged:Fire(OnMobile)
end
return Controller
1 Like
Yeah, it’s a really hacky implementation. I wish there was a built-in API, but I guess this will suffice for now.