This commit is contained in:
Caspian Rychlik-Prince 2002-08-28 21:58:14 +00:00
parent b5fab4fcc6
commit c6659f88a4
3 changed files with 165 additions and 0 deletions

View File

@ -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()
*/

View File

@ -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;
}
}

View File

@ -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