# Disable ESC from exiting program in fullscreen?

**URL:** <https://discourse.processing.org/t/disable-esc-from-exiting-program-in-fullscreen/32383>\
**Category:** Coding Questions\
**Created:** [September 22, 2021, 9:07pm UTC](https://discourse.processing.org/t/disable-esc-from-exiting-program-in-fullscreen/32383 "2021-09-22T21:07:56Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 24, 2021, 4:27pm UTC](https://discourse.processing.org/t/disable-esc-from-exiting-program-in-fullscreen/32383/4 "2021-09-24T16:27:36Z")

</div>

@jonnyetiz – there are at several ways to approach this.

One is to replace the key value, as you did above, so that a later check does not trigger the sketch `exit()` method.

Another way is to override the sketch `exit()` method and make it dependent, not on key, but on some gatekeeper value of your own such as `boolean doExit`.

```auto
boolean doExit=false;

void draw() {
}

void keyPressed() {
  if(key==' ') {
    doExit=true;
    exit();
  }
}

void exit(){
  if (doExit==true){
    super.exit();
  }
}

```

Now `exit()` does nothing unless your flag is set, in which case it exits normally. That means you can trigger exiting in as many ways as you want – with a keypress, or a mouse click, or a timer, or all of the above – and you aren’t limited to only a different keyboard key.

The only thing to be aware of about this design is that now the sketch applet won’t actually stop anymore if you close the applet window with the X / red button without running code that sets your boolean flag – it will still appear running in your toolbar, and you will need to use the PDE “stop” square button to quit it.

If you wish to handle that case as well, you may use an exit hook or dispose: [Save when app close, exit() ... stop()](https://discourse.processing.org/t/save-when-app-close-exit-stop/25754)

Or just stick to the keyPresses only solution.

---

_[View the full topic](https://discourse.processing.org/t/disable-esc-from-exiting-program-in-fullscreen/32383)._
