# Block the PApplet(Processing) closing action when ESC is pressed

**URL:** <https://discourse.processing.org/t/block-the-papplet-processing-closing-action-when-esc-is-pressed/21657>\
**Category:** Coding Questions\
**Created:** [June 7, 2020, 3:33pm UTC](https://discourse.processing.org/t/block-the-papplet-processing-closing-action-when-esc-is-pressed/21657 "2020-06-07T15:33:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Moritz](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Moritz](https://discourse.processing.org/u/Moritz)\
**Post date:** [June 7, 2020, 3:33pm UTC](https://discourse.processing.org/t/block-the-papplet-processing-closing-action-when-esc-is-pressed/21657/1 "2020-06-07T15:33:44Z")

</div>

Hey Guys,  
How can i block the closing action when ESC is pressed?  
The only way i found by myself was to overwrite the original closing method and creating a new one

```auto

@Override
public void exit(){
}

public void exitProcessing(){
super.exit();
}

```

Thank you.

---

<div class="post-metadata">

**Author:** ![slow\_izzm](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/slow_izzm/32/5637_2.png) [@slow\_izzm](https://discourse.processing.org/u/slow_izzm)\
**Post date:** [June 7, 2020, 3:41pm UTC](https://discourse.processing.org/t/block-the-papplet-processing-closing-action-when-esc-is-pressed/21657/2 "2020-06-07T15:41:22Z")

</div>

You need to clear it out first then you can call whatever you like …

```auto
void keyPressed() {
  if (key == ESC) {
    key = 0;
    println("no quit");
  }
}

```

---

<div class="post-metadata">

**Author:** ![Moritz](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Moritz](https://discourse.processing.org/u/Moritz)\
**Post date:** [June 7, 2020, 3:42pm UTC](https://discourse.processing.org/t/block-the-papplet-processing-closing-action-when-esc-is-pressed/21657/3 "2020-06-07T15:42:17Z")

</div>

Is there an other way to do this?

---

<div class="post-metadata">

**Author:** ![slow\_izzm](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/slow_izzm/32/5637_2.png) [@slow\_izzm](https://discourse.processing.org/u/slow_izzm)\
**Post date:** [June 7, 2020, 3:51pm UTC](https://discourse.processing.org/t/block-the-papplet-processing-closing-action-when-esc-is-pressed/21657/4 "2020-06-07T15:51:21Z")

</div>

> [@Moritz](#):
>
> Is there an other way to do this?

I guess you could change the source code …

as far as I know this is the recommended method to avoid the key being passed to the quit command.

---

<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:** [June 10, 2020, 4:49am UTC](https://discourse.processing.org/t/block-the-papplet-processing-closing-action-when-esc-is-pressed/21657/5 "2020-06-10T04:49:51Z")

</div>

Clearing the key or overriding the method are both good ways.

Is there any particular reason why you don’t want to use either of those?
