aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp/opengl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-04-11 07:16:19 +0200
committerSven Gothel <[email protected]>2013-04-11 07:16:19 +0200
commitb13868b612689307ebf4e46ee4ede2fd0560e504 (patch)
tree9cff4878336ed678f93998bacac12a26495e19fd /src/test/com/jogamp/opengl
parentf3e0f109ac7f03ef803523af8e965d713b6044db (diff)
NEWT KeyEvent: Use UTF-16 UniCode for key-code and key-symbol exposing well defined key encoding and simplify usage.
Note, we use one collision to reduce key-code range: [0x61 .. 0x78] keyCodes [F1..F24] collide w/ ['a'..'x'] Since keyCode/Sym won't use lower capital a-z, this is a no isssue. KeyEvent: - 'printable' type is being determined by a nonPrintableKeys table, while 'action' type is set in case !printable and !modifier. - public ctor hidden, use create(..) method instead. This allows us to ensure modifier bit are properly set (incl. the keySym one) w/o performance loss. - ctor validates that only one of the type flags is set, printable, modifyable or action. WindowImpl: - Using IntBitfield of 255 bits to track pressed state, while removing the repeat state tracking since it is redundant. The Windows impl. uses a single field to validate whether a key was already repeated or not. - Properly cast keyCode short values to int for tracking! AWTNewtEventFactory, SWTNewtEventFactory: - Add translation of keyCode/Sym from and to NEWT - All tested via: - Newt -> Awt for AWTRobot - OSX CALayer: AWT -> NEWT - SWT tests X11: - Add VK_CONTEXT_MENU mapping (XK_Menu) LinuxEventDeviceTracker: - Fix apostrophe and grave mapping, i.e. to VK_QUOTE and VK_BACK_QUOTE. Adapted all unit tests, especially: - TestNewtKeyCodesAWT: More fine grained keyCode ranges to test using proper keyCode symbols.
Diffstat (limited to 'src/test/com/jogamp/opengl')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java4
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodeModifiersAWT.java97
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodesAWT.java61
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java14
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/NEWTKeyUtil.java56
5 files changed, 131 insertions, 101 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java
index 7106ed7ce..d1b276105 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java
@@ -226,8 +226,8 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase {
{
try {
System.err.println("[K-"+_n+"]");
- AWTRobotUtil.keyPress(_n, _robot, true, KeyEvent.VK_0, 10);
- AWTRobotUtil.keyPress(_n, _robot, false, KeyEvent.VK_0, 0);
+ AWTRobotUtil.newtKeyPress(_n, _robot, true, KeyEvent.VK_0, 10);
+ AWTRobotUtil.newtKeyPress(_n, _robot, false, KeyEvent.VK_0, 0);
Thread.sleep( 40L ) ;
_n++;
if(!_display.isDisposed()) {
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodeModifiersAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodeModifiersAWT.java
index 08a181e10..b075af977 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodeModifiersAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodeModifiersAWT.java
@@ -160,81 +160,90 @@ public class TestNewtKeyCodeModifiersAWT extends UITestCase {
}
@SuppressWarnings("deprecation")
- static void testKeyCodeModifier(Robot robot, NEWTKeyAdapter keyAdapter, int modifierKey, int modifierMask, int keyCode, char keyCharOnly, char keyCharMod) {
+ static void testKeyCodeModifier(Robot robot, NEWTKeyAdapter keyAdapter, short modifierKey, int modifierMask, short keyCode,
+ char keyCharOnly, char keyCharMod) {
keyAdapter.reset();
- AWTRobotUtil.keyPress(0, robot, true, keyCode, 10); // press keyCode
- AWTRobotUtil.keyPress(0, robot, false, keyCode, 100); // release+typed keyCode
+ AWTRobotUtil.newtKeyPress(0, robot, true, keyCode, 10); // press keyCode
+ AWTRobotUtil.newtKeyPress(0, robot, false, keyCode, 100); // release+typed keyCode
robot.waitForIdle();
- for(int j=0; j < 40 && keyAdapter.getQueueSize() < 3; j++) { // wait until events are collected
+ for(int j=0; j < 100 && keyAdapter.getQueueSize() < 3; j++) { // wait until events are collected
robot.delay(100);
}
- AWTRobotUtil.keyPress(0, robot, true, modifierKey, 10); // press MOD
- AWTRobotUtil.keyPress(0, robot, true, keyCode, 10); // press keyCode
- AWTRobotUtil.keyPress(0, robot, false, keyCode, 10); // release+typed keyCode
- AWTRobotUtil.keyPress(0, robot, false, modifierKey, 100); // release MOD
+ AWTRobotUtil.newtKeyPress(0, robot, true, modifierKey, 10); // press MOD
+ AWTRobotUtil.newtKeyPress(0, robot, true, keyCode, 10); // press keyCode
+ AWTRobotUtil.newtKeyPress(0, robot, false, keyCode, 10); // release+typed keyCode
+ AWTRobotUtil.newtKeyPress(0, robot, false, modifierKey, 100); // release MOD
robot.waitForIdle();
- for(int j=0; j < 40 && keyAdapter.getQueueSize() < 3+5; j++) { // wait until events are collected
+ for(int j=0; j < 100 && keyAdapter.getQueueSize() < 3+5; j++) { // wait until events are collected
robot.delay(100);
}
- NEWTKeyUtil.validateKeyAdapterStats(keyAdapter,
- 3 /* press-SI */, 3 /* release-SI */, 2 /* typed-SI */,
+ final int modTypedCount = KeyEvent.NULL_CHAR != keyCharMod ? 2 : -1 ; // ignore due to mods 'isPrintable' impact.
+ NEWTKeyUtil.validateKeyAdapterStats(keyAdapter,
+ 3 /* press-SI */, 3 /* release-SI */, modTypedCount /* typed-SI */,
0 /* press-AR */, 0 /* release-AR */, 0 /* typed-AR */ );
- final List<EventObject> queue = keyAdapter.getQueued();
+ final List<EventObject> queue = keyAdapter.getQueued();
int i=0;
NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, 0, keyCode, keyCharOnly);
NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, 0, keyCode, keyCharOnly);
NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_TYPED, 0, keyCode, keyCharOnly);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, modifierMask, modifierKey, (char)0);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, modifierMask, modifierKey, KeyEvent.NULL_CHAR);
NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, modifierMask, keyCode, keyCharMod);
NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, modifierMask, keyCode, keyCharMod);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_TYPED, modifierMask, keyCode, keyCharMod);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, modifierMask, modifierKey, (char)0);
+ KeyEvent e = (KeyEvent) queue.get(i++);
+ if( KeyEvent.EVENT_KEY_TYPED == e.getEventType() ) { // optional, due to mods 'isPrintable' impact.
+ NEWTKeyUtil.validateKeyEvent(e, KeyEvent.EVENT_KEY_TYPED, modifierMask, keyCode, keyCharMod);
+ e = (KeyEvent) queue.get(i++);
+ }
+ NEWTKeyUtil.validateKeyEvent(e, KeyEvent.EVENT_KEY_RELEASED, modifierMask, modifierKey, KeyEvent.NULL_CHAR);
}
@SuppressWarnings("deprecation")
static void testKeyCodeAllModifierV1(Robot robot, NEWTKeyAdapter keyAdapter) {
- final int m1k = KeyEvent.VK_ALT;
- final int m1m = InputEvent.ALT_MASK;
- final int m2k = KeyEvent.VK_CONTROL;
- final int m2m = InputEvent.CTRL_MASK;
- final int m3k = KeyEvent.VK_SHIFT;
- final int m3m = InputEvent.SHIFT_MASK;
+ final short m1k = KeyEvent.VK_ALT;
+ final int m1m = InputEvent.ALT_MASK;
+ final short m2k = KeyEvent.VK_CONTROL;
+ final int m2m = InputEvent.CTRL_MASK;
+ final short m3k = KeyEvent.VK_SHIFT;
+ final int m3m = InputEvent.SHIFT_MASK;
keyAdapter.reset();
- AWTRobotUtil.keyPress(0, robot, true, m1k, 10); // press MOD1
- AWTRobotUtil.keyPress(0, robot, true, m2k, 10); // press MOD2
- AWTRobotUtil.keyPress(0, robot, true, m3k, 10); // press MOD3
- AWTRobotUtil.keyPress(0, robot, true, KeyEvent.VK_P, 10); // press P
+ AWTRobotUtil.newtKeyPress(0, robot, true, m1k, 10); // press MOD1
+ AWTRobotUtil.newtKeyPress(0, robot, true, m2k, 10); // press MOD2
+ AWTRobotUtil.newtKeyPress(0, robot, true, m3k, 10); // press MOD3
+ AWTRobotUtil.newtKeyPress(0, robot, true, KeyEvent.VK_1, 10); // press P
- AWTRobotUtil.keyPress(0, robot, false, KeyEvent.VK_P, 100); // release+typed P
- AWTRobotUtil.keyPress(0, robot, false, m3k, 10); // release MOD
- AWTRobotUtil.keyPress(0, robot, false, m2k, 10); // release MOD
- AWTRobotUtil.keyPress(0, robot, false, m1k, 10); // release MOD
+ AWTRobotUtil.newtKeyPress(0, robot, false, KeyEvent.VK_1, 100); // release+typed P
+ AWTRobotUtil.newtKeyPress(0, robot, false, m3k, 10); // release MOD
+ AWTRobotUtil.newtKeyPress(0, robot, false, m2k, 10); // release MOD
+ AWTRobotUtil.newtKeyPress(0, robot, false, m1k, 10); // release MOD
robot.waitForIdle();
- for(int j=0; j < 40 && keyAdapter.getQueueSize() < 4+4+1; j++) { // wait until events are collected
+ for(int j=0; j < 100 && keyAdapter.getQueueSize() < 4+4+1; j++) { // wait until events are collected
robot.delay(100);
}
NEWTKeyUtil.validateKeyAdapterStats(keyAdapter,
- 4 /* press-SI */, 4 /* release-SI */, 1 /* typed-SI */,
- 0 /* press-AR */, 0 /* release-AR */, 0 /* typed-AR */ );
+ 4 /* press-SI */, 4 /* release-SI */, -1 /* typed-SI - ignored, since unknow whether printable w/ all mods */,
+ 0 /* press-AR */, 0 /* release-AR */, 0 /* typed-AR */ );
final List<EventObject> queue = keyAdapter.getQueued();
int i=0;
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m, m1k, (char)0);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m|m2m, m2k, (char)0);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m|m2m|m3m, m3k, (char)0);
-
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m|m2m|m3m, KeyEvent.VK_P, (char)0);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, m1m|m2m|m3m, KeyEvent.VK_P, (char)0);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_TYPED, m1m|m2m|m3m, KeyEvent.VK_P, (char)0);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m, m1k, KeyEvent.NULL_CHAR);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m|m2m, m2k, KeyEvent.NULL_CHAR);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m|m2m|m3m, m3k, KeyEvent.NULL_CHAR);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, m1m|m2m|m3m, m3k, (char)0);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, m1m|m2m, m2k, (char)0);
- NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, m1m, m1k, (char)0);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_PRESSED, m1m|m2m|m3m, KeyEvent.VK_1, KeyEvent.NULL_CHAR);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, m1m|m2m|m3m, KeyEvent.VK_1, KeyEvent.NULL_CHAR);
+ KeyEvent e = (KeyEvent) queue.get(i++);
+ if( KeyEvent.EVENT_KEY_TYPED == e.getEventType() ) { // optional, due to mods 'isPrintable' impact.
+ NEWTKeyUtil.validateKeyEvent(e, KeyEvent.EVENT_KEY_TYPED, m1m|m2m|m3m, KeyEvent.VK_1, KeyEvent.NULL_CHAR);
+ e = (KeyEvent) queue.get(i++);
+ }
+ NEWTKeyUtil.validateKeyEvent(e, KeyEvent.EVENT_KEY_RELEASED, m1m|m2m|m3m, m3k, KeyEvent.NULL_CHAR);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, m1m|m2m, m2k, KeyEvent.NULL_CHAR);
+ NEWTKeyUtil.validateKeyEvent((KeyEvent) queue.get(i++), KeyEvent.EVENT_KEY_RELEASED, m1m, m1k, KeyEvent.NULL_CHAR);
}
void testImpl(GLWindow glWindow) throws AWTException, InterruptedException, InvocationTargetException {
@@ -265,8 +274,8 @@ public class TestNewtKeyCodeModifiersAWT extends UITestCase {
testKeyCodeModifier(robot, glWindow1KA, KeyEvent.VK_SHIFT, InputEvent.SHIFT_MASK, KeyEvent.VK_1, '1', '!');
testKeyCodeModifier(robot, glWindow1KA, KeyEvent.VK_SHIFT, InputEvent.SHIFT_MASK, KeyEvent.VK_Y, 'y', 'Y'); // US: Y, DE: Z
testKeyCodeModifier(robot, glWindow1KA, KeyEvent.VK_SHIFT, InputEvent.SHIFT_MASK, KeyEvent.VK_P, 'p', 'P');
- testKeyCodeModifier(robot, glWindow1KA, KeyEvent.VK_CONTROL, InputEvent.CTRL_MASK, KeyEvent.VK_P, 'p', (char)0);
- testKeyCodeModifier(robot, glWindow1KA, KeyEvent.VK_ALT, InputEvent.ALT_MASK, KeyEvent.VK_P, 'p', (char)0);
+ testKeyCodeModifier(robot, glWindow1KA, KeyEvent.VK_CONTROL, InputEvent.CTRL_MASK, KeyEvent.VK_1, '1', KeyEvent.NULL_CHAR);
+ testKeyCodeModifier(robot, glWindow1KA, KeyEvent.VK_ALT, InputEvent.ALT_MASK, KeyEvent.VK_1, '1', KeyEvent.NULL_CHAR);
testKeyCodeAllModifierV1(robot, glWindow1KA);
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodesAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodesAWT.java
index 277924477..fb42141ea 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodesAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtKeyCodesAWT.java
@@ -155,32 +155,35 @@ public class TestNewtKeyCodesAWT extends UITestCase {
testNewtCanvasAWT_Impl(false);
}
+ /** Almost all keyCodes reachable w/o modifiers [shift, alt, ..] on US keyboard! */
static CodeSeg[] codeSegments = new CodeSeg[] {
- new CodeSeg(0x008, 0x008, "bs"),
- // new CodeSeg(0x009, 0x009, "tab"), // TAB functions as focus traversal key
- new CodeSeg(0x00a, 0x00a, "cr"),
- new CodeSeg(0x010, 0x012, "shift, ctrl, alt"),
- new CodeSeg(0x01B, 0x01B, "esc"),
- new CodeSeg(0x020, 0x024, "space, up, down, end, home"),
- new CodeSeg(0x025, 0x028, "cursor"),
- new CodeSeg(0x02C, 0x02F, ", - . /"),
- new CodeSeg(0x030, 0x039, "0 - 9"),
- new CodeSeg(0x03B, 0x03B, ";"),
- new CodeSeg(0x03D, 0x03D, "="),
- new CodeSeg(0x041, 0x05A, "a - z"),
- new CodeSeg(0x05B, 0x05D, "[ \\ ]"),
- // new CodeSeg(0x060, 0x06B, "numpad1"), // can be mapped to normal keycodes
- // new CodeSeg(0x06D, 0x06F, "numpad2"), // can be mapped to normal keycodes
- new CodeSeg(0x07F, 0x07F, "del"),
- // new CodeSeg(0x090, 0x091, "num lock, scroll lock"),
- // new CodeSeg(0x070, 0x07B, "F1 - F12"),
- // new CodeSeg(0x09A, 0x09D, "prt ins hlp meta"),
- new CodeSeg(0x0C0, 0x0C0, "back quote"),
- new CodeSeg(0x0DE, 0x0DE, "quote"),
- // new CodeSeg(0x0E0, 0x0E3, "cursor kp"),
- // new CodeSeg(0x080, 0x08F, "dead-1"),
- // new CodeSeg(0x096, 0x0A2, "& ^ \" < > { }"),
- // new CodeSeg(0x200, 0x20D, "extra-2"), // @ ; ..
+ // new CodeSeg(KeyEvent.VK_HOME, KeyEvent.VK_PRINTSCREEN, "home, end, final, prnt"),
+ new CodeSeg(KeyEvent.VK_BACK_SPACE, KeyEvent.VK_BACK_SPACE, "bs"),
+ // new CodeSeg(KeyEvent.VK_TAB, KeyEvent.VK_TAB, "tab"), // TAB functions as focus traversal key
+ new CodeSeg(KeyEvent.VK_ENTER, KeyEvent.VK_ENTER, "cr"),
+ new CodeSeg(KeyEvent.VK_PAGE_DOWN, KeyEvent.VK_PAGE_DOWN, "pg_down"),
+ new CodeSeg(KeyEvent.VK_SHIFT, KeyEvent.VK_ALT, "shift, pg_up, ctrl, alt"),
+ // new CodeSeg(KeyEvent.VK_ALT_GRAPH, KeyEvent.VK_ALT_GRAPH, "alt_gr"), // AWT Robot produces 0xff7e on X11
+ // new CodeSeg(KeyEvent.VK_SCROLL_LOCK, KeyEvent.VK_SCROLL_LOCK, "scroll lock"),
+ new CodeSeg(KeyEvent.VK_ESCAPE, KeyEvent.VK_ESCAPE, "esc"),
+ new CodeSeg(KeyEvent.VK_SPACE, KeyEvent.VK_SPACE, "space"),
+ new CodeSeg(KeyEvent.VK_QUOTE, KeyEvent.VK_QUOTE, "quote"),
+ new CodeSeg(KeyEvent.VK_COMMA, KeyEvent.VK_SLASH, ", - . /"),
+ new CodeSeg(KeyEvent.VK_0, KeyEvent.VK_9, "0 - 9"),
+ new CodeSeg(KeyEvent.VK_SEMICOLON, KeyEvent.VK_SEMICOLON, ";"),
+ new CodeSeg(KeyEvent.VK_EQUALS, KeyEvent.VK_EQUALS, "="),
+ new CodeSeg(KeyEvent.VK_A, KeyEvent.VK_Z, "a - z"),
+ new CodeSeg(KeyEvent.VK_OPEN_BRACKET, KeyEvent.VK_CLOSE_BRACKET, "[ \\ ]"),
+ new CodeSeg(KeyEvent.VK_BACK_QUOTE, KeyEvent.VK_BACK_QUOTE, "`"),
+ new CodeSeg(KeyEvent.VK_F1, KeyEvent.VK_F8, "f1..f8"),
+ // new CodeSeg(KeyEvent.VK_F1, KeyEvent.VK_F12, "f1..f12"), // f9-f12 may cause some odd desktop functions!
+ new CodeSeg(KeyEvent.VK_DELETE, KeyEvent.VK_DELETE, "del"),
+ // new CodeSeg(KeyEvent.VK_NUMPAD0, KeyEvent.VK_NUMPAD9, "numpad0-9"), // can be mapped to normal keycodes
+ // new CodeSeg(KeyEvent.VK_DECIMAL, KeyEvent.VK_DIVIDE, "numpad ops"), // can be mapped to normal keycodes
+ // new CodeSeg(KeyEvent.VK_NUM_LOCK, KeyEvent.VK_NUM_LOCK, "num lock"),
+ // new CodeSeg(KeyEvent.VK_KP_LEFT, KeyEvent.VK_KP_DOWN, "numpad cursor arrows"),
+ new CodeSeg(KeyEvent.VK_LEFT, KeyEvent.VK_DOWN, "cursor arrows"),
+ // new CodeSeg(KeyEvent.VK_WINDOWS, KeyEvent.VK_HELP, "windows, meta, hlp"),
};
static void testKeyCodes(Robot robot, NEWTKeyAdapter keyAdapter) {
@@ -191,23 +194,23 @@ public class TestNewtKeyCodesAWT extends UITestCase {
final CodeSeg codeSeg = codeSegments[i];
// System.err.println("*** Segment "+codeSeg.description);
int eventCount = 0;
- for(short c=codeSeg.min; c<=codeSeg.max; c++) {
+ for(short c=codeSeg.min; c<=codeSeg.max; c++) {
// System.err.println("*** KeyCode 0x"+Integer.toHexString(c));
try {
- AWTRobotUtil.keyPress(0, robot, true, c, 10);
+ AWTRobotUtil.newtKeyPress(0, robot, true, c, 10);
} catch (Exception e) {
System.err.println("Exception @ AWT Robot.PRESS "+MiscUtils.toHexString(c)+" - "+e.getMessage());
break;
}
eventCount++;
try {
- AWTRobotUtil.keyPress(0, robot, false, c, 100);
+ AWTRobotUtil.newtKeyPress(0, robot, false, c, 100);
} catch (Exception e) {
System.err.println("Exception @ AWT Robot.RELEASE "+MiscUtils.toHexString(c)+" - "+e.getMessage());
break;
}
eventCount++;
- if( KeyEvent.isPrintableKey(c) ) {
+ if( KeyEvent.isPrintableKey(c, false) ) {
eventCount++;
}
robot.waitForIdle();
diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
index 4195711d6..e128123ed 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
@@ -29,6 +29,7 @@
package com.jogamp.opengl.test.junit.util;
import jogamp.newt.WindowImplAccess;
+import jogamp.newt.awt.event.AWTNewtEventFactory;
import java.lang.reflect.InvocationTargetException;
import java.awt.AWTException;
@@ -449,6 +450,19 @@ public class AWTRobotUtil {
return (int) ( System.currentTimeMillis() - t0 ) ;
}
+ /** No validation is performed .. */
+ public static int newtKeyPress(int i, Robot robot, boolean press, short newtKeyCode, int msDelay) {
+ final int keyCode = AWTNewtEventFactory.newtKeyCode2AWTKeyCode(newtKeyCode);
+ final long t0 = System.currentTimeMillis();
+ if(press) {
+ awtRobotKeyPress(robot, keyCode, msDelay);
+ } else {
+ awtRobotKeyRelease(robot, keyCode, msDelay);
+ }
+
+ return (int) ( System.currentTimeMillis() - t0 ) ;
+ }
+
/**
* @param keyCode TODO
* @param counter shall return the number of keys typed (press + release)
diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyUtil.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyUtil.java
index d007d2424..1def57edf 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyUtil.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyUtil.java
@@ -104,7 +104,7 @@ public class NEWTKeyUtil {
missCodes.add(new CodeEvent(c, codeSeg.description, e));
misses++;
}
- if( KeyEvent.isPrintableKey(c) ) {
+ if( KeyEvent.isPrintableKey(c, false) ) {
evtIdx += 3; // w/ TYPED
} else {
evtIdx += 2;
@@ -118,17 +118,17 @@ public class NEWTKeyUtil {
return res;
}
- public static void validateKeyEvent(KeyEvent e, int eventType, int modifier, int keyCode, char keyChar) {
+ public static void validateKeyEvent(KeyEvent e, short eventType, int modifiers, short keyCode, char keyChar) {
if(0 <= eventType) {
Assert.assertTrue("KeyEvent type mismatch, expected 0x"+Integer.toHexString(eventType)+", has "+e, eventType == e.getEventType());
}
- if(0 <= modifier) {
- Assert.assertTrue("KeyEvent modifier mismatch, expected 0x"+Integer.toHexString(modifier)+", has "+e, modifier == e.getModifiers());
+ if(0 <= modifiers) {
+ Assert.assertTrue("KeyEvent modifier mismatch, expected 0x"+Integer.toHexString(modifiers)+", has "+e, modifiers == e.getModifiers());
}
- if(0 < keyCode) {
+ if(KeyEvent.VK_UNDEFINED != keyCode) {
Assert.assertTrue("KeyEvent code mismatch, expected 0x"+Integer.toHexString(keyCode)+", has "+e, keyCode == e.getKeyCode());
}
- if(0 < keyChar) {
+ if(KeyEvent.NULL_CHAR != keyChar) {
Assert.assertTrue("KeyEvent char mismatch, expected 0x"+Integer.toHexString(keyChar)+", has "+e, keyChar == e.getKeyChar());
}
}
@@ -168,17 +168,17 @@ public class NEWTKeyUtil {
* @param keyAdapter
* @param expPressedCountSI number of single key press events
* @param expReleasedCountSI number of single key release events
- * @param expTypedCountSI number of single key types events
+ * @param expTypedCountSI number of single key types events, set to -1 to ignore
* @param expPressedCountAR number of auto-repeat key press events
* @param expReleasedCountAR number of auto-repeat key release events
- * @param expTypedCountAR number of auto-repeat key types events
+ * @param expTypedCountAR number of auto-repeat key types events, set to -1 to ignore
*/
public static void validateKeyAdapterStats(NEWTKeyAdapter keyAdapter,
int expPressedCountSI, int expReleasedCountSI, int expTypedCountSI,
int expPressedCountAR, int expReleasedCountAR, int expTypedCountAR) {
- final int expTotalCountSI = expPressedCountSI + expReleasedCountSI + expTypedCountSI;
- final int expTotalCountAR = expPressedCountAR + expReleasedCountAR + expTypedCountAR;
- final int expTotalCountALL = expTotalCountSI + expTotalCountAR;
+ final int expPressReleaseCountSI = expPressedCountSI + expReleasedCountSI;
+ final int expPressReleaseCountAR = expPressedCountAR + expReleasedCountAR;
+ final int expPressReleaseCountALL = expPressReleaseCountSI + expPressReleaseCountAR;
final int keyPressedALL = keyAdapter.getKeyPressedCount(false);
final int keyPressedAR = keyAdapter.getKeyPressedCount(true);
@@ -191,35 +191,39 @@ public class NEWTKeyUtil {
final int keyReleasedSI = keyReleasedALL-keyReleasedAR;
final int keyTypedSI = keyTypedALL-keyTypedAR;
- final int totalCountALL = keyPressedALL + keyReleasedALL + keyTypedALL;
- final int totalCountSI = keyPressedSI + keyReleasedSI + keyTypedSI;
- final int totalCountAR = keyPressedAR + keyReleasedAR + keyTypedAR;
+ final int pressReleaseCountALL = keyPressedALL + keyReleasedALL;
+ final int pressReleaseCountSI = keyPressedSI + keyReleasedSI;
+ final int pressReleaseCountAR = keyPressedAR + keyReleasedAR;
- System.err.println("Expec Single Press "+expPressedCountSI +", Release "+expReleasedCountSI +", Typed "+expTypedCountSI +", Events "+expTotalCountSI);
- System.err.println("Expec AutoRp Press "+expPressedCountAR +", Release "+expReleasedCountAR +", Typed "+expTypedCountAR +", Events "+expTotalCountAR);
+ System.err.println("Expec Single Press "+expPressedCountSI +", Release "+expReleasedCountSI +", Typed "+expTypedCountSI);
+ System.err.println("Expec AutoRp Press "+expPressedCountAR +", Release "+expReleasedCountAR +", Typed "+expTypedCountAR);
- System.err.println("Total Single Press "+keyPressedSI +", Release "+keyReleasedSI +", Typed "+keyTypedSI +", Events "+totalCountSI);
- System.err.println("Total AutoRp Press "+keyPressedAR +", Release "+keyReleasedAR +", Typed "+keyTypedAR +", Events "+totalCountAR);
- System.err.println("Total ALL Press "+keyPressedALL +", Release "+keyReleasedALL +", Typed "+keyTypedALL+", Events "+totalCountALL);
+ System.err.println("Total Single Press "+keyPressedSI +", Release "+keyReleasedSI +", Typed "+keyTypedSI +", Events "+pressReleaseCountSI);
+ System.err.println("Total AutoRp Press "+keyPressedAR +", Release "+keyReleasedAR +", Typed "+keyTypedAR +", Events "+pressReleaseCountAR);
+ System.err.println("Total ALL Press "+keyPressedALL +", Release "+keyReleasedALL +", Typed "+keyTypedALL+", Events "+pressReleaseCountALL);
- Assert.assertEquals("Internal Error: totalSI != totalALL - totalAR", totalCountSI, totalCountALL - totalCountAR);
+ Assert.assertEquals("Internal Error: pressReleaseSI != pressReleaseALL - pressReleaseAR", pressReleaseCountSI, pressReleaseCountALL - pressReleaseCountAR);
Assert.assertEquals("Invalid: Has AR Typed events", 0, keyTypedAR);
- Assert.assertEquals("Invalid: Exp AR Typed events", 0, expTypedCountAR);
+ if( 0 <= expTypedCountAR ) {
+ Assert.assertEquals("Invalid: Exp AR Typed events", 0, expTypedCountAR);
+ }
Assert.assertEquals("Key press count failure (SI)", expPressedCountSI, keyPressedSI);
Assert.assertEquals("Key released count failure (SI)", expReleasedCountSI, keyReleasedSI);
- Assert.assertEquals("Key typed count failure (SI)", expTypedCountSI, keyTypedSI);
+ if( 0 <= expTypedCountSI ) {
+ Assert.assertEquals("Key typed count failure (SI)", expTypedCountSI, keyTypedSI);
+ }
Assert.assertEquals("Key press count failure (AR)", expPressedCountAR, keyPressedAR);
Assert.assertEquals("Key released count failure (AR)", expReleasedCountAR, keyReleasedAR);
- Assert.assertEquals("Key total count failure (SI)", expTotalCountSI, totalCountSI);
- Assert.assertEquals("Key total count failure (AR)", expTotalCountAR, totalCountAR);
+ Assert.assertEquals("Key pressRelease count failure (SI)", expPressReleaseCountSI, pressReleaseCountSI);
+ Assert.assertEquals("Key pressRelease count failure (AR)", expPressReleaseCountAR, pressReleaseCountAR);
final List<EventObject> keyEvents = keyAdapter.getQueued();
- Assert.assertEquals("Key total count failure (ALL) w/ list sum ", expTotalCountALL, totalCountALL);
- Assert.assertEquals("Key total count failure (ALL) w/ list size ", expTotalCountALL, keyEvents.size());
+ Assert.assertEquals("Key pressRelease count failure (ALL) w/ list sum ", expPressReleaseCountALL, pressReleaseCountALL);
+ Assert.assertEquals("Key total count failure (ALL) w/ list size ", pressReleaseCountALL + keyTypedALL, keyEvents.size());
}
}