diff options
author | Sven Gothel <[email protected]> | 2012-10-31 04:04:39 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-10-31 04:04:39 +0100 |
commit | b62e1d027c289877686d6008ea8dd40e4e1541ec (patch) | |
tree | f0af41cb2c9bdd92c37192880439843de1b85f32 /src/newt/classes/com/jogamp | |
parent | dda5e1611fc41089a5f8d486435d3d2d7e9b76d6 (diff) |
Fix NEWT KeyEvent: Deliver keyChar w/ pressed and released; Deliver proper modified flags and modifier-key events; Simplify Windows key handling
Preface: Modifier-keys are SHIFT, CTRL, ALT and META and they have a matching modifier-bit.
- Simplify Windows key handling
- Employ MapVirtualKey(..) for virtual-key to character and scancode to virtual-key mappings,
allowing to drop tracking of keyCode to keyChar in java code.
This also removes the platform restriction of delivering keyChar at TYPED only.
- Deliver keyChar w/ pressed and released
- Due to the lift restriction on the Windows platform (see above),
we can deliver keyChar w/ all key events on all platforms.
- Deliver proper modified flags and modifier-key events
All modifier-keys deliver pressed, released and typed events
with their modifier-bit set.
The above is covered by unit tests, which passed on X11, Windows and OSX (manual test run).
Diffstat (limited to 'src/newt/classes/com/jogamp')
-rw-r--r-- | src/newt/classes/com/jogamp/newt/event/KeyEvent.java | 111 |
1 files changed, 67 insertions, 44 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/KeyEvent.java b/src/newt/classes/com/jogamp/newt/event/KeyEvent.java index 8d3d9e88f..927c9aa85 100644 --- a/src/newt/classes/com/jogamp/newt/event/KeyEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/KeyEvent.java @@ -59,6 +59,10 @@ package com.jogamp.newt.event; * The idea is if you mask out auto-repeat in your event listener * you just get one long pressed key D/U/T triple. * </p> + * <p> + * {@link #isModifierKey() Modifiers keys} will produce regular events (pressed, released and typed), + * however they will not produce Auto-Repeat events itself. + * </p> */ @SuppressWarnings("serial") public class KeyEvent extends InputEvent @@ -69,12 +73,12 @@ public class KeyEvent extends InputEvent this.keyChar=keyChar; } - /** Only valid on all platforms at {@link KeyListener#keyTyped(KeyEvent)} */ + /** Returns the character matching the {@link #getKeyCode() virtual key code}, if exist. */ public char getKeyChar() { return keyChar; } - /** Always valid. */ + /** Returns the virtual key code. */ public int getKeyCode() { return keyCode; } @@ -100,49 +104,68 @@ public class KeyEvent extends InputEvent } } - public boolean isActionKey() { + /** Returns true if <code>keyCode</code> represents a modifier key, i.e. one of {@link #VK_SHIFT}, {@link #VK_CONTROL}, {@link #VK_ALT}, {@link #VK_ALT_GRAPH}, {@link #VK_META}. */ + public static boolean isModifierKey(int keyCode) { + switch (keyCode) { + case VK_SHIFT: + case VK_CONTROL: + case VK_ALT: + case VK_ALT_GRAPH: + case VK_META: + return true; + default: + return false; + } + } + + /** Returns true if {@link #getKeyCode()} represents a modifier key, i.e. one of {@link #VK_SHIFT}, {@link #VK_CONTROL}, {@link #VK_ALT}, {@link #VK_ALT_GRAPH}, {@link #VK_META}. */ + public boolean isModifierKey() { + return isModifierKey(keyCode); + } + + public boolean isActionKey() { switch (keyCode) { - case VK_HOME: - case VK_END: - case VK_PAGE_UP: - case VK_PAGE_DOWN: - case VK_UP: - case VK_DOWN: - case VK_LEFT: - case VK_RIGHT: - - case VK_F1: - case VK_F2: - case VK_F3: - case VK_F4: - case VK_F5: - case VK_F6: - case VK_F7: - case VK_F8: - case VK_F9: - case VK_F10: - case VK_F11: - case VK_F12: - case VK_F13: - case VK_F14: - case VK_F15: - case VK_F16: - case VK_F17: - case VK_F18: - case VK_F19: - case VK_F20: - case VK_F21: - case VK_F22: - case VK_F23: - case VK_F24: - case VK_PRINTSCREEN: - case VK_CAPS_LOCK: - case VK_PAUSE: - case VK_INSERT: - - case VK_HELP: - case VK_WINDOWS: - return true; + case VK_HOME: + case VK_END: + case VK_PAGE_UP: + case VK_PAGE_DOWN: + case VK_UP: + case VK_DOWN: + case VK_LEFT: + case VK_RIGHT: + + case VK_F1: + case VK_F2: + case VK_F3: + case VK_F4: + case VK_F5: + case VK_F6: + case VK_F7: + case VK_F8: + case VK_F9: + case VK_F10: + case VK_F11: + case VK_F12: + case VK_F13: + case VK_F14: + case VK_F15: + case VK_F16: + case VK_F17: + case VK_F18: + case VK_F19: + case VK_F20: + case VK_F21: + case VK_F22: + case VK_F23: + case VK_F24: + case VK_PRINTSCREEN: + case VK_CAPS_LOCK: + case VK_PAUSE: + case VK_INSERT: + + case VK_HELP: + case VK_WINDOWS: + return true; } return false; } |