From: Caspian Rychlik-P. <ci...@us...> - 2002-08-28 21:58:18
|
Update of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/input In directory usw-pr-cvs1:/tmp/cvs-serv21286/src/java/org/lwjgl/input Modified Files: Joystick.java Mouse.java Keyboard.java Log Message: Stuff Index: Joystick.java CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/java/org/lwjgl/input/Joystick.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/input/Joystick.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Joystick.java 26 Aug 2002 21:05:20 -0000 1.6 +++ Joystick.java 28 Aug 2002 21:58:14 -0000 1.7 @@ -179,6 +179,19 @@ } /** + * 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() */ private static native boolean nHasZValue(); Index: Mouse.java CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/java/org/lwjgl/input/Mouse.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/input/Mouse.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Mouse.java 26 Aug 2002 21:05:20 -0000 1.8 +++ Mouse.java 28 Aug 2002 21:58:14 -0000 1.9 @@ -182,6 +182,18 @@ 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 * can be enabled for any reason Index: Keyboard.java CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/java/org/lwjgl/input/Keyboard.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/input/Keyboard.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Keyboard.java 26 Aug 2002 21:05:20 -0000 1.8 +++ Keyboard.java 28 Aug 2002 21:58:14 -0000 1.9 @@ -173,6 +173,128 @@ 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(); } @@ -343,5 +465,23 @@ } else 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; } } |