# Press Multiple keys

**URL:** <https://discourse.glfw.org/t/press-multiple-keys/1207>\
**Category:** support\
**Created:** [October 31, 2018, 5:56am UTC](https://discourse.glfw.org/t/press-multiple-keys/1207 "2018-10-31T05:56:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fido9dido](https://avatars.discourse-cdn.com/v4/letter/f/e79b87/32.png) [@fido9dido](https://discourse.glfw.org/u/fido9dido)\
**Post date:** [October 31, 2018, 5:56am UTC](https://discourse.glfw.org/t/press-multiple-keys/1207/1 "2018-10-31T05:56:32Z")

</div>

I am totally beginner, I can press and catch event for a single keyboard button easily but I want to catch events for pressing multiple keys at the same time like A+B or ALT + ENTER or CTRL + A

---

<div class="post-metadata">

**Author:** ![mmozeiko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/mmozeiko/32/29_2.png) [@mmozeiko](https://discourse.glfw.org/u/mmozeiko)\
**Post date:** [October 31, 2018, 8:09am UTC](https://discourse.glfw.org/t/press-multiple-keys/1207/2 "2018-10-31T08:09:34Z")

</div>

For detecting Alt or Ctrl check the `mods` argument to key callbacks. It is a bitmask containing info if Shift, Ctrl, Alt or Windows is pressed at the same time. Here are the symbol names: [http://www.glfw.org/docs/latest/group\_\_mods.html](http://www.glfw.org/docs/latest/group__mods.html)

For detecting other keys (will work also for Alt/Ctrl) you need to write custom code like this:

```auto
bool is_A_down = false;
bool is_B_down = false;

void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    if (key == GLFW_KEY_A) is_A_down = action == GLFW_PRESS;
    if (key == GLFW_KEY_B) is_B_down = action == GLFW_PRESS;
    if (is_A_down && is_B_down)
    {
        // now you know that both A and B keys are down, do what you need
        call_some_function();
    }
}

```

Of course this is very simple example. In real code you can use something like array for all the keys (512 element array) or create hashtable/std::map with your actions to call automatically. It is really your choice what your code needs to do.

Alternative is to explicitly check if keys are down:

```auto
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS &&
    glfwGetKey(window, GLFW_KEY_B) == GLFW_PRESS)
{
    call_some_function();
}

```

Be careful with missed events. You might want to enable sticky keys in this case if that does not conflict with handling your other keys. Read the documentation how keyboard input works: [http://www.glfw.org/docs/latest/input\_guide.html#input\_key](http://www.glfw.org/docs/latest/input_guide.html#input_key)
