I was under the impression that stop() always gets called by the applet so there isn't any need to test for ESC etc.
Yes you're right.
Whenever you press escape or ctrl+w processing will call exit() whose code is
/**
* Call to safely exit the sketch when finished. For instance,
* to render a single frame, save it, and quit.
*/
public void exit() {
if (thread == null) {
// exit immediately, stop() has already been called,
// meaning that the main thread has long since exited
exit2();
} else if (looping) {
// stop() will be called as the thread exits
finished = true;
// tell the code to call exit2() to do a System.exit()
// once the next draw() has completed
exitCalled = true;
} else if (!looping) {
// if not looping, need to call stop explicitly,
// because the main thread will be sleeping
stop();
// now get out
exit2();
}
}
And here's the processing call when you press escape :
// 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) {
if (key == KeyEvent.VK_ESCAPE) {
exit();
}
But i'm not sure that calling stop() would close audio buffers.
I've no idea about that.