# Override Escape Key in Python Mode

**URL:** <https://discourse.processing.org/t/override-escape-key-in-python-mode/12726>\
**Category:** Processing.py\
**Created:** [July 15, 2019, 5:34pm UTC](https://discourse.processing.org/t/override-escape-key-in-python-mode/12726 "2019-07-15T17:34:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pi3point1415](https://avatars.discourse-cdn.com/v4/letter/p/7bcc69/32.png) [@pi3point1415](https://discourse.processing.org/u/pi3point1415)\
**Post date:** [July 15, 2019, 5:34pm UTC](https://discourse.processing.org/t/override-escape-key-in-python-mode/12726/1 "2019-07-15T17:34:11Z")

</div>

In normal Java mode, when I use the code:

```auto
  if (key == ESC) {
    key = 0;
  }

```

pressing escape does not close the sketch. However, in python mode, when I try similar code:

```auto
    if key == ESC:
        key = 0

```

pressing escape still closes the sketch. I tried putting it in both the keyPressed function, and draw, and I made sure to put “global key” at the beginning of the function both times and it still didn’t work. I also tried the same thing but with keyCode. Is there some way to prevent escape from closing the sketch?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 15, 2019, 11:47pm UTC](https://discourse.processing.org/t/override-escape-key-in-python-mode/12726/2 "2019-07-15T23:47:31Z")

</div>

```auto
NO_ESCAPE = '0'

def keyPressed():
    print key, ord(key), keyCode
    if key == ESC: this.key = NO_ESCAPE

```

---

<div class="post-metadata">

**Author:** ![pi3point1415](https://avatars.discourse-cdn.com/v4/letter/p/7bcc69/32.png) [@pi3point1415](https://discourse.processing.org/u/pi3point1415)\
**Post date:** [July 16, 2019, 4:35am UTC](https://discourse.processing.org/t/override-escape-key-in-python-mode/12726/3 "2019-07-16T04:35:08Z")

</div>

That worked. Thank you.
