CaptureFocus() Creates a Space in TextBox when Called

Hello, I have been trying to fix this bug for a while now. I am making a custom Admin Command Prompt. Whenever I call CaptureFocus() for a TextBox, it creates a space inside the called TextBox. This not only makes my UI look bad, but it makes the commands unable to be called (unless the player presses backspace and removes the space, or unless I were to allow commands with a space in the front). Everything I have tried does not remove the space.

I have tried all of the following:

String.sub
Re-Defining the string ex: TextBox.Text = ""
Enabling ClearTextOnFocus

The conclusion that I have come up with, is that this is a Studio Bug. Still, I am not quite sure.

This post is extremely similar to the one below, but the conclusion drawn in that post was leaving the space, and moving the CursorPosition.

Any help on removing this pesky space would be greatly appreciated.

2 Likes

Hey !

I have actually found a solution for my problem. To access my chat, i was using a keydown event which was, for some mysterious reason, actually causing this bug. I switched to keyup and the bug disappeared. I found a post about this but can’t seem to find it back :confused:

Could this solve your problem ?

PS : I found it CaptureFocus in InputBegan handler is causing the TextBox.Text to also equal the key that was pressed on - #2 by buildthomas

2 Likes

Well, unless I could circumvent the action of FocusLost when the player presses Enter, I couldn’t really create a keydownevent for the enter key. Because pressing enter inside of a textbox causes the focus to be lost in the first place, how would I be able to have a keydown event for the same key? Hope that made sense.

But, to add onto this, a reply within that post poses a very good solution. @buildthomas mentions that you can wait until the next frame before capturing focus, so that the input doesn’t influence the contents of the activated textbox.