diff --git a/src/java/org/lwjgl/input/Keyboard.java b/src/java/org/lwjgl/input/Keyboard.java index bb1efcef..691f829c 100644 --- a/src/java/org/lwjgl/input/Keyboard.java +++ b/src/java/org/lwjgl/input/Keyboard.java @@ -397,6 +397,18 @@ public class Keyboard { assert created : "The keyboard has not been created."; return keyDownBuffer.get(key) != 0; } + + /** + * 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 + */ + public static boolean isStateKeySet(int key) { + assert created : "The keyboard has not been created."; + return nisStateKeySet(key); + } + private static native boolean nisStateKeySet(int key); /** * Gets a key's name diff --git a/src/java/org/lwjgl/test/input/KeyboardTest.java b/src/java/org/lwjgl/test/input/KeyboardTest.java index a085cfba..7077b89d 100644 --- a/src/java/org/lwjgl/test/input/KeyboardTest.java +++ b/src/java/org/lwjgl/test/input/KeyboardTest.java @@ -133,7 +133,6 @@ public class KeyboardTest { Keyboard.read(); int count = Keyboard.getNumKeyboardEvents(); - System.out.println("Read " + count + " events"); while(Keyboard.next()) { System.out.println("Checking key:" + Keyboard.getKeyName(Keyboard.key)); if(Keyboard.key == Keyboard.KEY_ESCAPE) { @@ -160,6 +159,17 @@ public class KeyboardTest { position.y -= 1; } + if(Keyboard.isStateKeySet(Keyboard.KEY_SCROLL)) { + System.out.println("SCROLL lock on"); + } + + if(Keyboard.isStateKeySet(Keyboard.KEY_CAPITAL)) { + System.out.println("CAPS lock on"); + } + + if(Keyboard.isStateKeySet(Keyboard.KEY_NUMLOCK)) { + System.out.println("NUM lock on"); + } } if (count > 0) { System.out.println(); diff --git a/src/native/common/org_lwjgl_input_Keyboard.h b/src/native/common/org_lwjgl_input_Keyboard.h index 55145f8e..5c074ceb 100644 --- a/src/native/common/org_lwjgl_input_Keyboard.h +++ b/src/native/common/org_lwjgl_input_Keyboard.h @@ -323,6 +323,14 @@ 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 + */ +JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Keyboard_nisStateKeySet + (JNIEnv *, jclass, jint); #ifdef __cplusplus } diff --git a/src/native/win32/org_lwjgl_input_Keyboard.cpp b/src/native/win32/org_lwjgl_input_Keyboard.cpp index 8eec3b79..01b815f9 100644 --- a/src/native/win32/org_lwjgl_input_Keyboard.cpp +++ b/src/native/win32/org_lwjgl_input_Keyboard.cpp @@ -331,3 +331,17 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nEnableBuffer env->SetStaticObjectField(clazz, fid_readBuffer, newBuffer); return KEYBOARD_BUFFER_SIZE; } + +/* + * Class: org_lwjgl_input_Keyboard + * Method: nisStateKeySet + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Keyboard_nisStateKeySet(JNIEnv *env, jclass clazz, jint key) +{ + 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); + } +} \ No newline at end of file