So, we have an application structure as following:
in the EC_GUI constructor I initialize the glViewer
private void initGlViewer() {
/**
* Viewer.
*/
glViewer = new GLViewer();
glViewer.setup();
centerPanel.add(glViewer.getNewtCanvasAWT());
}
The glViewer implements the GLEventListener and is the following
public GLViewer() {
GLProfile gLProfile = GLProfile.getDefault();
GLCapabilities gLCapabilities = new GLCapabilities(gLProfile);
glWindow = GLWindow.create(gLCapabilities);
/*
* We combine NEWT GLWindow inside existing AWT application (the main JFrame)
* by encapsulating the glWindow inside a NewtCanvasAWT canvas.
*/
newtCanvasAWT = new NewtCanvasAWT(glWindow);
}
in the glViewer.setup() I add mouse, key and glEvent listeners to the glWindow.
I am using the key and mouse event from the com.jogamp.newt.event.
My keyPressed event in my keyListener starts as:
@Override
public synchronized void keyPressed(KeyEvent ke) {
System.out.println("keyPressed " + ke.getKeyCode());
and the keyReleased as well.
Well sometimes I am experiencing inconsistencies regarding the triggering. Let's take as an example when I press the combination ctrl+o to open the fileChooser.
This is as it should be:
keyPressed 17
List of pressed inputs
ctrl
keyPressed 79
List of pressed inputs
ctrl
o
keyReleased 17
keyReleased 79
2014.10.09, 10:53:49 [INFORMATION] Open a project ...
2014.10.09, 10:53:49 [INFORMATION] Opening file chooser for load.
2014.10.09, 10:53:55 [INFORMATION] User clicked 'cancel' in file chooser dialog.
Here you can see I press ctrl (17), then o (17), they are both released and the fileChooser gets displayed. And then I exit, as you can see it in the last line.
But sometimes this is what I get:
keyPressed 17
List of pressed inputs
ctrl
keyPressed 79
List of pressed inputs
ctrl
o
keyReleased 17
2014.10.09, 10:57:34 [INFORMATION] Open a project ...
2014.10.09, 10:57:34 [INFORMATION] Opening file chooser for load.
2014.10.09, 10:57:35 [INFORMATION] User clicked 'cancel' in file chooser dialog.
keyPressed 17
List of pressed inputs
ctrl
keyReleased 79
2014.10.09, 10:57:36 [INFORMATION] Open a project ...
2014.10.09, 10:57:36 [INFORMATION] Opening file chooser for load.
2014.10.09, 10:57:38 [INFORMATION] User clicked 'cancel' in file chooser dialog.
I get the ctrl and o keyPressed, but I miss one of the keyReleased, the o in this case. Anyway the fileChooser still gets opened. In the next attempt I press again ctrl+o but this time I miss the o keyPressed. I also miss the ctrl keyReleased. Anyway the fileChooser gets still opened. But sometimes it doesnt open, for example:
keyPressed 17
List of pressed inputs
ctrl
keyPressed 79
List of pressed inputs
ctrl
o
keyReleased 17
2014.10.09, 11:08:57 [INFORMATION] Open a project ...
2014.10.09, 11:08:57 [INFORMATION] Opening file chooser for load.
2014.10.09, 11:08:58 [INFORMATION] User clicked 'cancel' in file chooser dialog.
keyPressed 17
List of pressed inputs
ctrl
keyReleased 79
2014.10.09, 11:08:59 [INFORMATION] Open a project ...
2014.10.09, 11:08:59 [INFORMATION] Opening file chooser for load.
2014.10.09, 11:09:02 [INFORMATION] User clicked 'cancel' in file chooser dialog.
keyReleased 79
keyReleased 17
keyReleased 79
I get ctrl-keyPressed, o-keyPressed, ctrl-keyReleased, no o-keyReleased, fileChooser opens, then I close it. I pressed them again, I get ctrl-keyPressed, no o-keyPressed, o-keyReleased, no ctrl-keyReleased, fileChooser opens, then I close it again. I press ctrl+o again, I do not get any keyPressed, I just get an o-keyReleased, a ctrl-keyReleased and then another o-keyReleased. FileChooser does not open this time..
Any clue?
I solved by checking at every keyPressed/keyReleased event the pressed modifiers by quering each X modifier by KeyEvent.isXDown()