[Bug report] Keyboard shortcut causing GUI freeze on start up

Hi JUCE team, @attila

I want to report a bug for keyboard shortcut after AudioPluginHost start up, I’m using macOS Monterey 12.6.3 and the latest JUCE development version.

I added a keyboard shortcut for a TextButton in my plugin, then when I test it in AudioPluginHost, after it opened up, I press the shortcut key I added with computer keyboard, the whole plugin UI would freeze immediately, it only went back to normal after I reopened the plugin window.

I checked the button state, they’re always in buttonDown state after I pressed the keyboard, no matter if I release the keyboard button or not.

Btw the keyboard shortcut has the same issue in GarageBand.

Hope JUCE team can help confirm this bug, thanks in advance!

Hi JUCE team, @attila

Just found the same issue in GarageBand, when the plugin window is opened in the first time, once you hit any keyboard shortcut, the UI would freeze, the button state will always be in buttonDown after you released the button. Here’s my implementation.

In PluginEditor structor:

if(isOnDesktop())
        grabKeyboardFocus();

nameComponent.previousButton.addShortcut(juce::KeyPress(juce::KeyPress::leftKey));
nameComponent.nextButton.addShortcut(juce::KeyPress(juce::KeyPress::rightKey));

Nothing crazy, but if you do the steps I mentioned in AudioPluginHost, you will see the freeze.

Hope you can check it, thanks!

I’m not able to repro this issue in GarageBand, but I do see the button getting stuck in the ‘pressed’ state when testing in the AudioPluginHost. I think the problem I’m seeing is that the hosted plugin view can receive key-down events that originate from the enclosing window when the outer window has focus. In that case, the outer window will be sent the matching keyUp events, and those keyUps won’t reach the plugin view.

Please can you try applying the attached patch and see whether it resolves the issue you’re seeing in the AudioPluginHost and in GarageBand?

keystates.patch (1.9 KB)

Thanks for the feedback!

I just patched the file, seems work fine for the stuck button state now, but I also noticed that the grabKeyboardFocus() lose its function, I specifically add this function to let the keyboard to be on focus once the plugin window is opened, so user don’t need to click into the plugin to use keyboard shortcut, but with the patch after the window is opened, I have to click the plugin interface once to see the keyboard shortcut working.

I found this one more click thing is needed in AudioPluginHost and Reaper, not GarageBand, I’m assuming it’s AudioPluginHost and Reaper is dealing with plugin windows differently from other DAWs?

Are you only calling grabKeyboardFocus() in the constructor of your AudioProcessorEditor? In general, that can’t be expected to work, because the editor will not be showing and on-screen at the point that it is constructed.

Yes, I was calling it in editor constructor. So I still need to do something to keep it on focus later, like recheck with a timer?

You could either use a timer, or use a ComponentMovementWatcher to find out when the top level component becomes visible.

The updates to the keyboard handling code are now on develop, with a few tweaks that should make it a bit more robust: