Remove ALT + F4 shortcut?


I want remove the ALT+F4 exit shortcut for my game, does anyone have an idea about how to do it?


Shatazone said:

I want remove the ALT+F4 exit shortcut for my game, does anyone have an idea about how to do it?

:? :? :? :? :? why would u want to do that

why ever you would want to do that.  :?

well as far as i know you cant exactly override the shortcut, since the OS will catch it first and then delegate it to the VM, and the OS has "close" bound to that normally.

However if you get a hold of the actual JFrame your application is displayed in, you can setDefaultCloseBehaviour(JFrame.DO_NOTHING_ON_CLOSE); and it will not close on alt+f4.

No idea though how you get the main JFrame in jme though…

EDIT: almost forgot to mention, that one disables the "close"-button in the title bar too.


public abstract class BaseGame extends AbstractGame {
// main loop
                while (!finished && !display.isClosing()) {

boolean com.jme.system.DisplaySystem.isClosing()
isClosing notifies if the window is currently closing. This could be caused via the application itself or external interrupts such as alt-f4 etc.

I thought you could just remove the check for display.isClosing() but it seems not enough, alt-f4 still kills the jme window.

DisplaySystem.isClosing() should do it, although SimpleGame or other implementations might take action on it without your consent.

This flag will be true if the user pressed Alt-F4, clicked the X button on the window, or tried to shutdown the program from task manager.

@t3chn0l0g1c : It is possible to override the alt + f4 command (many commercials games do it). The issue is how.

SimpleGame has too many things implemented and running in the background for anyone who likes their hair to ever want to try that. However, this is rather plausible for BaseGame and StandardGame.

I haven't really dug into the guts of jme, but wouldn't it be easier to just disable it within the JME code, finish the program, compile the program, then enable it again? (so you dont make a mistake where you have to kill the actual program. [which I think is only possible on windows and linux. I refuse to touch mac…])

I tried it again and removing the display.isClosing() check in BaseGame or StandardGame seems to work fine.

ALT+F4 dosen't kill the game anymore.

I'm not sure what i did wrong in my initial test.

thanks guys for your help

im gonna try it now … thanks Core-Dump :slight_smile: