How do I know when I player is typing in chat?

I’m making something where I check what movement keys a player has down to determine what to do. The problem is UserInputService.InputBegan fires even if the player is typing in chat. How do I differentiate between when the player is typing in chat vs moving around?

4 Likes

The second parameter in InputBegan is GameProcessedEvent if this is true that means the player has done something that is observed by Roblox, such as chatting.

Here’s how to use it:

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, gpe)
     if gpe then return end
     print("Your stuff")
end)
2 Likes

I tried this and it works for every key except shift for some reason. Shift gpe is always true for some reason. How do I get around this?

Try this:

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, gpe)
     if gpe and input.KeyCode ~= Enum.KeyCode.LeftShift and input.KeyCode ~= Enum.KeyCode.RightShift then return end
     print("Your stuff")
end)

the problem isn’t that my thing is firing because I’m pressing left shift. The problem is that I want something to happen when I press left shift but only when I’m not typing in chat

Ok, I thought that would work but now that I think of it it probably won’t. Sadly I won’t be of use to you as of now since I don’t have my computer.

oh ok. Thanks for trying tho. I’ll try to figure this out on my own now

Use
if UserInputService:GetFocusedTextBox() == nil then
to check if player is not typing in a textbox

1 Like

That’s interesting. But what if a player types something and then clicks out leaving the message still in the box. Will it still work?

Yes because technically they are not focused on the text box anymore

interesting. Thanks guys. Ill try it now

1 Like

You should use ChatService, since there’s a function that specifically detects when someone is typing in the chatbar. :GetFocusedTextBox is inaccurate because the event also fires when a person is typing inside a textbox too.

This is the event I’m referring to:
image

1 Like

wait how do I reference the chatbox with this? I tried the service “chat” but it gave me an error

Did you use ChatService I’ll see if I can get an example

yeah it says that isnt a thing

Chat and ChatService are 2 different things.

Use this to define ChatService:

local ServerScriptService = game:GetService("ServerScriptService")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner").ChatService)

ohhhhhh thank you. that makes more sense

1 Like

No problem.

And here’s a sample script that detects when a player is typing:

local ServerScriptService = game:GetService("ServerScriptService")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner").ChatService)

if ChatService:IsFocused() then
     print("Player is typing")
end
3 Likes

hold on its not returning anything. Can this be used in a local script?

ChatService can’t be used in a Local Script, no.