Hi,
I’m working on a plugin that adds parts to the workspace. A part-to-add can be selected in a widget. When a selection is made and the mouse is moved from the widget and over the workspace (main game window), the selected object and a selection box will follow the mouse, but keyboard input (currently for rotation and camera dolly) doesn’t work until the main window gains focus (by clicking it with the mouse).
This can create a few moments of confusion since the mouse inputs work as expected but the keyboard inputs appear to be broken. It’s also a minor hassle to have to click the window to get the keys working. Is there a way to set the focus to the main window when the mouse moves over it or from within the plugin as soon as a selection is made–maybe something similar to TextBox:CaptureFocus()?
Thanks for your thoughts.
I had a look at the plugin API reference, and unfortunately it seems like it isn’t possible
The closest thing I found was: PluginGui.WindowFocused, which only checks if it is focused.
Someone may come along and prove me completely wrong, but my research leads me to believe it is not possible to choose what is focused.
1 Like
That’s where my digging around ended up too. At least I’m not missing something obvious. I appreciate you taking time to look into it.
Well, I tried toggling enable on the plugin to see if it would lose focus, and I also tried creating a textbox in a screengui (att to coregui) and attempted to force-focus to that (before del it). I tried to capture keyboard input while the plugin widget had focus so I might duplicate the needed code there. No luck.
I can’t find a way to capture keypresses while a plugin widget has focus nor set focus (for keyboard input anyway) to the main game window, hacky or otherwise, short of clicking in the window. That’s unfortunate, because the mouse works fine and is likely to place an object if the user clicks with the left mouse button instead of the right while trying to set the focus. I guess I can cover the window with a button and a note to click in the window to make keys work and bury the first click from whatever button. 
If forcing focus isn’t an option, I’m open to thoughts on how I might capture keyboard input while the plugin widget has focus and do what I need to do from there. Not currently having any better luck with that approach though.
Sorry, don’t have a solution. Just checking in that I’ve had the same issue in the past and also didn’t find any workarounds :-(
This is a pretty sorely missing feature IMO, really holds back plugins from creating efficient workflows and making Studio so much more usable
1 Like
Thanks for the confirmation/validation. Makes me feel better about leaving it alone for now. It works well enough for me in the short term while I continue with the script. I’ll visit it again later and try changing my approach, like adding a rotation grabber, and see if that helps avoid the confusion and accidental placements. I wasn’t crazy about using keys as the only means of rotation for the obj I was placing anyway.
I agree that it would be a nice feature to have. Either setting focus to main window or being able to handle keyboard input while the plugin gui is active would be nice, really. The widgets seem to work similarly to other windows like the Explorer, and, with the exception of the quick open window, those don’t seem to utilize much window refocusing. It probably isn’t good ui design to force the focus to a window the user hasn’t clicked. Having a way to handle user keyboard input while the widget is active still seems like it should be possible.
Anyway, thanks for the comments! I’ll move on to more productive things.