Hi,
I am working on a project using LWJGL and I ran across a bug when pulling input keyboards inputs (it probably does the same with the mouse inputs, I haven't checked yet.)
He is a short demo of the bug:
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class DemoBugLWJGL {
public void start() {
try {
Display.setDisplayMode(new DisplayMode(800, 600));
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
boolean running = true;
while (!Display.isCloseRequested() && running) {
pollInput();
if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
running = false;
}
if(Keyboard.isKeyDown(Keyboard.KEY_A)) {
System.out.println("key A down");
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
Display.update();
}
Display.destroy();
}
public void pollInput() {
while(Mouse.next()) {
// do stuff
}
while (Keyboard.next()) {
// do stuff
}
}
public static void main(String[] argv) {
DemoBugLWJGL inputExample = new DemoBugLWJGL();
inputExample.start();
}
}
This code is almost the same as the Input tutorial in the wiki.
When the user press the A key, the message is displayed in the console.
The bug occurs if the user changes the main windows (with alt-tab or just by clicking outside of the lwjgl windows) while pressing the key and then releases the key.
The message keeps being displayed even if the key has been released (that is normal because the jwjgl windows cannot access the input
once not on focus).
The problem is when the focus is gained back by the display, the method Keyboard.isKeyDown(Keyboard.KEY_A) keeps returning true.
I ran across the method Keyboard.reset(), but this method is private, maybe calling this method when the display loses/get the focus can fix this bug.
Thanks for your time,
Mytrill.
EDIT: I work with the last version of LWJGL, and my OS is Windows 7 pro 32bit, if that is relevant to the problem^^