LWJGL 似乎在骚扰我(或者我又是个笨蛋)。我正在使用以下代码:
if(Keyboard.getEventKey() == Keyboard.KEY_Q) {
if (Keyboard.getEventKeyState()) {
System.err.println("Pressed");
}else {
System.err.println("Released");
}
}
当我按下并释放“Q”时,它既不会打印出“Pressed”也不会打印出“Released”。帮助?
编辑:问题解决了。在使用 getEventKey() 之前,您首先必须轮询键盘缓冲区。固定代码是:
while(Keyboard.next()) {
if(Keyboard.getEventKey() == Keyboard.KEY_Q) {
System.out.println("HI");
if (Keyboard.getEventKeyState()) {
System.out.println("Pressed");
}else {
System.out.println("Released");
}
}
}