diff options
Diffstat (limited to 'src/newt/classes/jogamp')
3 files changed, 27 insertions, 25 deletions
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 311ed0bbb..4f8eb3d3a 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -2193,6 +2193,9 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } return -1; } + protected final boolean isKeyCodeTracked(int keyCode) { + return 0 <= keyCode && keyCode < keyRepeatState.capacity(); + } public void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { consumeKeyEvent(new KeyEvent(eventType, this, System.currentTimeMillis(), modifiers, keyCode, keyChar) ); diff --git a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java index bcdd6b9df..e0ea8ea76 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java @@ -324,24 +324,21 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl // Auto-Repeat: OSX delivers only PRESSED, inject auto-repeat RELEASE and TYPED keys _before_ PRESSED switch(eventType) { case KeyEvent.EVENT_KEY_RELEASED: - if( 1 == isKeyInAutoRepeat(keyCode) ) { - // AR out - keyRepeatState.put(keyCode, false); + if( isKeyCodeTracked(keyCode) ) { + keyRepeatState.put(keyCode, false); // prev == true -> AR out + keyPressedState.put(keyCode, false); } - keyPressedState.put(keyCode, false); keyChar = (char)-1; break; case KeyEvent.EVENT_KEY_PRESSED: - if( 1 == isKeyPressed(keyCode) ) { - if( 0 == isKeyInAutoRepeat(keyCode) ) { - // AR in - keyRepeatState.put(keyCode, true); + if( isKeyCodeTracked(keyCode) ) { + if( keyPressedState.put(keyCode, true) ) { + // key was already pressed + keyRepeatState.put(keyCode, true); // prev == false -> AR in + modifiers |= InputEvent.AUTOREPEAT_MASK; + emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_RELEASED, modifiers, keyCode, (char)-1); // RELEASED + emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_TYPED, modifiers, keyCode, keyChar); // TYPED } - modifiers |= InputEvent.AUTOREPEAT_MASK; - emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_RELEASED, modifiers, keyCode, (char)-1); // RELEASED - emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_TYPED, modifiers, keyCode, keyChar); // TYPED - } else { - keyPressedState.put(keyCode, true); } keyChar = (char)-1; break; diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java index be9f6603e..8b57a241d 100644 --- a/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java @@ -281,12 +281,13 @@ public class WindowDriver extends WindowImpl { // Auto-Repeat: WINDOWS delivers only PRESSED and TYPED. switch(eventType) { case KeyEvent.EVENT_KEY_RELEASED: - if( 1 == isKeyInAutoRepeat(keyCode) ) { - // AR out - send out missing PRESSED - emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_PRESSED, modifiers | InputEvent.AUTOREPEAT_MASK, keyCode, (char)-1); - keyRepeatState.put(keyCode, false); + if( isKeyCodeTracked(keyCode) ) { + if( keyRepeatState.put(keyCode, false) ) { + // AR out - send out missing PRESSED + emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_PRESSED, modifiers | InputEvent.AUTOREPEAT_MASK, keyCode, (char)-1); + } + keyPressedState.put(keyCode, false); } - keyPressedState.put(keyCode, false); emitKeyEvent(send, wait, eventType, modifiers, keyCode, keyChar); final char lastTypedKeyChar = (char) typedKeyCode2KeyChar.put(keyCode, 0); if( 0 < lastTypedKeyChar ) { @@ -294,16 +295,17 @@ public class WindowDriver extends WindowImpl { } break; case KeyEvent.EVENT_KEY_PRESSED: - lastPressedKeyCode = keyCode; - if( 1 == isKeyPressed(keyCode) ) { - if( 0 == isKeyInAutoRepeat(keyCode) ) { - // AR in - skip already send PRESSED - keyRepeatState.put(keyCode, true); + lastPressedKeyCode = keyCode; + if( isKeyCodeTracked(keyCode) ) { + if( keyPressedState.put(keyCode, true) ) { + // key was already pressed + if( keyRepeatState.put(keyCode, true) ) { + emitKeyEvent(send, wait, eventType, modifiers | InputEvent.AUTOREPEAT_MASK, keyCode, (char)-1); + } // else AR in - skip already send PRESSED } else { - emitKeyEvent(send, wait, eventType, modifiers | InputEvent.AUTOREPEAT_MASK, keyCode, (char)-1); + emitKeyEvent(send, wait, eventType, modifiers, keyCode, (char)-1); } } else { - keyPressedState.put(keyCode, true); emitKeyEvent(send, wait, eventType, modifiers, keyCode, (char)-1); } break; |