UserInputService.InputBegan fires as I'm typing on a TextBox, and gameProcessed is false

This is an example of one of the TextBoxes inflicted with this bug.

image
image

Title explains it all basically.

Literally, code:


game:GetService'UserInputService'.InputBegan:connect(function(Input, gameProcessed)
	if Input.UserInputType == Enum.UserInputType.Keyboard and not gameProcessed then
         ......
    end
end

However, there are like 8-10 TextBoxes across all the GUI, I don’t want to write actual Focused cases for ALL
individual ones for them. I don’t know what property or something I have to do in order for InputBegan keys to not fire while I’m typing on a TextBox.

3 Likes

I think there’s a way for you to specifically direct it to just one TextBox.
TextBox:GetPropertyChangedSignal(“Text”):Connect(function()
// code here
end)

That’s odd, have you tried using ContextActionService instead? It automatically handles things like GameProcessed, so it may fix your issue.

http://wiki-origin.roblox.com/index.php?title=API:Class/UserInputService/GetFocusedTextBox

This method can be used to determine whether the user has a textbox selected that they’re typing in, and if so disregard the fired input for further processing.

Well yeah, of course it’s going to fire. UserInputService.InputBegan is an event that fires when input is made. You’re checking for the keyboard UserInputType, meaning any keyboard interaction that isn’t internally preoccupied will fire.

You’ll want to use a TextBox-specific method or Instance::GetPropertyChangedSignal on the text box.

Actually, over that, you don’t even have to go as far as UserInputService. GuiObjects have their own mini-UIS events, such as GuiObject.InputBegan.

1 Like

UserInputService has two events UserInputService/TextBoxFocused and UserInputService/TextBoxReleased

Maybe hook them up to specific events with a boolean

Example:

local UserInputService = game:GetService("UserInputService")
local TEXTBOX_FOCUSED = false

UserInputService.TextBoxFocused:Connect(function(textBox)
   TEXTBOX_FOCUSED = true
end)

UserInputService.TextBoxFocusReleased:Connect(function(textBox)
   TEXTBOX_FOCUSED = false
end)

UserInputService.InputBegan:Connect(function(Input, game processed)
   if Input.UserInputType == Enum.UserInputType.Keyboard and not gameProcessed and not TEXTBOX_FOCUSED then
      --sample code here
   end
end)
2 Likes

I noticed in the picture of the properties for the affected text box you uploaded that the class name is ‘TextLabel’. Are all the afflicted text boxes like this? It may be a custom text box implementation.

Whoops, wrong object (I’ll change it)

1 Like