I am making a game with lwjgl and GLFW and am having a hard time figuring out how to check for a single press on the keyboard.


1 Answer 1


I figured this out on my own eventually. So I used the GLFWKeyCallback method and created something like this.

private static List<Integer> pressed = new ArrayList<Integer>();
private static boolean[] keys = new boolean[65536];

public static boolean isPressed(int key){
    return keys[key];

public static boolean isClicked(int key){
    if (!keys[key]) return false;
    if (pressed.contains(new Integer(key))) return false;
    pressed.add(new Integer(key));
    return true;

public static void glfwKeyCallback(long window, int key, int scanCode, int action, int mods){
    keys[key] = action != GLFW_RELEASE;
    if(action == GLFW_RELEASE && pressed.contains(new Integer(key))) pressed.remove(new Integer(key));

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .