Is there a way to ignore Cmd-Q or Alt-F4?


#1

My application is for interactive live performance, so I'd like there to be a way to disable exiting the program via keyboard only (i.e. NOT via mouse).  I want this so that the operator of the program doesn't mistakenly exit the app while executing other keyboard commands, even though this would be a very rare occurence.

So, my question is, how do I disable Alt-F4 (Windows) and Cmd-Q (OS X)?  On Windows for example, it seems that the WM_CLOSE message is sent to the Window without any information about whether it was triggered by the keyboard vs. by clicking the close button.

It might also be relevant that I'm using native OS windows.

Thanks for any advice.


#2

Just override the closeButtonPressed method and don't close the window!


#3

Yes, but how do I know if the closeButtonPressed method was triggered by keyboard or by mouse click?  That's my main question -- I want to differentiate between the two.

Also, doesn't Cmd-Q (on Mac) bypass the window system entirely (when using native menus)?  The keypress goes directly to the application, no?


#4

Well, you don't know what triggered it, and in general, neither does the app. There may be tricks that could be used to figure that out, but it's not something I'd want to investigate.. And remember there are probably many other indirect ways that the same event could be triggered, e.g. closing down the OS, etc

Yes, on OSX the shortcut does bypass the window - you'd want to look at JUCEApplication::systemRequestedQuit() to catch that.