Sends all key events (including repeat events) in the JOGL NEWT backend

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10744 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
jul..se 12 years ago
parent 166373230c
commit 92757f8a9d
  1. 30
      engine/src/jogl/com/jme3/input/jogl/NewtKeyInput.java

@ -39,7 +39,6 @@ import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.KeyListener; import com.jogamp.newt.event.KeyListener;
import com.jogamp.newt.opengl.GLWindow; import com.jogamp.newt.opengl.GLWindow;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.BitSet;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -50,7 +49,6 @@ public class NewtKeyInput implements KeyInput, KeyListener {
private final ArrayList<KeyInputEvent> eventQueue = new ArrayList<KeyInputEvent>(); private final ArrayList<KeyInputEvent> eventQueue = new ArrayList<KeyInputEvent>();
private RawInputListener listener; private RawInputListener listener;
private GLWindow component; private GLWindow component;
private BitSet keyStateSet = new BitSet(0xFF);
public NewtKeyInput() { public NewtKeyInput() {
} }
@ -66,7 +64,6 @@ public class NewtKeyInput implements KeyInput, KeyListener {
if (component != null){ if (component != null){
component.removeKeyListener(this); component.removeKeyListener(this);
eventQueue.clear(); eventQueue.clear();
keyStateSet.clear();
} }
component = comp; component = comp;
component.addKeyListener(this); component.addKeyListener(this);
@ -96,34 +93,23 @@ public class NewtKeyInput implements KeyInput, KeyListener {
} }
public void keyTyped(KeyEvent evt) { public void keyTyped(KeyEvent evt) {
// key code is zero for typed events
} }
public void keyPressed(KeyEvent evt) { public void keyPressed(KeyEvent evt) {
int code = convertNewtKey(evt.getKeySymbol()); int code = convertNewtKey(evt.getKeySymbol());
KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), true, evt.isAutoRepeat());
// Check if key was already pressed keyEvent.setTime(evt.getWhen());
if (!keyStateSet.get(code)){ synchronized (eventQueue){
keyStateSet.set(code); eventQueue.add(keyEvent);
KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), true, false);
keyEvent.setTime(evt.getWhen());
synchronized (eventQueue){
eventQueue.add(keyEvent);
}
} }
} }
public void keyReleased(KeyEvent evt) { public void keyReleased(KeyEvent evt) {
int code = convertNewtKey(evt.getKeySymbol()); int code = convertNewtKey(evt.getKeySymbol());
KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), false, evt.isAutoRepeat());
// Check if key was already released keyEvent.setTime(evt.getWhen());
if (keyStateSet.get(code)) { synchronized (eventQueue) {
keyStateSet.clear(code); eventQueue.add(keyEvent);
KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), false, false);
keyEvent.setTime(evt.getWhen());
synchronized (eventQueue){
eventQueue.add(keyEvent);
}
} }
} }

Loading…
Cancel
Save