GLFW Key Event Bouncing

Hi guys,

I have come across an issue with GLFW’s key event callback function that I can’t seem to work out. I have set up the following callback function:


glfwSetKeyCallback(Window.getWindowId(), (window, key, scancode, action, mods) ->
{
    if (action == GLFW_PRESS)
    {
        currentKeyState.put(key, true);
        System.out.print("P");
    }

    if (action == GLFW_RELEASE)
    {
        currentKeyState.put(key, false);
        System.out.print("R");
    }
});

In my main loop I am calling glfwPollEvents once per frame.

When I quickly press and release a key, I get an output of “P” followed by “R” upon release.

If I press and hold a key for more than two seconds, I get an output of “P” followed by “RPR” upon release, regardless of how long I hold the key down.

It seems to me as though the key repeat event is causing the the key press and release events to bounce?? I am moving my camera based on the key state stored in the “currentKeyState” map. When I hold a directional key, my camera will move, when I release the key, it stops for a split second, then moves a small amount due to this bouncing.

Is this behaviour expected?

I have just noticed that this problem occurs in Ubuntu, but not in OS X.

GLFW includes GLFW_REPEAT which is for repeat keys. It could be a bug in GLFW. Consider opening a ticket on their repo on Github.