|
From: <eli...@us...> - 2006-10-11 20:26:50
|
Revision: 2583
http://svn.sourceforge.net/java-game-lib/?rev=2583&view=rev
Author: elias_naur
Date: 2006-10-11 13:26:35 -0700 (Wed, 11 Oct 2006)
Log Message:
-----------
Windows: Restore the old ToAscii code used on win9x platforms in an attempt to fix broken keyboard input on win98se machines.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java
trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsKeyboard.c
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java 2006-10-11 13:48:48 UTC (rev 2582)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java 2006-10-11 20:26:35 UTC (rev 2583)
@@ -51,7 +51,9 @@
private final WindowsDirectInputDevice keyboard;
private final IntBuffer temp_data_buffer;
private final ByteBuffer keyboard_state;
+ private final boolean unicode;
private final CharBuffer unicode_buffer;
+ private final ByteBuffer ascii_buffer;
public WindowsKeyboard(WindowsDirectInput dinput, long hwnd) throws LWJGLException {
this.dinput = dinput;
@@ -72,9 +74,19 @@
keyboard.acquire();
temp_data_buffer = BufferUtils.createIntBuffer(BUFFER_SIZE*WindowsDirectInputDevice.DATA_SIZE);
keyboard_state = BufferUtils.createByteBuffer(256);
- unicode_buffer = BufferUtils.createCharBuffer(BUFFER_SIZE);
+ unicode = isWindowsNT();
+ if (unicode) {
+ unicode_buffer = BufferUtils.createCharBuffer(BUFFER_SIZE);
+ ascii_buffer = null;
+ } else {
+ unicode_buffer = null;
+ // ToAscii returns at most 2 characters
+ ascii_buffer = BufferUtils.createByteBuffer(2);
+ }
}
+ private static native boolean isWindowsNT();
+
public void destroy() {
keyboard.unacquire();
keyboard.release();
@@ -117,12 +129,22 @@
if (virt_key != 0 && GetKeyboardState(keyboard_state) != 0) {
// Mark key down in the scan code
dwOfs = dwOfs & 0x7fff;
- unicode_buffer.clear();
- int num_chars = ToUnicode(virt_key,
+ int num_chars;
+ if (unicode) {
+ unicode_buffer.clear();
+ num_chars = ToUnicode(virt_key,
dwOfs,
keyboard_state,
unicode_buffer,
unicode_buffer.capacity(), 0);
+ } else {
+ ascii_buffer.clear();
+ num_chars = ToAscii(virt_key,
+ dwOfs,
+ keyboard_state,
+ ascii_buffer,
+ 0);
+ }
if (num_chars > 0) {
int current_char = 0;
do {
@@ -130,7 +152,12 @@
dst.putInt(0);
dst.put((byte)0);
}
- int char_int = ((int)unicode_buffer.get()) & 0xFFFF;
+ int char_int;
+ if (unicode) {
+ char_int = ((int)unicode_buffer.get()) & 0xFFFF;
+ } else {
+ char_int = ((int)ascii_buffer.get()) & 0xFF;
+ }
dst.putInt(char_int);
dst.putLong(nanos);
current_char++;
@@ -151,6 +178,7 @@
}
private static native int MapVirtualKey(int uCode, int uMapType);
private static native int ToUnicode(int wVirtKey, int wScanCode, ByteBuffer lpKeyState, CharBuffer pwszBuff, int cchBuff, int flags);
+ private static native int ToAscii(int wVirtKey, int wScanCode, ByteBuffer lpKeyState, ByteBuffer lpChar, int flags);
private static native int GetKeyboardState(ByteBuffer lpKeyState);
public void read(ByteBuffer buffer) {
Modified: trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsKeyboard.c
===================================================================
--- trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsKeyboard.c 2006-10-11 13:48:48 UTC (rev 2582)
+++ trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsKeyboard.c 2006-10-11 20:26:35 UTC (rev 2583)
@@ -45,12 +45,26 @@
return MapVirtualKey(uCode, uMapType);
}
+JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_WindowsKeyboard_isWindowsNT(JNIEnv *env, jclass unused) {
+ OSVERSIONINFO osvi;
+
+ osvi.dwOSVersionInfoSize = sizeof(osvi);
+ GetVersionEx(&osvi);
+ return osvi.dwPlatformId == VER_PLATFORM_WIN32_NT ? JNI_TRUE : JNI_FALSE;
+}
+
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WindowsKeyboard_ToUnicode(JNIEnv *env, jclass unused, jint wVirtKey, jint wScanCode, jobject lpKeyState_obj, jobject pwszBuff_obj, jint cchBuff, jint flags) {
const PBYTE lpKeyState = (*env)->GetDirectBufferAddress(env, lpKeyState_obj);
LPWSTR pwszBuff = (*env)->GetDirectBufferAddress(env, pwszBuff_obj);
return ToUnicode(wVirtKey, wScanCode, lpKeyState, pwszBuff, cchBuff, flags);
}
+JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WindowsKeyboard_ToAscii(JNIEnv *env, jclass unused, jint wVirtKey, jint wScanCode, jobject lpKeyState_obj, jobject lpChar_obj, jint flags) {
+ const PBYTE lpKeyState = (*env)->GetDirectBufferAddress(env, lpKeyState_obj);
+ LPWORD lpChar = (*env)->GetDirectBufferAddress(env, lpChar_obj);
+ return ToAscii(wVirtKey, wScanCode, lpKeyState, lpChar, flags);
+}
+
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WindowsKeyboard_GetKeyboardState(JNIEnv *env, jclass unused, jobject lpKeyState_obj) {
PBYTE lpKeyState = (*env)->GetDirectBufferAddress(env, lpKeyState_obj);
return GetKeyboardState(lpKeyState);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|