因此,我们有一个如下的应用程序结构:
在EC_GUI构造函数中的
我初始化glViewer
private void initGlViewer() {
/**
* Viewer.
*/
glViewer = new GLViewer();
glViewer.setup();
centerPanel.add(glViewer.getNewtCanvasAWT());
}
glViewer实现了GLEventListener,它是以下
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);
}
在glViewer.setup()中我将鼠标,键和glEvent监听器添加到glWindow。
我正在使用com.jogamp.newt.event中的键和鼠标事件。
我的keyListener中的keyPressed事件以:
开头@Override
public synchronized void keyPressed(KeyEvent ke) {
System.out.println("keyPressed " + ke.getKeyCode());
和keyReleased也是。
有时我遇到有关触发的不一致。以组合ctrl + o打开fileChooser为例。
这应该是:
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.
在这里你可以看到我按下ctrl(17),然后按o(17),它们都被释放并且fileChooser被显示出来。然后我退出,你可以在最后一行看到它。
但有时这就是我得到的:
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.
我得到了ctrl和o keyPressed,但我错过了一个keyReleased,在这种情况下是o。无论如何fileChooser仍然被打开。在下一次尝试中我再次按ctrl + o但这次我错过了o keyPressed。我也想念ctrl keyReleased。无论如何fileChooser仍然打开。 但有时它不会打开,例如:
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
我得到ctrl-keyPressed,o-keyPressed,ctrl-keyReleased,没有o-keyReleased,fileChooser打开,然后我关闭它。 我再次按下它们,我得到ctrl-keyPressed,没有o-keyPressed,o-keyReleased,没有ctrl-keyReleased,fileChooser打开,然后我再次关闭它。 我再次按ctrl + o,我没有得到任何keyPressed,我只是得到一个o-keyReleased,一个ctrl-keyReleased然后另一个o-keyReleased。 FileChooser这次没有打开..
有任何线索吗?
答案 0 :(得分:0)
我通过在每个keyPressed / keyReleased事件中检查按下的修饰符,通过KeyEvent.isXDown()
查询每个X修饰符来解决