Is there any way at all to detect when a user is typing on a mobile device?
I’m working on a system where every time a player types a character in the chat bar, it plays a typewriter sound. This system is working flawlessly on desktop however I’m struggling to get it to work on mobile. I looked through documentations and found no way of detecting when a player is using their mobile keyboard.
I noticed during my testing that the event UserInputService.TouchStarted
does not fire when the player is using the keyboard. This is preventing me to gauge if the player is touching the screen while ChatInputBarConfiguration.IsFocused
is true
.
This is what the intended result should be:
-- Desktop detection
UserInputService.InputBegan:Connect(function(input, gameProcessed)
local keyCode, inputType = input.KeyCode, input.UserInputType
if inputType == Enum.UserInputType.Keyboard then
if gameProcessed and chatConfig.IsFocused then
if not typing then
-- Ensure the key has a character input to avoid misleading key presses
if table.find(blacklistedKeys, keyCode) == nil then
typing = true
RemoteEvent:FireServer(true) -- Communicate input has started to the server
end
end
-- Play type writer sound
local newSound = Replicators.KeystrokeSound(false)
newSound.Parent = SoundService
newSound.Volume *= 0.25
newSound:Play()
if table.find(blacklistedKeys, keyCode) == nil then
keystroke:FireServer(keyCode == Enum.KeyCode.Space) -- Communicate key input to the server
lastKeyPressTime = tick()
end
end
end
end)