We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Disabling the Escape Keybinding
Page Index Toggle Pages: 1
Disabling the Escape Keybinding (Read 789 times)
Disabling the Escape Keybinding
Sep 14th, 2006, 5:14am
 
I want to disable the escape key quitting, but still know that the Escape key has been pressed, preferably with the keycode itself.  Is this possible?

Found this in the source code:
   // if someone else wants to intercept the key, they should
   // set key to zero (or something besides the ESC).
   if ((event.getID() == KeyEvent.KEY_PRESSED) &&
       (key == KeyEvent.VK_ESCAPE)) {
     exit();
   }

It would be nice if there was a way to turn this on or off,   set a variable, say, exitOnEsc to true by default, but disable it by a method call, like disableExitOnEsc() which simply sets exitOnEsc to false.  

--- a possible way to put this into Processing ---

//put in declaration section
boolean exitOnEsc;

//put in initialization section
exitOnEsc=true;

//put in methods section
disableExitOnEsc() {
 exitOnEsc=false;
}

//modified handleKeyEvent snippet
   if ((event.getID() == KeyEvent.KEY_PRESSED) &&
       (key == KeyEvent.VK_ESCAPE) && exitOnEsc) {
     exit();
   }

Re: Disabling the Escape Keybinding
Reply #1 - Sep 15th, 2006, 2:42pm
 
or you can add

if (key == ESC) key = 0;

to your keyPressed() method. i'm debating whether that's any more difficult than writing something like hint(DISABLE_EXIT_ON_ESC). last i thought about it, i decided it wasn't, but if people feel otherwise, i can change it.
Re: Disabling the Escape Keybinding
Reply #2 - Sep 19th, 2006, 5:14am
 
I would like to get back VK_ESCAPE when I press the escape key.  Virtual keys represent arbitrary key code values, which Sun reserves the right to change at any time.  There may not be a VK assigned to 0, but there could be in the future.
Re: Disabling the Escape Keybinding
Reply #3 - Sep 19th, 2006, 6:30am
 
the ESC constant in the p5 api is the same as VK_ESCAPE. so you can use

if (key == KeyEvent.VK_ESCAPE) key = 0;

if you'd prefer to type more. key 0 is NUL, no "new" key data will be assigned to it.
Page Index Toggle Pages: 1