Tell standalone app to quit

Hi,

So if I run my plugin as standalone and it want it to quit, right now I have to either use Alt-F4 or close the window with the mouse.

Is there a way to do this programmatically? Let’s say I want to close the app by pressing the escape key on my keyboard. How would I do this?

Cheers,
Mike

I haven’t tried, but I think it could work like this in your keyPress:

if (JUCEApplicationBase::isStandaloneApp())
    JUCEApplicationBase::quit();
1 Like

Thank you. That worked like a charm. Do you happen to know how to make sure that the window actually has focus right after the application starts? grabKeyboardFocus () from the constructor or from visibilityChanged () didn’t work :frowning:

Glad it worked. Unfortunately I don’t have much experience with the focus. The project I spend most of my time has a non-JUCE frontend.

But I assume, the problem is rather that the focus goes to a sub component rather than the window not getting it in the first place. I guess setting Component:: setWantsKeyboardFocus(false) to all child components is the safest way. You may iterate the child components in the constructor, I read a lot people recommending that…

Unfortunately it’s more complicated than that. It seems the window itself doesn’t have focus. The “keyPress” overload already sends the event to the parent until it either gets used or it hits the main-window. It seems the main-component simply doesn’t have ANY focus whatsoever when the stand-alone application starts. I can then click anywhere within the window (even on sliders etc.) and the escape key will then trigger the ::quit () call.

Well, you can’t have everything, I guess :frowning:

Thanks for helping me.