fix: isStateKeySet now returning int

This commit is contained in:
Brian Matzon 2003-08-23 09:45:22 +00:00
parent 16ea129071
commit f27e5a294c
4 changed files with 38 additions and 15 deletions

View File

@ -188,6 +188,10 @@ public class Keyboard {
public static final int KEY_APPS = 0xDD; /* AppMenu key */
public static final int KEY_POWER = 0xDE;
public static final int KEY_SLEEP = 0xDF;
public static final int STATE_ON = 0;
public static final int STATE_OFF = 1;
public static final int STATE_UNKNOWN = 2;
/** Key names */
private static final String[] keyName = new String[255];
@ -402,13 +406,13 @@ public class Keyboard {
* Checks whether one of the state keys are "active"
*
* @param key State key to test (KEY_CAPITAL | KEY_NUMLOCK | KEY_SYSRQ)
* @return true if state key is on
* @return STATE_ON if on, STATE_OFF if off and STATE_UNKNOWN if the state is unknown
*/
public static boolean isStateKeySet(int key) {
public static int isStateKeySet(int key) {
assert created : "The keyboard has not been created.";
return nisStateKeySet(key);
}
private static native boolean nisStateKeySet(int key);
private static native int nisStateKeySet(int key);
/**
* Gets a key's name

View File

@ -159,15 +159,15 @@ public class KeyboardTest {
position.y -= 1;
}
if(Keyboard.isStateKeySet(Keyboard.KEY_SCROLL)) {
if(Keyboard.isStateKeySet(Keyboard.KEY_SCROLL) == Keyboard.STATE_ON) {
System.out.println("SCROLL lock on");
}
if(Keyboard.isStateKeySet(Keyboard.KEY_CAPITAL)) {
if(Keyboard.isStateKeySet(Keyboard.KEY_CAPITAL) == Keyboard.STATE_ON) {
System.out.println("CAPS lock on");
}
if(Keyboard.isStateKeySet(Keyboard.KEY_NUMLOCK)) {
if(Keyboard.isStateKeySet(Keyboard.KEY_NUMLOCK) == Keyboard.STATE_ON) {
System.out.println("NUM lock on");
}
}

View File

@ -258,7 +258,16 @@ extern "C" {
#define org_lwjgl_input_Keyboard_KEY_POWER 222L
#undef org_lwjgl_input_Keyboard_KEY_SLEEP
#define org_lwjgl_input_Keyboard_KEY_SLEEP 223L
#undef org_lwjgl_input_Keyboard_STATE_ON
#define org_lwjgl_input_Keyboard_STATE_ON 0L
#undef org_lwjgl_input_Keyboard_STATE_OFF
#define org_lwjgl_input_Keyboard_STATE_OFF 1L
#undef org_lwjgl_input_Keyboard_STATE_UNKNOWN
#define org_lwjgl_input_Keyboard_STATE_UNKNOWN 2L
/* Inaccessible static: keyName */
/* Inaccessible static: keyMap */
/* Inaccessible static: counter */
/* Inaccessible static: keyCount */
/* Inaccessible static: created */
/* Inaccessible static: keyDownBuffer */
/* Inaccessible static: readBuffer */
@ -267,7 +276,8 @@ extern "C" {
/* Inaccessible static: character */
/* Inaccessible static: key */
/* Inaccessible static: state */
/* Inaccessible static: class_00024org_00024lwjgl_00024input_00024Keyboard */
/* Inaccessible static: class_000240 */
/* Inaccessible static: class_000241 */
/*
* Class: org_lwjgl_input_Keyboard
* Method: initIDs
@ -323,13 +333,13 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Keyboard_nEnableTranslation
*/
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nEnableBuffer
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_input_Keyboard
* Method: nisStateKeySet
* Signature: (I)Z
* Signature: (I)I
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Keyboard_nisStateKeySet
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nisStateKeySet
(JNIEnv *, jclass, jint);
#ifdef __cplusplus

View File

@ -335,13 +335,22 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nEnableBuffer
/*
* Class: org_lwjgl_input_Keyboard
* Method: nisStateKeySet
* Signature: (I)Z
* Signature: (I)I
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Keyboard_nisStateKeySet(JNIEnv *env, jclass clazz, jint key)
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nisStateKeySet(JNIEnv *env, jclass clazz, jint key)
{
int state = org_lwjgl_input_Keyboard_STATE_UNKNOWN;
switch(key) {
case org_lwjgl_input_Keyboard_KEY_CAPITAL: return GetKeyState(VK_CAPITAL);
case org_lwjgl_input_Keyboard_KEY_NUMLOCK: return GetKeyState(VK_NUMLOCK);
case org_lwjgl_input_Keyboard_KEY_SCROLL: return GetKeyState(VK_SCROLL);
case org_lwjgl_input_Keyboard_KEY_CAPITAL:
state = GetKeyState(VK_CAPITAL) ? org_lwjgl_input_Keyboard_STATE_ON : org_lwjgl_input_Keyboard_STATE_OFF;
break;
case org_lwjgl_input_Keyboard_KEY_NUMLOCK:
state = GetKeyState(VK_NUMLOCK) ? org_lwjgl_input_Keyboard_STATE_ON : org_lwjgl_input_Keyboard_STATE_OFF;
break;
case org_lwjgl_input_Keyboard_KEY_SCROLL:
state = GetKeyState(VK_SCROLL) ? org_lwjgl_input_Keyboard_STATE_ON : org_lwjgl_input_Keyboard_STATE_OFF;
break;
}
return state;
}