<void keyPressed() {
if (key == ESC) {
key = 0;
}
}>
The only code I’ve found to do it is from 2018 and doesn’t seem to be working in my current application, I still use Processing 4. Are there any other ways to kind of ‘change’ they key that’s pressed?
quark
September 11, 2025, 4:53pm
2
You need to override the exit
method like this
void setup(){
size(480,320);
}
void draw(){
background(200,220,200);
}
void exit(){
// do nothing
}
2 Likes
Wait, so i literally put nothing in the void exit section?
I never knew you could use that as a section in the first place lol.
glv
September 11, 2025, 5:24pm
4
The exit()
function (empty function definition) overrides the default exit()
function.
Some insights here to see what is happening:
keyEventMethods.handle(new Object[] { event.getNative() });
}
*/
handleMethods("keyEvent", event);
// if someone else wants to intercept the key, they should
// set key to zero (or something besides the ESC).
if (event.getAction() == KeyEvent.PRESS) {
//if (key == java.awt.event.KeyEvent.VK_ESCAPE) {
if (key == ESC) {
exit();
}
// When running tethered to the Processing application, respond to
// Ctrl-W (or Cmd-W) events by closing the sketch. Not enabled when
// running independently, because this sketch may be one component
// embedded inside an application that has its own close behavior.
if (external &&
event.getKeyCode() == 'W' &&
((event.isMetaDown() && platform == MACOS) ||
(event.isControlDown() && platform != MACOS))) {
I just gave you a starting point… you will have to follow the trail of breadcrumbs.
:)
quark
September 11, 2025, 5:27pm
5
An alternative to keeping the window open when the esc
key is pressed is to allow the window to close but perform some cleanup code prior to closing like this
void exit(){
// perform some clean up here
// e.g. close open files or whatever
super.exit(); // now close the window
}
1 Like
Thanks so much for all the info!
1 Like