summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-05-16 21:33:25 +0200
committerSven Gothel <[email protected]>2013-05-16 21:33:25 +0200
commit86a5460c5052cdab7b9f6294c46a0b4e30dfa260 (patch)
tree5c029a5d847fe6f7856098e5c734dd621cd31c9d /src
parent890dabf77593732bd9833350b441a37c60f74d45 (diff)
Fix Bug 723: Remove VK_KP_<Cursor> numpad key-codes, use general VK_<Cursor> key-codes; Respect numpad printable keys; Use keySym for numpad if possible.
- KeyEvent keyCode/keySym values re-ordered! - Remove VK_KP_<Cursor> numpad key-codes, use general VK_<Cursor> key-codes. Numpad cursor keys are not supported on some platforms (Windows), or not configured on most X11 configurations. - Respect numpad printable keys, i.e. don't treat them as non-printable. - Use keySym for numpad if possible. Numpad keys require modifiers, hence X11 and Windows shall return keySym.
Diffstat (limited to 'src')
-rw-r--r--src/newt/classes/com/jogamp/newt/event/KeyEvent.java61
-rw-r--r--src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java12
-rw-r--r--src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java4
-rw-r--r--src/newt/native/KeyEvent.h20
-rw-r--r--src/newt/native/WindowsWindow.c42
-rw-r--r--src/newt/native/X11Display.c24
6 files changed, 83 insertions, 80 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/KeyEvent.java b/src/newt/classes/com/jogamp/newt/event/KeyEvent.java
index 45bccf964..6e63ad3a3 100644
--- a/src/newt/classes/com/jogamp/newt/event/KeyEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/KeyEvent.java
@@ -327,7 +327,6 @@ public class KeyEvent extends InputEvent
( 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 ) ||
@@ -391,12 +390,14 @@ public class KeyEvent extends InputEvent
this.max = max;
this.inclKeyChar = inclKeyChar;
}
- };
- /** Non printable key ranges, currently fixed to an aray of size 4. */
- public final static NonPrintableRange[] nonPrintableKeys = { new NonPrintableRange( (short)0x0000, (short)0x001F, true ),
- new NonPrintableRange( (short)0x0061, (short)0x0078, false),
- new NonPrintableRange( (short)0x007F, (short)0x009F, true ),
- new NonPrintableRange( (short)0xE000, (short)0xF8FF, true ) };
+ };
+ /** Non printable key ranges, currently fixed to an array of size 4. */
+ public final static NonPrintableRange[] nonPrintableKeys = {
+ new NonPrintableRange( (short)0x0000, (short)0x001F, true ), // Unicode: Non printable controls: [0x00 - 0x1F]
+ 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)
+ };
//
// Unicode: Non printable controls: [0x00 - 0x1F]
@@ -657,7 +658,7 @@ public class KeyEvent extends InputEvent
/** Constant for the "`" key */
public static final short VK_BACK_QUOTE = (short) 0x60;
- /** Small UTF/ASCII 'a' thru 'z' (0x61 - 0x7a) - Not used for keyCode / keySym. */
+ /** Small UTF/ASCII 'a' thru 'z' (0x61 - 0x7a) - Not used for keyCode / keySym. */
/**
* Constant for the F<i>n</i> function keys.
@@ -754,9 +755,11 @@ public class KeyEvent extends InputEvent
//
// Unicode: Non printable controls: [0x7F - 0x9F]
//
+ // Numpad keys [0x7F - 0x8E] are printable
+ //
- /** Constant for the DEL key, matching ASCII. Non printable UTF control. */
- public static final short VK_DELETE = (short) 0x7F;
+ /** Numeric keypad <b>decimal separator</b> key. Non printable UTF control. */
+ public static final short VK_SEPARATOR = (short) 0x7F;
/** Numeric keypad VK_NUMPAD0 thru VK_NUMPAD9 are mapped to UTF control (0x80 - 0x89). Non printable UTF control. */
public static final short VK_NUMPAD0 = (short) 0x80;
@@ -782,49 +785,37 @@ public class KeyEvent extends InputEvent
/** Numeric keypad <b>decimal separator</b> key. Non printable UTF control. */
public static final short VK_DECIMAL = (short) 0x8A;
- /** Numeric keypad <b>decimal separator</b> key. Non printable UTF control. */
- public static final short VK_SEPARATOR = (short) 0x8B;
-
/** Numeric keypad <b>add</b> key. Non printable UTF control. */
- public static final short VK_ADD = (short) 0x8C;
+ public static final short VK_ADD = (short) 0x8B;
/** Numeric keypad <b>subtract</b> key. Non printable UTF control. */
- public static final short VK_SUBTRACT = (short) 0x8D;
+ public static final short VK_SUBTRACT = (short) 0x8C;
/** Numeric keypad <b>multiply</b> key. Non printable UTF control. */
- public static final short VK_MULTIPLY = (short) 0x8E;
+ public static final short VK_MULTIPLY = (short) 0x8D;
/** Numeric keypad <b>divide</b> key. Non printable UTF control. */
- public static final short VK_DIVIDE = (short) 0x8F;
+ public static final short VK_DIVIDE = (short) 0x8E;
- /** Numeric keypad <b>num lock</b> key. Non printable UTF control. */
- public static final short VK_NUM_LOCK = (short) 0x90;
+ /** Constant for the DEL key, matching ASCII. Non printable UTF control. */
+ public static final short VK_DELETE = (short) 0x93;
- /** Numeric keypad <b>left</b> arrow key, for cursor pad see {@link #VK_LEFT}. Non printable UTF control. */
- public static final short VK_KP_LEFT = (short) 0x91;
-
- /** Numeric keypad <b>up</b> arrow key, for cursor pad see {@link #VK_UP}. Non printable UTF control. */
- public static final short VK_KP_UP = (short) 0x92;
-
- /** Constant for the numeric keypad <b>right</b> arrow key, for cursor pad see {@link #VK_RIGHT}. Non printable UTF control. */
- public static final short VK_KP_RIGHT = (short) 0x93;
+ /** Numeric keypad <b>num lock</b> key. Non printable UTF control. */
+ public static final short VK_NUM_LOCK = (short) 0x94;
- /** Numeric keypad <b>down</b> arrow key, for cursor pad see {@link #VK_DOWN}. Non printable UTF control. */
- public static final short VK_KP_DOWN = (short) 0x94;
-
- /** Constant for the cursor-pad <b>left</b> arrow key, for numerical pad see {@link #VK_KP_LEFT}*/
+ /** Constant for the cursor- or numerical-pad <b>left</b> arrow key. Non printable UTF control. */
public static final short VK_LEFT = (short) 0x95;
- /** Constant for the cursor-pad <b>left</b> arrow key, for numerical pad see {@link #VK_KP_UP}.*/
+ /** Constant for the cursor- or numerical-pad <b>up</b> arrow key. Non printable UTF control. */
public static final short VK_UP = (short) 0x96;
- /** Constant for the cursor-pad <b>left</b> arrow key, for numerical pad see {@link #VK_KP_RIGHT}.*/
+ /** Constant for the cursor- or numerical-pad <b>right</b> arrow key. Non printable UTF control. */
public static final short VK_RIGHT = (short) 0x97;
- /** Constant for the cursor-pad <b>left</b> arrow key, for numerical pad see {@link #VK_KP_DOWN}.*/
+ /** Constant for the cursor- or numerical pad <b>down</b> arrow key. Non printable UTF control. */
public static final short VK_DOWN = (short) 0x98;
- /** Constant for the Context Menu key. */
+ /** Constant for the Context Menu key. Non printable UTF control. */
public static final short VK_CONTEXT_MENU = (short) 0x99;
/**
diff --git a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java
index ccbdc07bf..a1aa69e0a 100644
--- a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java
+++ b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java
@@ -369,13 +369,13 @@ public class AWTNewtEventFactory {
case java.awt.event.KeyEvent.VK_MULTIPLY : return com.jogamp.newt.event.KeyEvent.VK_MULTIPLY;
case java.awt.event.KeyEvent.VK_DIVIDE : return com.jogamp.newt.event.KeyEvent.VK_DIVIDE;
case java.awt.event.KeyEvent.VK_NUM_LOCK : return com.jogamp.newt.event.KeyEvent.VK_NUM_LOCK;
- case java.awt.event.KeyEvent.VK_KP_LEFT : return com.jogamp.newt.event.KeyEvent.VK_KP_LEFT;
- case java.awt.event.KeyEvent.VK_KP_UP : return com.jogamp.newt.event.KeyEvent.VK_KP_UP;
- case java.awt.event.KeyEvent.VK_KP_RIGHT : return com.jogamp.newt.event.KeyEvent.VK_KP_RIGHT;
- case java.awt.event.KeyEvent.VK_KP_DOWN : return com.jogamp.newt.event.KeyEvent.VK_KP_DOWN;
+ case java.awt.event.KeyEvent.VK_KP_LEFT : /** Fall through intended .. */
case java.awt.event.KeyEvent.VK_LEFT : return com.jogamp.newt.event.KeyEvent.VK_LEFT;
+ case java.awt.event.KeyEvent.VK_KP_UP : /** Fall through intended .. */
case java.awt.event.KeyEvent.VK_UP : return com.jogamp.newt.event.KeyEvent.VK_UP;
+ case java.awt.event.KeyEvent.VK_KP_RIGHT : /** Fall through intended .. */
case java.awt.event.KeyEvent.VK_RIGHT : return com.jogamp.newt.event.KeyEvent.VK_RIGHT;
+ case java.awt.event.KeyEvent.VK_KP_DOWN : /** Fall through intended .. */
case java.awt.event.KeyEvent.VK_DOWN : return com.jogamp.newt.event.KeyEvent.VK_DOWN;
case java.awt.event.KeyEvent.VK_CONTEXT_MENU : return com.jogamp.newt.event.KeyEvent.VK_CONTEXT_MENU;
case java.awt.event.KeyEvent.VK_WINDOWS : return com.jogamp.newt.event.KeyEvent.VK_WINDOWS;
@@ -550,10 +550,6 @@ public class AWTNewtEventFactory {
case com.jogamp.newt.event.KeyEvent.VK_MULTIPLY : return java.awt.event.KeyEvent.VK_MULTIPLY;
case com.jogamp.newt.event.KeyEvent.VK_DIVIDE : return java.awt.event.KeyEvent.VK_DIVIDE;
case com.jogamp.newt.event.KeyEvent.VK_NUM_LOCK : return java.awt.event.KeyEvent.VK_NUM_LOCK;
- case com.jogamp.newt.event.KeyEvent.VK_KP_LEFT : return java.awt.event.KeyEvent.VK_KP_LEFT;
- case com.jogamp.newt.event.KeyEvent.VK_KP_UP : return java.awt.event.KeyEvent.VK_KP_UP;
- case com.jogamp.newt.event.KeyEvent.VK_KP_RIGHT : return java.awt.event.KeyEvent.VK_KP_RIGHT;
- case com.jogamp.newt.event.KeyEvent.VK_KP_DOWN : return java.awt.event.KeyEvent.VK_KP_DOWN;
case com.jogamp.newt.event.KeyEvent.VK_LEFT : return java.awt.event.KeyEvent.VK_LEFT;
case com.jogamp.newt.event.KeyEvent.VK_UP : return java.awt.event.KeyEvent.VK_UP;
case com.jogamp.newt.event.KeyEvent.VK_RIGHT : return java.awt.event.KeyEvent.VK_RIGHT;
diff --git a/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java b/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java
index 5e240636d..24a5c41de 100644
--- a/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java
+++ b/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java
@@ -189,13 +189,9 @@ public class SWTNewtEventFactory {
case com.jogamp.newt.event.KeyEvent.VK_MULTIPLY : return SWT.KEYPAD_MULTIPLY;
case com.jogamp.newt.event.KeyEvent.VK_DIVIDE : return SWT.KEYPAD_DIVIDE;
case com.jogamp.newt.event.KeyEvent.VK_NUM_LOCK : return SWT.NUM_LOCK;
- case com.jogamp.newt.event.KeyEvent.VK_KP_LEFT :
case com.jogamp.newt.event.KeyEvent.VK_LEFT : return SWT.ARROW_LEFT;
- case com.jogamp.newt.event.KeyEvent.VK_KP_UP :
case com.jogamp.newt.event.KeyEvent.VK_UP : return SWT.ARROW_UP;
- case com.jogamp.newt.event.KeyEvent.VK_KP_RIGHT :
case com.jogamp.newt.event.KeyEvent.VK_RIGHT : return SWT.ARROW_RIGHT;
- case com.jogamp.newt.event.KeyEvent.VK_KP_DOWN :
case com.jogamp.newt.event.KeyEvent.VK_DOWN : return SWT.ARROW_DOWN;
case com.jogamp.newt.event.KeyEvent.VK_HELP : return SWT.HELP;
}
diff --git a/src/newt/native/KeyEvent.h b/src/newt/native/KeyEvent.h
index 7a63b19ce..a182db973 100644
--- a/src/newt/native/KeyEvent.h
+++ b/src/newt/native/KeyEvent.h
@@ -161,7 +161,7 @@
// Unicode: Non printable controls: [0x7F - 0x9F]
//
-#define J_VK_DELETE ( 0x7FU )
+#define J_VK_SEPARATOR ( 0x7FU )
#define J_VK_NUMPAD0 ( 0x80U )
#define J_VK_NUMPAD1 ( 0x81U )
#define J_VK_NUMPAD2 ( 0x82U )
@@ -173,16 +173,13 @@
#define J_VK_NUMPAD8 ( 0x88U )
#define J_VK_NUMPAD9 ( 0x89U )
#define J_VK_DECIMAL ( 0x8AU )
-#define J_VK_SEPARATOR ( 0x8BU )
-#define J_VK_ADD ( 0x8CU )
-#define J_VK_SUBTRACT ( 0x8DU )
-#define J_VK_MULTIPLY ( 0x8EU )
-#define J_VK_DIVIDE ( 0x8FU )
-#define J_VK_NUM_LOCK ( 0x90U )
-#define J_VK_KP_LEFT ( 0x91U )
-#define J_VK_KP_UP ( 0x92U )
-#define J_VK_KP_RIGHT ( 0x93U )
-#define J_VK_KP_DOWN ( 0x94U )
+#define J_VK_ADD ( 0x8BU )
+#define J_VK_SUBTRACT ( 0x8CU )
+#define J_VK_MULTIPLY ( 0x8DU )
+#define J_VK_DIVIDE ( 0x8EU )
+
+#define J_VK_DELETE ( 0x93U )
+#define J_VK_NUM_LOCK ( 0x94U )
#define J_VK_LEFT ( 0x95U )
#define J_VK_UP ( 0x96U )
#define J_VK_RIGHT ( 0x97U )
@@ -195,7 +192,6 @@
#define J_VK_BEGIN ( 0x9EU )
#define J_VK_STOP ( 0x9FU )
-
//
// Unicode: Printable [0x00A0 - 0xDFFF]
//
diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c
index 7ede3a20d..ac0ebf07e 100644
--- a/src/newt/native/WindowsWindow.c
+++ b/src/newt/native/WindowsWindow.c
@@ -219,6 +219,7 @@ static KeyMapEntry keyMapTable[] = {
{J_VK_INSERT, VK_INSERT, 0},
{J_VK_DELETE, VK_DELETE, 0},
{J_VK_HOME, VK_HOME, 0},
+ // {J_VK_BEGIN, VK_BEGIN, 0}, // not mapped
{J_VK_END, VK_END, 0},
{J_VK_PAGE_UP, VK_PRIOR, 0},
{J_VK_PAGE_DOWN, VK_NEXT, 0},
@@ -332,6 +333,8 @@ static KeyMapEntry keyMapTable[] = {
#define MAPVK_VK_TO_VSC_EX 4
#endif
+#define IS_WITHIN(k,a,b) ((a)<=(k)&&(k)<=(b))
+
static HKL kbdLayoutUS = 0;
static const LPCSTR US_LAYOUT_NAME = "00000409";
@@ -398,23 +401,6 @@ static void ParseWmVKeyAndScanCode(USHORT winVKey, BYTE winScanCode, BYTE flags,
kbdState[VK_SPACE] &= ~0x80;
}
- // Assume extended scan code 0xE0 if extended flags is set (no 0xE1 from WM_KEYUP/WM_KEYDOWN)
- USHORT winScanCodeExt = winScanCode;
- if( 0 != ( 0x01 & flags ) ) {
- winScanCodeExt |= 0xE000;
- }
-
- //
- // winVKey, winScanCodeExt -> javaVKeyUS w/ US KeyboardLayout
- //
- for (i = 0; keyMapTable[i].windowsKey != 0; i++) {
- if ( keyMapTable[i].windowsScanCodeUS == winScanCodeExt ) {
- javaVKeyUS = keyMapTable[i].javaKey;
- winVKeyUS = keyMapTable[i].windowsKey;
- break;
- }
- }
-
//
// winVKey -> javaVKeyXX
//
@@ -424,6 +410,28 @@ static void ParseWmVKeyAndScanCode(USHORT winVKey, BYTE winScanCode, BYTE flags,
break;
}
}
+ if( IS_WITHIN( winVKey, VK_NUMPAD0, VK_DIVIDE ) ) {
+ // Use modded keySym for keypad for US and NN
+ winVKeyUS = winVKey;
+ javaVKeyUS = javaVKeyXX;
+ } else {
+ // Assume extended scan code 0xE0 if extended flags is set (no 0xE1 from WM_KEYUP/WM_KEYDOWN)
+ USHORT winScanCodeExt = winScanCode;
+ if( 0 != ( 0x01 & flags ) ) {
+ winScanCodeExt |= 0xE000;
+ }
+
+ //
+ // winVKey, winScanCodeExt -> javaVKeyUS w/ US KeyboardLayout
+ //
+ for (i = 0; keyMapTable[i].windowsKey != 0; i++) {
+ if ( keyMapTable[i].windowsScanCodeUS == winScanCodeExt ) {
+ winVKeyUS = keyMapTable[i].windowsKey;
+ javaVKeyUS = keyMapTable[i].javaKey;
+ break;
+ }
+ }
+ }
*outJavaVKeyUS = javaVKeyUS;
*outJavaVKeyXX = javaVKeyXX;
diff --git a/src/newt/native/X11Display.c b/src/newt/native/X11Display.c
index 56b7251d2..e2392a113 100644
--- a/src/newt/native/X11Display.c
+++ b/src/newt/native/X11Display.c
@@ -58,6 +58,10 @@ static jmethodID requestFocusID = NULL;
#define IS_WITHIN(k,a,b) ((a)<=(k)&&(k)<=(b))
+/**
+ * QT Reference:
+ * <http://qt.gitorious.org/qt/qt/blobs/4.7/src/gui/kernel/qkeymapper_x11.cpp#line879>
+ */
static short X11KeySym2NewtVKey(KeySym keySym) {
if( IS_WITHIN( keySym, XK_a, XK_z ) ) {
return ( keySym - XK_a ) + J_VK_A ;
@@ -84,8 +88,6 @@ static short X11KeySym2NewtVKey(KeySym keySym) {
return J_VK_TAB;
case XK_Cancel:
return J_VK_CANCEL;
- case XK_Clear:
- return J_VK_CLEAR;
case XK_Shift_L:
case XK_Shift_R:
return J_VK_SHIFT;
@@ -95,6 +97,7 @@ static short X11KeySym2NewtVKey(KeySym keySym) {
case XK_Alt_L:
return J_VK_ALT;
case XK_Alt_R:
+ case XK_ISO_Level3_Shift:
return J_VK_ALT_GRAPH;
case XK_Super_L:
case XK_Super_R:
@@ -119,6 +122,10 @@ static short X11KeySym2NewtVKey(KeySym keySym) {
case XK_End:
case XK_KP_End:
return J_VK_END;
+ case XK_Begin:
+ return J_VK_BEGIN;
+ case XK_KP_Begin: // NumPad 5 - equal behavior w/ QT/Windows
+ return J_VK_CLEAR;
case XK_Home:
case XK_KP_Home:
return J_VK_HOME;
@@ -146,6 +153,7 @@ static short X11KeySym2NewtVKey(KeySym keySym) {
return J_VK_DECIMAL;
case XK_KP_Divide:
return J_VK_DIVIDE;
+ case XK_Clear: // equal behavior w/ QT
case XK_Delete:
case XK_KP_Delete:
return J_VK_DELETE;
@@ -450,7 +458,15 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessage
keyString = (*env)->NewStringUTF(env, text);
}
- if( 0 == keyChar ) {
+ #ifdef DEBUG_KEYS
+ fprintf(stderr, "NEWT X11 Key.0: keyCode 0x%X keySym 0x%X, (shifted: 0x%X)\n",
+ (int)keyCode, (int)keySym, (int) shiftedKeySym);
+ #endif
+ if( IS_WITHIN( shiftedKeySym, XK_KP_Space, XK_KP_9 ) ) {
+ // Use modded keySym for keypad for US and NN
+ keySym = shiftedKeySym;
+ unShiftedKeySym = shiftedKeySym;
+ } else if( 0 == keyChar ) {
// Use keyCode's keySym for dead-key (aka modifiers, etc)
unShiftedKeySym = keySym;
} else if( 0 == ( evt.xkey.state & ShiftCtrlModMask ) ) {
@@ -467,7 +483,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessage
modifiers |= X11InputState2NewtModifiers(xkey_state, javaVKeyNN, evt.type == KeyPress) | autoRepeatModifiers;
#ifdef DEBUG_KEYS
- fprintf(stderr, "NEWT X11 Key: keyCode 0x%X keySym 0x%X, (0x%X, shifted: 0x%X), keyChar '%c' 0x%X %d, javaVKey[US 0x%X, NN 0x%X], xstate 0x%X %u, jmods 0x%X\n",
+ fprintf(stderr, "NEWT X11 Key.X: keyCode 0x%X keySym 0x%X, (0x%X, shifted: 0x%X), keyChar '%c' 0x%X %d, javaVKey[US 0x%X, NN 0x%X], xstate 0x%X %u, jmods 0x%X\n",
(int)keyCode, (int)keySym, (int) unShiftedKeySym, (int)shiftedKeySym, keyChar, keyChar, charCount,
(int)javaVKeyUS, (int)javaVKeyNN,
(int)xkey_state, (int)xkey_state, (int)modifiers);