diff options
Diffstat (limited to 'src')
6 files changed, 54 insertions, 40 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/font/FontFactory.java b/src/jogl/classes/com/jogamp/graph/font/FontFactory.java index bbdfc0e9f..d2824b9dc 100644 --- a/src/jogl/classes/com/jogamp/graph/font/FontFactory.java +++ b/src/jogl/classes/com/jogamp/graph/font/FontFactory.java @@ -93,10 +93,13 @@ public class FontFactory { } public static boolean isPrintableChar( char c ) { - Character.UnicodeBlock block = Character.UnicodeBlock.of( c ); - return (!Character.isISOControl(c)) && - c != 0 && - block != null && - block != Character.UnicodeBlock.SPECIALS; + if( Character.isWhitespace(c) ) { + return true; + } + if( 0 == c || Character.isISOControl(c) ) { + return false; + } + final Character.UnicodeBlock block = Character.UnicodeBlock.of( c ); + return block != null && block != Character.UnicodeBlock.SPECIALS; } } diff --git a/src/newt/classes/com/jogamp/newt/event/KeyEvent.java b/src/newt/classes/com/jogamp/newt/event/KeyEvent.java index 156708779..085f598dc 100644 --- a/src/newt/classes/com/jogamp/newt/event/KeyEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/KeyEvent.java @@ -312,27 +312,25 @@ public class KeyEvent extends InputEvent * @param isKeyChar true if <code>uniChar</code> is a key character, otherwise a virtual key code */ public static boolean isPrintableKey(final short uniChar, final boolean isKeyChar) { - if( VK_UNDEFINED == uniChar ) { - return false; + if ( VK_BACK_SPACE == uniChar || VK_TAB == uniChar || VK_ENTER == uniChar ) { + return true; } if( !isKeyChar ) { if( ( nonPrintableKeys[0].min <= uniChar && uniChar <= nonPrintableKeys[0].max ) || ( nonPrintableKeys[1].min <= uniChar && uniChar <= nonPrintableKeys[1].max ) || - ( nonPrintableKeys[2].min <= uniChar && uniChar <= nonPrintableKeys[2].max ) || - ( nonPrintableKeys[3].min <= uniChar && uniChar <= nonPrintableKeys[3].max ) || - ( nonPrintableKeys[4].min <= uniChar && uniChar <= nonPrintableKeys[4].max ) ) { + ( nonPrintableKeys[2].min <= uniChar && uniChar <= nonPrintableKeys[2].max ) || + ( nonPrintableKeys[3].min <= uniChar && uniChar <= nonPrintableKeys[3].max ) ) { return false; } } else { if( ( nonPrintableKeys[0].inclKeyChar && nonPrintableKeys[0].min <= uniChar && uniChar <= nonPrintableKeys[0].max ) || ( nonPrintableKeys[1].inclKeyChar && nonPrintableKeys[1].min <= uniChar && uniChar <= nonPrintableKeys[1].max ) || ( nonPrintableKeys[2].inclKeyChar && nonPrintableKeys[2].min <= uniChar && uniChar <= nonPrintableKeys[2].max ) || - ( nonPrintableKeys[3].inclKeyChar && nonPrintableKeys[3].min <= uniChar && uniChar <= nonPrintableKeys[3].max ) || - ( nonPrintableKeys[4].inclKeyChar && nonPrintableKeys[4].min <= uniChar && uniChar <= nonPrintableKeys[4].max ) ) { + ( nonPrintableKeys[3].inclKeyChar && nonPrintableKeys[3].min <= uniChar && uniChar <= nonPrintableKeys[3].max ) ) { return false; } } - return true; + return VK_UNDEFINED != uniChar; } /** @@ -383,10 +381,19 @@ public class KeyEvent extends InputEvent this.inclKeyChar = inclKeyChar; } }; - /** Non printable key ranges, currently fixed to an array of size 5. */ + /** + * Non printable key ranges, currently fixed to an array of size 4. + * <p> + * Not included, queried upfront: + * <ul> + * <li>{@link #VK_BACK_SPACE}</li> + * <li>{@link #VK_TAB}</li> + * <li>{@link #VK_ENTER}</li> + * </ul> + * </p> + */ public final static NonPrintableRange[] nonPrintableKeys = { - new NonPrintableRange( (short)0x0000, (short)0x0007, true ), // Unicode: Non printable controls: [0x00 - 0x07] - new NonPrintableRange( (short)0x000A, (short)0x001F, true ), // Unicode: Non printable controls: [0x0A - 0x1F] + new NonPrintableRange( (short)0x0000, (short)0x001F, true ), // Unicode: Non printable controls: [0x00 - 0x1F], see exclusion above new NonPrintableRange( (short)0x0061, (short)0x0078, false), // Small 'a' thru 'z' (0x61 - 0x7a) - Not used for keyCode / keySym - Re-used for Fn (collision) new NonPrintableRange( (short)0x008F, (short)0x009F, true ), // Unicode: Non printable controls: [0x7F - 0x9F], Numpad keys [0x7F - 0x8E] are printable! new NonPrintableRange( (short)0xE000, (short)0xF8FF, true ) // Unicode: Private 0xE000 - 0xF8FF (Marked Non-Printable) @@ -433,7 +440,7 @@ public class KeyEvent extends InputEvent /** Constant for the CLEAR key, i.e. FORM FEED, matching ASCII. */ public static final short VK_CLEAR = (short) 0x0C; - /** Constant for the ENTER key, i.e. CARRIAGE RETURN, matching ASCII. Non printable! */ + /** Constant for the ENTER key, i.e. CARRIAGE RETURN, matching ASCII. Printable! */ public static final short VK_ENTER = (short) 0x0D; static final short VK_FREE0E = (short) 0x0E; diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 600035bf6..f449d185f 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -2567,16 +2567,18 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer if( null != keyboardFocusHandler && !e.isAutoRepeat() ) { consumedE = propagateKeyEvent(e, keyboardFocusHandler); if(DEBUG_KEY_EVENT) { - System.err.println("consumeKeyEvent(kfh): "+e+", keyboardFocusHandler consumed: "+consumedE); + if( consumedE ) { + System.err.println("consumeKeyEvent(kfh): "+e+", consumed: "+consumedE); + } } } - if(DEBUG_KEY_EVENT) { - if( !consumedE ) { - System.err.println("consumeKeyEvent(usr): "+e); + if( !consumedE ) { + for(int i = 0; !consumedE && i < keyListeners.size(); i++ ) { + consumedE = propagateKeyEvent(e, keyListeners.get(i)); + } + if(DEBUG_KEY_EVENT) { + System.err.println("consumeKeyEvent(usr): "+e+", consumed: "+consumedE); } - } - for(int i = 0; !consumedE && i < keyListeners.size(); i++ ) { - consumedE = propagateKeyEvent(e, keyListeners.get(i)); } } diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java index 7a8e683af..393445db0 100644 --- a/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java @@ -291,7 +291,7 @@ public class WindowDriver extends WindowImpl { public final void sendKeyEvent(short eventType, int modifiers, short keyCode, short keySym, char keyChar) { final boolean isModifierKey = KeyEvent.isModifierKey(keySym); // System.err.println("*** sendKeyEvent: event "+KeyEvent.getEventTypeString(eventType)+", keyCode "+toHexString(keyCode)+", keyChar <"+keyChar+">, mods "+toHexString(modifiers)+ - // ", isKeyCodeTracked "+isKeyCodeTracked(keyCode)+", was: pressed "+isKeyPressed(keyCode)+", repeat "+isKeyInAutoRepeat(keyCode)+", printableKey "+KeyEvent.isPrintableKey(keyCode)+" [modifierKey "+isModifierKey+"] - "+System.currentTimeMillis()); + // ", isKeyCodeTracked "+isKeyCodeTracked(keyCode)+", was: pressed "+isKeyPressed(keyCode)+", printableKey "+KeyEvent.isPrintableKey(keyCode, false)+" [modifierKey "+isModifierKey+"] - "+System.currentTimeMillis()); // Reorder: WINDOWS delivery order is PRESSED (t0), TYPED (t0) and RELEASED (t1) -> NEWT order: PRESSED (t0) and RELEASED (t1) // Auto-Repeat: WINDOWS delivers only PRESSED (t0) and TYPED (t0). diff --git a/src/newt/native/KeyEvent.h b/src/newt/native/KeyEvent.h index 59977d565..c0a366a17 100644 --- a/src/newt/native/KeyEvent.h +++ b/src/newt/native/KeyEvent.h @@ -39,9 +39,9 @@ #define J_VK_PRINTSCREEN ( 0x05U ) #define J_VK_BACK_SPACE ( 0x08U ) #define J_VK_TAB ( 0x09U ) -#define J_VK_ENTER ( 0x0AU ) #define J_VK_PAGE_DOWN ( 0x0BU ) #define J_VK_CLEAR ( 0x0CU ) +#define J_VK_ENTER ( 0x0DU ) #define J_VK_SHIFT ( 0x0FU ) #define J_VK_PAGE_UP ( 0x10U ) #define J_VK_CONTROL ( 0x11U ) diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java index 31377025a..1dc104cbb 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java @@ -269,27 +269,27 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB } public class KeyAction implements KeyListener { - public void keyPressed(KeyEvent arg0) { + public void keyPressed(KeyEvent e) { if(userInput) { return; } - - if(arg0.getKeyCode() == KeyEvent.VK_3) { + final short s = e.getKeySymbol(); + if(s == KeyEvent.VK_3) { fontIncr(10); } - else if(arg0.getKeyCode() == KeyEvent.VK_4) { + else if(s == KeyEvent.VK_4) { fontIncr(-10); } - else if(arg0.getKeyCode() == KeyEvent.VK_H) { + else if(s == KeyEvent.VK_H) { switchHeadBox(); } - else if(arg0.getKeyCode() == KeyEvent.VK_F) { + else if(s == KeyEvent.VK_F) { drawFPS = !drawFPS; } - else if(arg0.getKeyCode() == KeyEvent.VK_SPACE) { + else if(s == KeyEvent.VK_SPACE) { nextFontSet(); } - else if(arg0.getKeyCode() == KeyEvent.VK_I) { + else if(s == KeyEvent.VK_I) { userInput = true; setIgnoreInput(true); } @@ -300,15 +300,17 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB return; } if(userInput) { - char c = e.getKeyChar(); - - if(c == 0x0d) { + final short k = e.getKeySymbol(); + if( KeyEvent.VK_ENTER == k ) { userInput = false; setIgnoreInput(false); - } else if(c == 0x08 && userString.length()>0) { + } else if( KeyEvent.VK_BACK_SPACE == k && userString.length()>0) { userString.deleteCharAt(userString.length()-1); - } else if( font.isPrintableChar( c ) ) { - userString.append(c); + } else { + final char c = e.getKeyChar(); + if( font.isPrintableChar( c ) ) { + userString.append(c); + } } } } |