How to detect if a user changes textbox text?

Hello, I’m trying to use UserInputService keybind so that when they press E it pulls up the build menu. The only issue I’m having is that it still triggers even if they are typing text. If you don’t know, E is a vowel which means that it gets pressed a lot in typing. How do I check if they are editting any textbox (including chat) then enable UIS?

Here is my code:

local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		script.Parent.Parent.Visible = not script.Parent.Parent.Visible
	end
end)

Use the second parameter of input began, GameProcessedEvent to know if the input is something a control.

local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, gpe)
    if gpe then return end
	if input.KeyCode == Enum.KeyCode.E then
		script.Parent.Parent.Visible = not script.Parent.Parent.Visible
	end
end)

I know this works for chat, not sure about text boxes, if it doesn’t then let me know

1 Like

Use UserInputService:GetFocusedTextBox

local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, gpe)
	if gpe or UIS:GetFocusedTextBox() ~= nil then return end
	if input.KeyCode == Enum.KeyCode.E then
		script.Parent.Parent.Visible = not script.Parent.Parent.Visible
	end
end)
1 Like
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, gpe)
	if input.KeyCode == Enum.KeyCode.E and gpe == false then
		script.Parent.Parent.Visible = not script.Parent.Parent.Visible
	end
end)

Yup this works for both textboxes and chat. Thanks. (FYI chat uses textboxes not some magic code)

1 Like

Chat and textboxes don’t have a difference. just doing gpe worked.

I’m aware, I just didn’t know if regular (non-chat) text-boxes counted as being “game processed”

1 Like

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