|
From: <sp...@us...> - 2012-08-23 10:36:23
|
Revision: 3789
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3789&view=rev
Author: spasi
Date: 2012-08-23 10:36:12 +0000 (Thu, 23 Aug 2012)
Log Message:
-----------
Attempt to fix lost key up events when Display is out of focus. (Windows)
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
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/WindowsDisplay.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2012-08-19 06:56:25 UTC (rev 3788)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2012-08-23 10:36:12 UTC (rev 3789)
@@ -345,6 +345,9 @@
redoMakeContextCurrent = true;
if (Display.isFullscreen())
updateClipping();
+
+ if ( keyboard != null )
+ keyboard.fireLostKeyEvents();
} else if (Display.isFullscreen()) {
showWindow(getHwnd(), SW_SHOWMINNOACTIVE);
resetDisplayMode();
@@ -1045,15 +1048,6 @@
return height;
}
- private int firstMouseButtonDown() {
- for(int i=0; i<Mouse.getButtonCount(); i++) {
- if(Mouse.isButtonDown(i)) {
- return i;
- }
- }
- return -1;
- }
-
private native boolean nTrackMouseEvent(long hwnd);
public boolean isInsideWindow() {
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java 2012-08-19 06:56:25 UTC (rev 3788)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java 2012-08-23 10:36:12 UTC (rev 3789)
@@ -49,8 +49,8 @@
private static final int BUFFER_SIZE = 50;
private final long hwnd;
- private final ByteBuffer keyboard_state;
private final byte[] key_down_buffer = new byte[Keyboard.KEYBOARD_SIZE];
+ private final byte[] virt_key_down_buffer = new byte[Keyboard.KEYBOARD_SIZE];
private final EventQueue event_queue = new EventQueue(Keyboard.EVENT_SIZE);
private final ByteBuffer tmp_event = ByteBuffer.allocate(Keyboard.EVENT_SIZE);
@@ -65,7 +65,6 @@
WindowsKeyboard(long hwnd) throws LWJGLException {
this.hwnd = hwnd;
- keyboard_state = BufferUtils.createByteBuffer(256);
}
private static native boolean isWindowsNT();
@@ -99,6 +98,7 @@
private static native int ToAscii(int wVirtKey, int wScanCode, ByteBuffer lpKeyState, ByteBuffer lpChar, int flags);
private static native int GetKeyboardState(ByteBuffer lpKeyState);
private static native int GetKeyState(int virt_key);
+ private static native int GetAsyncKeyState(int virt_key);
private void putEvent(int keycode, byte state, int ch, long millis, boolean repeat) {
tmp_event.clear();
@@ -155,8 +155,10 @@
flushRetained();
has_retained_event = true;
int keycode = WindowsKeycodes.mapVirtualKeyToLWJGLCode(virt_key);
- if (keycode < key_down_buffer.length)
+ if (keycode < key_down_buffer.length) {
key_down_buffer[keycode] = event_state;
+ virt_key_down_buffer[virt_key] = event_state;
+ }
retained_key_code = keycode;
retained_state = event_state;
retained_millis = millis;
@@ -164,6 +166,14 @@
retained_repeat = repeat;
}
+
+ public void fireLostKeyEvents() {
+ for ( int i = 0; i < virt_key_down_buffer.length; i++ ) {
+ if ( (virt_key_down_buffer[i] & 1) == 1 && (GetAsyncKeyState(i) & 1) == 0 )
+ handleKey(i, 0, false, (byte)0, System.currentTimeMillis(), false);
+ }
+ }
+
public void handleChar(int event_char, long millis, boolean repeat) {
if (has_retained_event && retained_char != 0)
flushRetained();
Modified: trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsKeyboard.c
===================================================================
--- trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsKeyboard.c 2012-08-19 06:56:25 UTC (rev 3788)
+++ trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsKeyboard.c 2012-08-23 10:36:12 UTC (rev 3789)
@@ -45,6 +45,10 @@
return GetKeyState(virt_key);
}
+JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WindowsKeyboard_GetAsyncKeyState(JNIEnv *env, jclass unused, jint virt_key) {
+ return GetAsyncKeyState(virt_key);
+}
+
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WindowsKeyboard_MapVirtualKey(JNIEnv *env, jclass unused, jint uCode, jint uMapType) {
return MapVirtualKey(uCode, uMapType);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|