Attempt to fix lost key up events when Display is out of focus. (Windows)

This commit is contained in:
Ioannis Tsakpinis 2012-08-23 10:36:12 +00:00
parent ad4f4c74eb
commit 814f9a141e
3 changed files with 20 additions and 12 deletions

View File

@ -345,6 +345,9 @@ final class WindowsDisplay implements DisplayImplementation {
redoMakeContextCurrent = true;
if (Display.isFullscreen())
updateClipping();
if ( keyboard != null )
keyboard.fireLostKeyEvents();
} else if (Display.isFullscreen()) {
showWindow(getHwnd(), SW_SHOWMINNOACTIVE);
resetDisplayMode();
@ -1045,15 +1048,6 @@ final class WindowsDisplay implements DisplayImplementation {
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() {

View File

@ -49,8 +49,8 @@ final class WindowsKeyboard {
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 @@ final class WindowsKeyboard {
WindowsKeyboard(long hwnd) throws LWJGLException {
this.hwnd = hwnd;
keyboard_state = BufferUtils.createByteBuffer(256);
}
private static native boolean isWindowsNT();
@ -99,6 +98,7 @@ final class WindowsKeyboard {
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 @@ final class WindowsKeyboard {
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 @@ final class WindowsKeyboard {
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();

View File

@ -45,6 +45,10 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WindowsKeyboard_GetKeyState(JNIEnv
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);
}