We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I'm having trouble when using G4P with multiple windows. In my program I have the following code to prevent the escape key from closing the application. This works fine as long as I do not open a new window.
void keyPressed(){
switch(key){
case ESC:
key = 0;
break;
}
}
However, when opening a new window, pressing the escape key now closes the application.
The code for the window opener is something like
new_win = new GWindow(this, "title", x, y, w, h, false, JAVA2D);
new_win.setActionOnClose(GWindow.CLOSE_WINDOW);
If I change the action on close to KEEP_OPEN the escape key still closes the application but the window can't be closed as intended with the close button.
I guess that opening a new window makes keyboard presses to another call function within the new window/applet or something? Is there a way to prevent the escape key from closing the application when a new window has been opened? (Using MS Windows enviroment)
/ Blom
Answers
Effectively each GWindow is a separate Processing sketch with its own event handling mechanism. The setActionOnClose only controls what happens when the user clicks on the window close icon.
The trick would be to add a key-event-handler for each GWindow and then add your own key handling code.
This code worked for me.
Thank you quark. It works like a charm!