I know this has been discussed elsewhere and I have read and tried code ideas from several threads and also some from Stack Overflow but with no luck. So how can the the BACK key behaviour be controlled in the new version of Processing. In P2 and early versions of P3 (before android mode started putting us in a Fragment - why?) I was able to use the function boolean surfaceKeyDown(int code, KeyEvent event) but that has now for some reason become void surfaceKeyDown(int code, KeyEvent event) and doesn't work any longer.
So back to basics .... the following code makes use of keyPressed() as described in the Android Mode Wiki. The code runs when the BACK key is pressed, but the app quits.... setting keyCode = 0 doesn't prevent quitting. This is presumably dated info in the wiki??
So what to try next .... any ideas please?
Thanks, Mark
void setup() {
fullScreen(P2D);
rectMode(CENTER) ;
}
// draw() ... just to have somethng happening ...
void draw() {
background(0) ;
rect(mouseX, mouseY, width/8, width/8) ;
}
// keyPressed() ... copied from Processing's Android Mode WIKI ...
void keyPressed() {
// doing other things here, and then:
if (key == CODED && keyCode == android.view.KeyEvent.KEYCODE_BACK) {
keyCode = 0; // don't quit by default
println("BACK key pressed") ; // to prove the code ran to here ...
}
}