From c6659f88a4ccf2ade2febfef17305ea0bcfbd1b8 Mon Sep 17 00:00:00 2001 From: Caspian Rychlik-Prince Date: Wed, 28 Aug 2002 21:58:14 +0000 Subject: [PATCH] Stuff --- src/java/org/lwjgl/input/Joystick.java | 13 +++ src/java/org/lwjgl/input/Keyboard.java | 140 +++++++++++++++++++++++++ src/java/org/lwjgl/input/Mouse.java | 12 +++ 3 files changed, 165 insertions(+) diff --git a/src/java/org/lwjgl/input/Joystick.java b/src/java/org/lwjgl/input/Joystick.java index 4067f889..7280674e 100644 --- a/src/java/org/lwjgl/input/Joystick.java +++ b/src/java/org/lwjgl/input/Joystick.java @@ -178,6 +178,19 @@ public class Joystick { return nHasZValue(); } + /** + * See if a particular mouse button is down. + * + * @param button The index of the button you wish to test (0..getNumButtons()) + * @return true if the specified button is down + * @see #getNumButtons() + */ + public static boolean isButtonDown(int button) { + assert created : "The joystick has not been created."; + return Joystick.button[button]; + } + + /** * Native implementation of hasZValue() */ diff --git a/src/java/org/lwjgl/input/Keyboard.java b/src/java/org/lwjgl/input/Keyboard.java index 8a2a6e9e..3a31ed75 100644 --- a/src/java/org/lwjgl/input/Keyboard.java +++ b/src/java/org/lwjgl/input/Keyboard.java @@ -173,6 +173,128 @@ public class Keyboard { public static final int KEY_POWER = 0xDE; public static final int KEY_SLEEP = 0xDF; + // Maps keycodes to ascii characters + private static final char map[] = + { + 0, + 0, + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + '0', + '-', + '=', + 0, + 0, + 'q', + 'w', + 'e', + 'r', + 't', + 'y', + 'u', + 'i', + 'o', + 'p', + '[', + ']', + '*', + '*', + 'a', + 's', + 'd', + 'f', + 'g', + 'h', + 'j', + 'k', + 'l', + ';', + '\'', + '#', + '*', + '\\', + 'z', + 'x', + 'c', + 'v', + 'b', + 'n', + 'm', + ',', + '.', + '/', + '*', + '*', + '*', + ' ' }; + private static final char shiftMap[] = + { + 0, + 0, + '!', + '"', + '*', + '$', + '%', + '^', + '&', + '*', + '(', + ')', + '_', + '+', + '*', + '*', + 'Q', + 'W', + 'E', + 'R', + 'T', + 'Y', + 'U', + 'I', + 'O', + 'P', + '{', + '}', + 0, + 0, + 'A', + 'S', + 'D', + 'F', + 'G', + 'H', + 'J', + 'K', + 'L', + ':', + '@', + '~', + 0, + '|', + 'Z', + 'X', + 'C', + 'V', + 'B', + 'N', + 'M', + '<', + '>', + '?', + 0, + 0, + 0, + ' ' }; + static { initialize(); } @@ -344,4 +466,22 @@ public class Keyboard { return false; } + + /** + * Maps a keycode to a character. + * @param keyCode The keycode + * @return the corresponding ASCII character or 0 if no mapping is possible + */ + public static char map(int keyCode) { + char c; + + if (keyCode < 0 || keyCode >= map.length) + return 0; + else if (isKeyDown(KEY_LSHIFT) || isKeyDown(KEY_RSHIFT)) { + c = shiftMap[keyCode]; + } else { + c = map[keyCode]; + } + return c; + } } diff --git a/src/java/org/lwjgl/input/Mouse.java b/src/java/org/lwjgl/input/Mouse.java index 6f2f3fa4..c430eea1 100644 --- a/src/java/org/lwjgl/input/Mouse.java +++ b/src/java/org/lwjgl/input/Mouse.java @@ -181,6 +181,18 @@ public class Mouse { */ private static native boolean nHasZValue(); + /** + * See if a particular mouse button is down. + * + * @param button The index of the button you wish to test (0..getNumButtons()) + * @return true if the specified button is down + * @see #getNumButtons() + */ + public static boolean isButtonDown(int button) { + assert created : "The mouse has not been created."; + return Mouse.button[button]; + } + /** * Enable mouse buffering. Must be called after the mouse is created. * @return the size of the mouse buffer in events, or 0 if no buffering