Override Escape Key in Python Mode

In normal Java mode, when I use the code:

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

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

    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?

2 Likes
NO_ESCAPE = '0'

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

That worked. Thank you.