summaryrefslogtreecommitdiffstats
path: root/src/newt/classes
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-04-08 23:02:00 +0200
committerSven Gothel <[email protected]>2013-04-08 23:02:00 +0200
commitd2fc229b844942646fd9a32fc943923a5770a4be (patch)
treed4032ccba1f2c9f14d091ebec62aa781295a495e /src/newt/classes
parent6755fc707672a77025bcde81a47a5e4d93b37fb1 (diff)
Bug 641 NEWT/OSX Deliver keySym, derived from the current layout's lower-case UTF-16 character.
Diffstat (limited to 'src/newt/classes')
-rw-r--r--src/newt/classes/com/jogamp/newt/event/UTFKeyUtil.java82
-rw-r--r--src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java21
2 files changed, 99 insertions, 4 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/UTFKeyUtil.java b/src/newt/classes/com/jogamp/newt/event/UTFKeyUtil.java
new file mode 100644
index 000000000..73afa0993
--- /dev/null
+++ b/src/newt/classes/com/jogamp/newt/event/UTFKeyUtil.java
@@ -0,0 +1,82 @@
+/**
+ * Copyright 2013 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.newt.event;
+
+import com.jogamp.newt.event.KeyEvent;
+
+public class UTFKeyUtil {
+
+ //
+ // UTF Key Constants
+ //
+ private static final char UTF_Equal = '=';
+ private static final char UTF_Minus = '-';
+ private static final char UTF_RightBracket = ']';
+ private static final char UTF_LeftBracket = '[';
+ private static final char UTF_Quote = '\'';
+ private static final char UTF_Semicolon = ';';
+ private static final char UTF_Backslash = '\\';
+ private static final char UTF_Comma = ',';
+ private static final char UTF_Slash = '/';
+ private static final char UTF_Period = '.';
+ private static final char UTF_Grave = '`'; // back quote
+
+ /**
+ * @param keyChar UTF16 value to map. Note: Lower case values are preferred.
+ * @return {@link KeyEvent} virtual key (VK) value if possible,
+ * otherwise simply the UTF16 value of type short as a last resort.
+ */
+ public static short utf16ToVKey(char keyChar) {
+ if( 'a' <= keyChar && keyChar <= 'z' ) {
+ return (short) ( ( keyChar - 'a' ) + KeyEvent.VK_A );
+ }
+ if( '0' <= keyChar && keyChar <= '9' ) {
+ return (short) ( ( keyChar - '0' ) + KeyEvent.VK_0 );
+ }
+ switch(keyChar) {
+ //
+ // KeyCodes (Layout Dependent)
+ //
+ case UTF_Equal: return KeyEvent.VK_EQUALS;
+ case UTF_Minus: return KeyEvent.VK_MINUS;
+ case UTF_RightBracket: return KeyEvent.VK_CLOSE_BRACKET;
+ case UTF_LeftBracket: return KeyEvent.VK_OPEN_BRACKET;
+ case UTF_Quote: return KeyEvent.VK_QUOTE;
+ case UTF_Semicolon: return KeyEvent.VK_SEMICOLON;
+ case UTF_Backslash: return KeyEvent.VK_BACK_SLASH;
+ case UTF_Comma: return KeyEvent.VK_COMMA;
+ case UTF_Slash: return KeyEvent.VK_SLASH;
+ case UTF_Period: return KeyEvent.VK_PERIOD;
+ case UTF_Grave: return KeyEvent.VK_BACK_QUOTE; // KeyEvent.VK_DEAD_GRAVE
+ }
+ if( 'A' <= keyChar && keyChar <= 'Z' ) {
+ return (short) ( ( keyChar - 'A' ) + KeyEvent.VK_A );
+ }
+ return (short) keyChar;
+ }
+}
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
index 965138ddf..b1d18e487 100644
--- a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
@@ -51,6 +51,7 @@ import jogamp.newt.driver.DriverUpdatePosition;
import com.jogamp.newt.event.InputEvent;
import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.event.UTFKeyUtil;
public class WindowDriver extends WindowImpl implements MutableSurface, DriverClearFocus, DriverUpdatePosition {
@@ -401,13 +402,25 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
}
@Override
- public final void enqueueKeyEvent(boolean wait, short eventType, int modifiers, short _keyCode, short keySym, char keyChar) {
+ public final void enqueueKeyEvent(boolean wait, short eventType, int modifiers, short _keyCode, short _keySym, char keyChar) {
+ throw new InternalError("XXX: Adapt Java Code to Native Code Changes");
+ }
+
+ protected final void enqueueKeyEvent(boolean wait, short eventType, int modifiers, short _keyCode, char keyChar, char keySymChar) {
// Note that we send the key char for the key code on this
// platform -- we do not get any useful key codes out of the system
final short keyCode = MacKeyUtil.validateKeyCode(_keyCode, keyChar);
+ final short keySym;
+ {
+ short _keySym = KeyEvent.NULL_CHAR != keySymChar ? UTFKeyUtil.utf16ToVKey(keySymChar) : KeyEvent.VK_UNDEFINED;
+ keySym = KeyEvent.VK_UNDEFINED != _keySym ? _keySym : keyCode;
+ }
/* {
final boolean isModifierKeyCode = KeyEvent.isModifierKey(keyCode);
- System.err.println("*** handleKeyEvent: event "+KeyEvent.getEventTypeString(eventType)+", key 0x"+Integer.toHexString(_keyCode)+" -> 0x"+Integer.toHexString(keyCode)+", mods "+toHexString(modifiers)+
+ System.err.println("*** handleKeyEvent: event "+KeyEvent.getEventTypeString(eventType)+
+ ", keyCode 0x"+Integer.toHexString(_keyCode)+" -> 0x"+Integer.toHexString(keyCode)+
+ ", keySymChar '"+keySymChar+"', 0x"+Integer.toHexString(keySymChar)+" -> 0x"+Integer.toHexString(keySym)+
+ ", mods "+toHexString(modifiers)+
", was: pressed "+isKeyPressed(keyCode)+", repeat "+isKeyInAutoRepeat(keyCode)+", isModifierKeyCode "+isModifierKeyCode);
} */
@@ -426,12 +439,12 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
// key was already pressed
keyRepeatState.put(keyCode, true); // prev == false -> AR in
modifiers |= InputEvent.AUTOREPEAT_MASK;
- super.enqueueKeyEvent(wait, KeyEvent.EVENT_KEY_RELEASED, modifiers, keyCode, keyCode, keyChar); // RELEASED
+ super.enqueueKeyEvent(wait, KeyEvent.EVENT_KEY_RELEASED, modifiers, keyCode, keySym, keyChar); // RELEASED
}
}
break;
}
- super.enqueueKeyEvent(wait, eventType, modifiers, keyCode, keyCode, keyChar);
+ super.enqueueKeyEvent(wait, eventType, modifiers, keyCode, keySym, keyChar);
}
//----------------------------------------------------------------------