Any way to intercept ALT-F4 to query user to save before quitting?

Title says it all.

LWJGL has a method that you can periodically query to check if the application is attempting to close (by the close button, ALT-F4, etc)


Maybe it’s me, but using this in the update loop doesn’t seem to trigger when hitting ALT-F4.



public void simpleUpdate(float tpf) {

if (Display.isCloseRequested()) {

// Query user to save before quitting. For now, just save.

System.out.println(“Saving before quitting.”);




maybe it happens so fast that System.out.println(); doesnt display ?

I traced it with a breakpoint. It didn’t trigger. Besides, even if it were going too fast, the printout would still happen, just lagged.

Anyway, can anyone reproduce it? As I said, maybe it’s me.

thats what happens when you hear sbook, this is jme3 not lwjgl, it is not supposed to work.



public void destroy()



System.out.println(“Exiting Game”);



Now it works just override simple application’s destroy.

1 Like

Thanks. Works like a charm.

It works but anyone wanting to use that; be warned. If the game/app crashes, this will be invoked.