I’m using UIS.LastInputTypeChanged event to detect if a user is on mobile or laptop for some reason it works when I use the mobile screen on my roblox studio however when I tried playing the game on my phone it didn’t work at all.
InputController.Type = nil
InputController.TouchTable = {
Enum.UserInputType.Touch,
Enum.UserInputType.Accelerometer,
Enum.UserInputType.Gyro
}
InputController.KeyboardTable = {
Enum.UserInputType.MouseButton1,
Enum.UserInputType.MouseButton2,
Enum.UserInputType.MouseButton3,
Enum.UserInputType.Keyboard,
Enum.UserInputType.MouseMovement,
Enum.UserInputType.MouseWheel
}
--Main
function InputController:CreateInput(Func, Key)
local UtilityController = Knit.GetController("UtilityController")
UtilityController:Wrap(function()
repeat
task.wait()
until self.Type ~= nil--Pause until InputType is determined
if self.Type == Enum.UserInputType.Touch then
print("Mobile")
UIS.TouchTap:Connect(function(TapPos, GameProcessedEvent)
if GameProcessedEvent then return end
Func()
end)
else
print("Laptop")
UIS.InputBegan:Connect(function(Input, GameProcessedEvent)
if GameProcessedEvent then return end
if Input.KeyCode == Key or Input.UserInputType == Key then
Func()
end
end)
end
end)
end
function InputController:KnitInit()
print("InputController Initialized")
end
function InputController:KnitStart()
UIS.LastInputTypeChanged:Connect(function(LastInputType)
if table.find(self.TouchTable, LastInputType) and table.find(self.TouchTable, self.Type) == nil then
self.Type = Enum.UserInputType.Touch
elseif table.find(self.KeyboardTable, LastInputType) and table.find(self.KeyboardTable, self.Type) == nil then
self.Type = Enum.UserInputType.Keyboard
end
end)
end