Plugin widget TextBox:CaptureFocus not working as expected

I’m trying to make a command bar plugin that allows the user to quickly execute Lua code just like the built-in Command Bar.

image

The difference is that I want to be able to bring the bar up with a keyboard shortcut, and especially to focus it with a keyboard shortcut. Otherwise the user has to use the mouse to click the command bar manually, which slows things way down for power users.

I’m using TextBox:CaptureFocus to do this, but it’s not working as expected.

image

It appears to focus the TextBox, but it only actually does that if the 3D viewport is “focused” by clicking in it. Clicking in any other widget causes it to send keyboard inputs to that widget instead of the TextBox that should be focused. E.g. if a script window is focused, typed text goes into the script instead of the TextBox.

Does anyone know of a way to make TextBoxes properly capture focus?

6 Likes