summaryrefslogtreecommitdiffstats
path: root/src/newt/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-01-29 21:27:57 +0100
committerSven Gothel <[email protected]>2013-01-29 21:27:57 +0100
commit90e136b65a10d8daf8c3a2df6cc193e55a63722c (patch)
tree863f8a3679a70065b031aaf83bd7cc6053fd69ab /src/newt/classes/jogamp
parent2f63a43fd6ff9964251c43e248c51bc821f3ecbd (diff)
Fix Bug 678: Deliver key-char value for printable chars on all KeyEventListener (-> On Windows as well)
The following is observed, where t0 and t1 refer to subsequent different timestamps: NEWT delivery order: PRESSED (t0), RELEASED (t1) and TYPED (t1) WINDOWS delivery order: PRESSED (t0), TYPED (t0) and RELEASED (t1) Windows Auto-Repeat: PRESSED (t0), TYPED (t0) Hence we changed the event reorder-code in NEWT to trigger NEWT-PRESSED on Windows-TYPED for printable chars, assuring key-char values on all listener callbacks. - KeyEvent.getKeyChar(): Removed disclaimer dedicated for Windows - Keyevent.isActionKey(): Completed for all NEWT non-printable action keys; Added static variant - Keyevent.isPrintableKey(): NEW: returns !isModifierKey(keyCode) && !isActionKey(keyCode) ; With static variant - Windows WindowDriver: - EVENT_KEY_PRESSED handles non-printable chars only - EVENT_KEY_TYPE handles printable chars only - Native: VK_DELETE passes keyCode - Unit tests: Wait for completion 1s -> 2s
Diffstat (limited to 'src/newt/classes/jogamp')
-rw-r--r--src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java62
1 files changed, 38 insertions, 24 deletions
diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java
index b2e518f45..650958f25 100644
--- a/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java
@@ -273,53 +273,67 @@ public class WindowDriver extends WindowImpl {
private IntIntHashMap typedKeyCode2KeyChar = new IntIntHashMap(KeyEvent.VK_CONTEXT_MENU+1);
private final void handleKeyEvent(boolean send, boolean wait, int eventType, int modifiers, int keyCode, char keyChar) {
- final boolean isModifierKeyCode = KeyEvent.isModifierKey(keyCode);
- // System.err.println("*** handleKeyEvent: event "+KeyEvent.getEventTypeString(eventType)+", keyCode "+toHexString(keyCode)+", keyChar <"+keyChar+">, mods "+toHexString(modifiers)+", was: pressed "+isKeyPressed(keyCode)+", repeat "+isKeyInAutoRepeat(keyCode)+", isModifierKeyCode "+isModifierKeyCode);
+ final boolean isPrintableKey = KeyEvent.isPrintableKey(keyCode);
+ final boolean isModifierKey = KeyEvent.isModifierKey(keyCode);
+ // System.err.println("*** handleKeyEvent: event "+KeyEvent.getEventTypeString(eventType)+", keyCode "+toHexString(keyCode)+", keyChar <"+keyChar+">, mods "+toHexString(modifiers)+", was: pressed "+isKeyPressed(keyCode)+", repeat "+isKeyInAutoRepeat(keyCode)+", printableKey "+isPrintableKey+" [modifierKey "+isModifierKey+"] - "+System.currentTimeMillis());
- // Reorder: WINDOWS delivery order is PRESSED, TYPED and RELEASED -> NEWT order: PRESSED, RELEASED and TYPED
- // Auto-Repeat: WINDOWS delivers only PRESSED and TYPED.
+ // Reorder: WINDOWS delivery order is PRESSED (t0), TYPED (t0) and RELEASED (t1) -> NEWT order: PRESSED (t0), RELEASED (t1) and TYPED (t1)
+ // Auto-Repeat: WINDOWS delivers only PRESSED (t0) and TYPED (t0).
switch(eventType) {
case KeyEvent.EVENT_KEY_RELEASED:
+ final int keyCharTyped = typedKeyCode2KeyChar.put(keyCode, 0);
+ if( 0 != keyCharTyped ) {
+ keyChar = (char)keyCharTyped;
+ }
if( isKeyCodeTracked(keyCode) ) {
- if( keyRepeatState.put(keyCode, false) && !isModifierKeyCode ) {
+ if( keyRepeatState.put(keyCode, false) && !isModifierKey ) {
// AR out - send out missing PRESSED
emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_PRESSED, modifiers | InputEvent.AUTOREPEAT_MASK, keyCode, keyChar);
}
keyPressedState.put(keyCode, false);
}
- final int keyCharTyped = typedKeyCode2KeyChar.put(keyCode, 0);
- if( 0 != keyCharTyped ) {
- keyChar = (char)keyCharTyped;
- }
emitKeyEvent(send, wait, eventType, modifiers, keyCode, keyChar);
emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_TYPED, modifiers, keyCode, keyChar);
break;
case KeyEvent.EVENT_KEY_PRESSED:
- if( isKeyCodeTracked(keyCode) ) {
- if( keyPressedState.put(keyCode, true) ) {
- // key was already pressed
- if( keyRepeatState.put(keyCode, true) && !isModifierKeyCode ) {
- emitKeyEvent(send, wait, eventType, modifiers | InputEvent.AUTOREPEAT_MASK, keyCode, keyChar);
- } // else AR in - skip already send PRESSED ; or ALT
- } else {
- emitKeyEvent(send, wait, eventType, modifiers, keyCode, keyChar);
+ // TYPED is delivered right after PRESSED for printable keys and contains the key-char information,
+ // hence we only deliver non printable keys (action and modifier keys) here.
+ // Modifier keys shall not AR.
+ if( !isPrintableKey ) {
+ if( !handlePressTypedAutoRepeat(isModifierKey, send, wait, modifiers, keyCode, keyChar) ) {
+ emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_PRESSED, modifiers, keyCode, keyChar);
}
- } else {
- emitKeyEvent(send, wait, eventType, modifiers, keyCode, keyChar);
}
break;
case KeyEvent.EVENT_KEY_TYPED:
- if( 1 == isKeyInAutoRepeat(keyCode) ) {
- modifiers |= InputEvent.AUTOREPEAT_MASK;
- emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_RELEASED, modifiers, keyCode, keyChar);
- emitKeyEvent(send, wait, eventType, modifiers, keyCode, keyChar);
- } else if( 0 != keyCode ) {
+ if( isPrintableKey ) {
typedKeyCode2KeyChar.put(keyCode, keyChar);
+ if( !handlePressTypedAutoRepeat(isModifierKey, send, wait, modifiers, keyCode, keyChar) ) {
+ emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_PRESSED, modifiers, keyCode, keyChar);
+ }
}
break;
}
}
+ private final boolean handlePressTypedAutoRepeat(boolean isModifierKey, boolean send, boolean wait, int modifiers, int keyCode, char keyChar) {
+ if( isKeyCodeTracked(keyCode) && keyPressedState.put(keyCode, true) ) {
+ final boolean preKeyRepeatState = keyRepeatState.put(keyCode, true);
+ if( !isModifierKey ) {
+ // AR: Key was already pressed: Either [enter | within] AR mode
+ modifiers |= InputEvent.AUTOREPEAT_MASK;
+ if( preKeyRepeatState ) {
+ // AR: Within AR mode
+ emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_PRESSED, modifiers, keyCode, keyChar);
+ } // else { AR: Enter AR mode - skip already send PRESSED ; or ALT }
+ emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_RELEASED, modifiers, keyCode, keyChar);
+ emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_TYPED, modifiers, keyCode, keyChar);
+ }
+ return true;
+ }
+ return false;
+ }
+
@Override
public void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
handleKeyEvent(true, false, eventType, modifiers, keyCode, keyChar);