# Keyboard - several keys pressed simultaneously

**URL:** <https://discourse.psychopy.org/t/keyboard-several-keys-pressed-simultaneously/20790>\
**Category:** Coding\
**Created:** [February 25, 2021, 1:05pm UTC](https://discourse.psychopy.org/t/keyboard-several-keys-pressed-simultaneously/20790 "2021-02-25T13:05:19Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![sol](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/sol/32/15018_2.png) [@sol](https://discourse.psychopy.org/u/sol)\
**Post date:** [March 1, 2021, 11:48am UTC](https://discourse.psychopy.org/t/keyboard-several-keys-pressed-simultaneously/20790/2 "2021-03-01T11:48:28Z")

</div>

> [@Mkienlen](#):
>
> **several keyboard keys** are pressed **simultaneously**.

In Python…

Something like this would tell you if \> 1 press event has occurred since the last screen retrace / call to `event.getKeys()`:

```auto
from psychopy import visual, event, core

win = visual.Window([800, 400]) # , fullscr=True, allowGUI=False)
msg = visual.TextStim(win, text="No keys pressed.")
stime = core.getTime()
while core.getTime() - stime < 5:
    key_events = event.getKeys()
    if len(key_events) > 0:
        msg.setText("%d keys were pressed at about the same time: %s"%(len(key_events), str(key_events)))
    msg.draw()
    win.flip()

```

You could do a similar type thing using the `psychopy.hardware.keyboard.Keyboard()` class as well.

If you want to know if \> 1 key is being pressed down, regardless of when each key was first pressed, you could use iohub keyboard:

```auto
from psychopy import visual, iohub, core

keyboard = iohub.launchHubServer().devices.keyboard

win = visual.Window([800, 400]) # , fullscr=True, allowGUI=False)
msg = visual.TextStim(win, text="No keys pressed.")

stime = core.getTime()
while core.getTime() - stime < 5:
    pressed_keys = keyboard.state
    if len(pressed_keys) > 0:
        msg.setText("%d keys are currently pressed: %s"%(len(pressed_keys), str(pressed_keys.keys())))
    else:
        msg.setText("No keys pressed.")
    msg.draw()
    win.flip()

core.quit()

```

---

_[View the full topic](https://discourse.psychopy.org/t/keyboard-several-keys-pressed-simultaneously/20790)._
