Plugin Global Keyboard Commands and Window Focus

Hi there,

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:

bool keyPressed (const KeyPress& key) override
{
    // Increase interface zoom
    if (key == KeyPress ('=', ModifierKeys::commandModifier, 0))
    {
        increaseZoom();
        return true; // Key command consumed
    }
    else if (key == KeyPress ('-', ModifierKeys::commandModifier, 0))
    {
        decreaseZoom();
        return true; // Key command consumed
    }
    
    return false; // Key command not consumed
}

I am looking into ApplicationCommandManager as an alternative.
Does anyone know if ApplicationCommandManager remedies this issue?

Thank you for any help!

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.

1 Like