My plugin has some global keyboard commands used to zoom the UI in/out.
Right now, these keyboard commands only work if the user first clicks somewhere in the PluginEditor UI. These keyboard commands DO NOT work if the user has just clicked the plugin window title bar drawn by the host OS.
From what I gather, the code that processes my keyboard commands only works when the PluginEditor is in focus. When the window title bar is clicked, it seems the PluginEditor loses focus.
Is there any way I can make my app’s global keyboard commands always be received as long as any part of my plugin (including the native window title bar) is in focus?
Currently, this is how I receive keyboard commands in my PluginEditor:
After more testing, I realize I have reported this issue improperly. It’s a bit more nuanced than I realized.
After testing different plugin formats on MacOS in Ableton, I see different plugin formats actually behave slightly differently regarding this issue.
AU plugin format does not exhibit the problem. If you click on the plugin’s OS window title bar OR the PluginEditor UI, you can run the keyboard commands. If you click off of the plugin window, into the host DAW, keyboard commands no longer work as expected. Clicking back to the plugin title bar or PluginEditor UI allows keyboard commands to work again.
VST/VST3 plugin formats do exhibit an issue with keyboard command focus. After the PluginEditor is constructed, you will not be able to run keyboard commands if you simply click the plugin’s OS window title bar. Only after you have clicked the PluginEditor UI, can you successfully complete keyboard commands. At that point you can click either the plugin’s OS window title bar OR the PluginEditor UI and keyboard commands will work, but only after the first initial click on the PluginEditor UI. As soon as you click into the host DAW, keyboard commands no longer work as expected. But now, the keyboard command focus behavior is reset for the plugin, and you will need to click the PluginEditor UI again to gain initial keyboard focus of the plugin and complete keyboard commands.
Standalone app format does exhibit an issue with keyboard command focus. You cannot run keyboard commands until you have clicked on the PluginEditor UI for the first time. After this point, you can click either the app’s OS window title bar OR the PluginEditor UI to have keyboard focus and complete keyboard commands.
Regarding the use of ApplicationCommandManager, I received the same results using ApplicationCommandManager as I did when overriding the PluginEditor's Component::keyPressed function.
This issue is pretty edge-case, and keyboard commands work properly most of the time, but it would be nice if there was a way to always receive keyboard commands if any part of the plugin/app (including the OS window title bar) is in focus.
These rough edges still exist in 2024. Is there any way to improve this behavior?
Standalone app format … You cannot run keyboard commands until you have clicked on the PluginEditor UI for the first time. After this point, you can click either the app’s OS window title bar OR the PluginEditor UI to have keyboard focus and complete keyboard commands.
I am finding I never receive keyboard events if the last thing clicked was the OS window title bar. This is on MacOS with JUCE 7. I always have to click the PluginEditor UI to receive key presses.
I did not try ApplicationCommandManager because, based on the above discussion, it won’t work either. But maybe I will investigate that for myself later.
ApplicationCommandManager should work as long as you have registered an ApplicationCommandTarget to the the actual window (or viewport? i forget what it is) rather than the component returned by the Component::getTopLevelComponent function.
For me, this is Desktop::getInstance().getComponent(0) (in a standalone app) and works even if the OS native title bar is in focus.