How to tell if a player is typing in the chat?

I have keybinds that I want to disable when the player is typing in the chat. I already have a way how. I just need a way to detect when a player is typing.

15 Likes

Hi there, the second formal parameter of the UserInputService Input... signals (which I’m presuming you’re using) is bound to a bool describing if that input was observed by the game engine (in the context of some UI process or otherwise).


ContextActionService takes care of this for you; I’d recommend using it for keybinds that need to be context-sensitive like this.

6 Likes

The input is done through a local script within the StarterCharacterScripts folder.

2 Likes

This is how you would use the parameter mentioned by @thatsaniceROOT

UserInputService.InputBegan:Connect(function(key,chatting)
	if chatting then return end
end)
10 Likes

you can use the UserInputServiceLike this

local userInputService =game:GetService("UserInputService")

userInputService.InputBegan:Connect(function(input,gameProcessedEvent)
      if not gameProcessedEvent then
         -player is typing
      end
end
37 Likes

To be exact,

(Could also use UserInputService, but this just seems easier)

6 Likes

this is not correct the first parameter is the input object and the second is gameProcessedEvent you can read about it here UserInputService | Documentation - Roblox Creator Hub

1 Like

Yes, I am aware what it is, but for readability and ease of understanding I changed the name. I am not sure why this is a big issue?

1 Like

how is key more readable than input? input is a table object, key sounds more like an index

1 Like

I do not mean key like dictionary key,
I mean key like key pressed.

well thats wrong anyway lol, its not that to check the key you would have to do input.UserInputType, and its not only keys passed, mouse movements, gamepads inputs, and so on can also be passed

I realize, but for this particular use case, OP is asking for keybinds.

2 Likes

I tried both scripts. And both work fine, I guess its all the matter of optimization.

1 Like

I only changed the variable names as said before, for ease of understanding.

1 Like

I think it’s less understandable to use the word key as the parameter for the InputObject than input, so I have to take @RomeoEDD’s side here. He’s not wrong in when he says that it’s

  1. Wrong.
  2. Less readable than input.

Using the variable key gives a wrong impression about what’s actually passed to UserInputService events, which is an object that describes the nature of the input across several levels - state, type, position, so on. Key doesn’t make sense because a key isn’t being passed.

Even if it’s for the sake of simplifying or understanding, key isn’t a simplification equivalent for the InputObject. The proper concept to be teaching individuals when referencing the event is input and it should not be introduced in any other way because that sprouts misconception early on.

Key is more appropriate for the deprecated Mouse.KeyDown or a table indice. Not the InputObject.

2 Likes

The script’s location doesn’t invalidate @thatsaniceROOT’s suggestion. ContextActionService automatically handles input conditions and voids input when something internally is listening to that input type. It’s the same as not processing an event when using UserInputService and seeing if GameProcessedEvent is true, but it does this internally for you.

Would you have to manually set a variable for chat bar or is there a faster way?
example:

for _, bar in pairs(LP.PlayerGui:WaitForChild('Chat'):GetDescendants()) do
    if bar:IsA('TextBox') and bar.Name == 'ChatBar' then
        if bar:IsFocused() then -- not sure how to use the API as ive never seen it before
            -- code here
        end
    end
end
3 Likes