Hello, I'm trying to make game not using any game engines, but have problem in keyboard input. This is hardest part for me, to make keyboard listen for key press event, not key down. Here is my current Keyboard.java code:
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class Keyboard implements KeyListener {
private static boolean keys[] = new boolean[65535];
public void keyPressed(KeyEvent e){
keys[e.getKeyCode()] = true;
}
public void keyReleased(KeyEvent e){
keys[e.getKeyCode()] = false;
}
public void keyTyped(KeyEvent e){
}
public static boolean isKeyDown(int keyCode){
return keys[keyCode];
}
}
When I create jframe I do this:
//At the top of class
public Keyboard keyboard = new Keyboard();
//On init jframe:
addKeyListener(keyboard);
And how I could listen for key press in other classes? For example how it would be with LWJGL:
while(Keyboard.next()){
if(Keyboard.getEventKeyState()){
//blabla...
}
}
But I actually do not know what does next() method and getEventKeyState() method. Maybe someone were working with keyboard input and knows how to create those two methods?