Hey all,
I'm still getting the hang of LWJGL and I am hitting a minor snag. I'm just trying to get a block to move smoothly around the screen and I'm having an issue with the Keyboard inputs. I use the Keyboard.enableRepeatEvents(true);
code so that I can hold down WASD to move the object on the screen. It does do that; however, there's a half-second or so lag between when I press down the key and when the object begins to move. Could this simply have to do with my OS's key repeat rate preventing the code from recognizing that I'm actually holding down the key?
EDIT: Maybe I can be more precise, when I press the key, the box will move one increment, wait for a half-second, and then move rapidly. The lag is only on the repeat, not any movement.
Here's my input code, if that helps out. It's almost verbatim from the tutorial on the LWJGL site wiki:
public void pollInput(Components character){
if(Mouse.isButtonDown(0)){ //left click
int mouseX = Mouse.getX();
int mouseY = Mouse.getY();
System.out.println("Mouse clicked at " + mouseX + ", " + mouseY);
}
while(Keyboard.next()){
if(Keyboard.getEventKeyState()){
if(Keyboard.getEventKey() == Keyboard.KEY_W){
System.out.println("Move Forward");
character.y += 4;
}
if(Keyboard.getEventKey() == Keyboard.KEY_A){
System.out.println("Move Left");
character.x -=4;
}
if(Keyboard.getEventKey() == Keyboard.KEY_D){
System.out.println("Move Right");
character.x += 4;
}
if(Keyboard.getEventKey() == Keyboard.KEY_S){
System.out.println("Move Back");
character.y -= 4;
}
} else {
if(Keyboard.getEventKey() == Keyboard.KEY_W){
System.out.println("Stop Moving Forward");
}
if(Keyboard.getEventKey() == Keyboard.KEY_A){
System.out.println("Stop Moving Left");
}
if(Keyboard.getEventKey() == Keyboard.KEY_D){
System.out.println("Stop Moving Right");
}
if(Keyboard.getEventKey() == Keyboard.KEY_S){
System.out.println("Stop Moving Back");
}
}
}
}