# Key Callback Not Registering Every Key Press

**URL:** <https://discourse.glfw.org/t/key-callback-not-registering-every-key-press/1438>\
**Category:** support\
**Created:** [November 11, 2019, 8:23pm UTC](https://discourse.glfw.org/t/key-callback-not-registering-every-key-press/1438 "2019-11-11T20:23:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rian-Schmit](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@Rian-Schmit](https://discourse.glfw.org/u/Rian-Schmit)\
**Post date:** [November 11, 2019, 8:23pm UTC](https://discourse.glfw.org/t/key-callback-not-registering-every-key-press/1438/1 "2019-11-11T20:23:57Z")

</div>

I am currently trying to get input working on my OpenGL project with GLFW and I seem to have run in to a problem or have missed something when reading the documentation. I am trying to get every key press that happens during a frame and fill a list with the information about that event. I then can query it from anywhere else in my program. If I read the documentation right, the key callback should have every key that was pressed before glfwPollEvents is called next. The only problem is that the callback only ever seems to detect one key event each frame so if I press more than one key it dumps the other keys.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [November 12, 2019, 9:32am UTC](https://discourse.glfw.org/t/key-callback-not-registering-every-key-press/1438/2 "2019-11-12T09:32:12Z")

</div>

Hi, welcome to the GLFW forums!

It’s possible that you may be hitting a hardware limitation on keyboards for how many particular keys can be registered simultaneously, this is called rollover: [https://en.wikipedia.org/wiki/Rollover\_(key)](https://en.wikipedia.org/wiki/Rollover_(key))

If you want to check that your program is using GLFW correctly you could first [try the GLFW test program events.c](https://github.com/glfw/glfw/blob/master/tests/events.c). If this works but your program doesn’t there may be an error in how you’re using GLFW.

If you’re still having issues then let me know, along with what operating system your using (and which window manager if you’re using Linux).

---

<div class="post-metadata">

**Author:** ![Rian-Schmit](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@Rian-Schmit](https://discourse.glfw.org/u/Rian-Schmit)\
**Post date:** [November 13, 2019, 3:13am UTC](https://discourse.glfw.org/t/key-callback-not-registering-every-key-press/1438/3 "2019-11-13T03:13:20Z")

</div>

So I tried the demo and it works just like my implementation does. When I press multiple keys it only tells me that the most recent one I pressed is being held but not the one prior. I’m not exactly sure if my keyboard is the problem as I have a Corsair K70 so this shouldn’t be a problem. I guess my question is can GLFW detect multiple key events at the same time besides modifier keys and one other key?

My OS is Windows 10 x64, version 10.0.18362.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [November 13, 2019, 10:37am UTC](https://discourse.glfw.org/t/key-callback-not-registering-every-key-press/1438/4 "2019-11-13T10:37:07Z")

</div>

I think I now understand your issue - I think your problem is with the callback and the action `GLFW_REPEAT`.

GLFW does handle mutliple `GLFW_PRESS` or `GLFW_RELEASE` events on the same frame, but Windows only generates repeat events for one key, and only does so at a specific regular frequency not your application frame rate.

Basically `GLFW_REPEAT` is not intended for multiple physical key input, it’s designed for typing words like _aaaaaaaaaaaarrrrrrrrrrrrrrrrggggggggghhhh_. I think we should consider adding a note to the documentation to clarify this.

So if you want to know which key is down on a given frame you need to keep a state of the keys you’re interested in, or better yet just keep the state of what action you map each key to:

```auto
static in move_forwards = 0;

static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    if( key == 'W' )
    {
        if( GLFW_RELEASE == action )
        {
            move_forwards = 0;
        }
        else
        {
            move_forwards = 1;
        }
    }
}

```

Edit: I’ve added an issue about the documentation: [https://github.com/glfw/glfw/issues/1596](https://github.com/glfw/glfw/issues/1596)

---

<div class="post-metadata">

**Author:** ![Rian-Schmit](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@Rian-Schmit](https://discourse.glfw.org/u/Rian-Schmit)\
**Post date:** [November 13, 2019, 7:06pm UTC](https://discourse.glfw.org/t/key-callback-not-registering-every-key-press/1438/5 "2019-11-13T19:06:08Z")

</div>

Okay, so what you’re saying is only one key each frame will be marked as GLFW\_REPEAT but I will be notified when any key I held down is released?

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [November 13, 2019, 7:21pm UTC](https://discourse.glfw.org/t/key-callback-not-registering-every-key-press/1438/6 "2019-11-13T19:21:36Z")

</div>

You will receive `GLFW_PRESS` for every key pressed, and `GLFW_RELEASE` for every key released (providing the keyboard can handle that those keys pressed at the same time).

I would ignore `GLFW_REPEAT` actions in the key callback.

---

<div class="post-metadata">

**Author:** ![Rian-Schmit](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@Rian-Schmit](https://discourse.glfw.org/u/Rian-Schmit)\
**Post date:** [November 13, 2019, 7:21pm UTC](https://discourse.glfw.org/t/key-callback-not-registering-every-key-press/1438/7 "2019-11-13T19:21:58Z")

</div>

Awesome, thank you so much for your help.

---

<div class="post-metadata">

**Author:** ![note8g2018](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/note8g2018/32/538_2.png) [@note8g2018](https://discourse.glfw.org/u/note8g2018)\
**Post date:** [June 23, 2021, 3:22am UTC](https://discourse.glfw.org/t/key-callback-not-registering-every-key-press/1438/8 "2021-06-23T03:22:19Z")

</div>

I have similar problem.  
I want to do the following:  
increase the speed in a certain direction while I am holding the SHIFT key and press the arrow key at the same time.  
the problem is I get release event of shift key when I press the arrow key.  
even I try mods == shift , still when I press the arrow, the mods change so I cannot increase the speed.  
please any help

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [June 23, 2021, 11:05am UTC](https://discourse.glfw.org/t/key-callback-not-registering-every-key-press/1438/9 "2021-06-23T11:05:46Z")

</div>

HI @note8g2018 - I’m answering your question on the thread you created:

> [@Why glfw give me release event key when I press another key even I still press the old one](https://discourse.glfw.org/t/why-glfw-give-me-release-event-key-when-i-press-another-key-even-i-still-press-the-old-one/1882):
>
> I want to do the following: increase the speed in a certain direction while I am holding the SHIFT key and press the arrow key at the same time. the problem is I get release event of shift key when I press the arrow key. even I try mods == shift , still when I press the arrow, the mods change so I cannot increase the speed. please any help
