CaptureFocus in InputBegan handler is causing the TextBox.Text to also equal the key that was pressed on

game:GetService("UserInputService").InputBegan:Connect(function(input, GPE)
	if GPE then return end
	
	if input.KeyCode == Enum.KeyCode.Slash or input.KeyCode == Enum.KeyCode.T then
		Box:CaptureFocus()
	end
end)

Pressing the slash or T puts a / or T into the text box.

Same problem occurs here, however solution wouldn’t work in my case as using InputService (don’t particularly wanna change)

1 Like

As a workaround (if you need this working right now), you could wait until the next frame before capturing focus, so that the input event doesn’t influence the textbox contents anymore.

i.e.:

game:GetService("UserInputService").InputBegan:Connect(function(input, GPE)
	if GPE then return end
	
	if input.KeyCode == Enum.KeyCode.Slash or input.KeyCode == Enum.KeyCode.T then
+		game:GetService("RunService").RenderStepped:Wait()
		Box:CaptureFocus()
	end
end)
13 Likes

Hi! Thanks for reporting this. Unfortunately, we don’t have a good ETA on when this will be fixed. We have some larger changes in mind that will fix this, but I don’t know when they’ll happen due to their complexity. For the foreseeable future, you can either:

  • Wait a frame as @buildthomas suggested.
  • Listen to InputEnded instead of InputBegan.

Sorry for the inconvenience!

4 Likes