Enter key being stolen by Juce plugin to click button


Logic 8 Mac Au

I add my plugin to a track on logic, the gui opens, I move a knob on the interface then let go of the mouse button. If I then press space bar the song plays just fine, but if I then press the enter key instead of the host stopping to play it seems like the top left most button is getting a button click event. Does this sound normal? I have set flags saying I don’t want keyboard events.

Andrew Simper


Hmm, did you call setWantsKeyboardFocus (false) on the button itself?


Yes, but that means that the enter key still gets stolen, but the button doesn’t get clicked. Is there any way to not steal the enter key?


Andrew Simper


Hold off on that last post, I want to double check that the correct version of the plugin is being loaded since I’m seeing odd behavior debugging.

Andrew Simper


My previous post stands, the plugin was still eating the enter key. I found the culprit:

TopLevelWindow::TopLevelWindow (…)

setWantsKeyboardFocus (false);
//setWantsKeyboardFocus (true);


That does the trick.

Perhaps this should be throughout the code based on the plugin flag specifying if the plugin wants keyboard forcus or not?

#define JucePlugin_EditorRequiresKeyboardFocus 0

Andrew Simper


Well, maybe, though if you’re using a separate TopLevelWindow, it’s pretty reasonable to assume it might want keyboard focus like any other floating window. The JucePlugin_EditorRequiresKeyboardFocus flag is really just there for handling the embedded plugin window…


I’m not using a separate top level window, I only popup new windows for text entry as this is the only reliable way to get keystrokes. For those new windows I explicitly say I want keyboard focus.

Andrew Simper


…but you mentioned a TopLevelWindow above? The embedded plugin GUI doesn’t use them, so I assumed you must be talking about a separate window…


I’ll put a breakpoint in the code and double check it’s getting called and if so by who.

Andrew Simper


As you predicted the breakpoint was not hit. It has nothing to do with the TopLevelWindow, and everything to do with the constructor of the Button class declaring it wants keyboard input. Once I set that to false all is good. The reason for the mix up is that I think the dependencies got mixed up and I was debugging different code to what was running. I did the post build phase of copying to .vst manually and all was good.

So, the solution for no enter key stealing in Logic for me was to edit the juce::Button::Button () constructor, and change the code to:

//setWantsKeyboardFocus (true);
setWantsKeyboardFocus (false);

Andrew Simper


Ok, though I’d have thought it’d be better just to call setWantsKeyboardFocus(false) on your button after you create it, rather than hacking the juce code - otherwise when you grab a new version of the code in the future you’re bound to forget to put that hack back in there…