I want to figure out if there is a way so that you can test if a player is typing in chat but did not press enter yet. Any ideas?
I already found another question on this site but, that's from 3 years ago and it doesn't really work. Here it is
game:GetService('UserInputService').TextBoxFocused:connect(function(TextBox) local succ = pcall(function() TextBox:GetFullName() end) if not succ then print('User is typing.') end end) game:GetService('UserInputService').TextBoxFocusReleased:connect(function(TextBox) local succ = pcall(function() TextBox:GetFullName() end) if not succ then print('User quit typing.') end end)
(Credit goes to M39a9am3R, I'm just wondering if someone can figure out to make this work, I have no idea how to possibly make this script work.)
Use UserInputService
s GameProcessed parameter
UserInputService.InputBegan:Connect(function(InoutObject, GameProcessed) if (InputObject.UserInputType = Enum.UserInputType.KeyBoard) then if (GameProcessed) then --// Otherwise known as 'IsTyping' print("Is Typing!") end end end)
Or, you could just say what's below, yet I highly recommend what's above
TextBox.Focused:Connect(function() print("Is Typing!") end) TextBox.FocusLost:Connect(function(Return) --// Parameter that you can restric to if pressed return print("Quit typing") end)
I forgot to mention that GameProcessed binds to anything requirng interaction, Eg. Jumping, GuiButtons, etc, so I added a UserInputType check that narrows things down a bit. (Shout to Incap)
Hope this helps!
Feahren's solution works quite well, but I felt like something was missing, that I felt was too big to fit in a comment.
Game Processed Event is true when the UI was interacted with in general. Clicking on a GUI button will fire InputBegan
, and also cause game processed event to be true. You should also be checking if the user input type is Keyboard
before doing anything else.
UserInputService.InputBegan:Connect(function(input, gpe) if input.UserInputType == Enum.UserInputType.Keyboard then if gpe then -- # extra sure that it wasn't button clicking end end end)
Do not forget to accept Feahren's answer if this helps.