Any way to make UserInput only detect a keyboard and not mouse as well?

Title says it.

This is my code:

game.ReplicatedStorage.ChatEDANCE:FireServer(senderp)
		
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(inputObject)
	game.ReplicatedStorage.ChatEDANCEstop:FireServer(senderp)
end)

Yep

also will it work on mobile? if not, its not a huge deal but i would like it

Try this to detect inputs. It works perfectly for computers, but I also checked for movement so that it can deal with mobile as best as I can think of, since Enum.UserInputType.Keyboard doesn’t detect any keyboard use on mobile devices. (Read PS below for more important info)

local UserInputService = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local EmoteStopped = true

local function stopEmote()
	game.ReplicatedStorage.ChatEDANCEstop:FireServer(senderp)
end

game.ReplicatedStorage.ChatEDANCE:FireServer(senderp)

UserInputService.InputBegan:Connect(function(inputObject)
	if inputObject.UserInputType == Enum.UserInputType.Keyboard then
		stopEmote()
	end
	
	Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
		if Humanoid.MoveDirection.Magnitude > 0 then
			if EmoteStopped == false then
				EmoteStopped = true
				
				stopEmote()
			end
		elseif Humanoid.MoveDirection.Magnitude == 0 then
			if EmoteStopped == true then
				EmoteStopped = false
			end
		end
	end)
	
	Humanoid.StateChanged:Connect(function()
		if Humanoid:GetState() == Enum.HumanoidStateType.Jumping then
			if EmoteStopped == false then
				EmoteStopped = true
				
				stopEmote()
			end
		else
			if EmoteStopped == true then
				EmoteStopped = false
			end
		end
	end)
end)

PS: I only tested mobile devices in Roblox Studio in the “TEST” tab, so I’m not exactly sure if they can detect any inputs from a keyboard, since Roblox studio used a keyboard that didn’t actually type anything when keys were pressed.

This does work on mobile as well! Thank you : - )

Since mobile doesn’t have a keyboard, I checked for movement instead, since their only GUI is a thumbstick and jump button. Hopefully that’s okay!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.