# Pressing key duration

**URL:** <https://discourse.psychopy.org/t/pressing-key-duration/8451>\
**Category:** Coding\
**Created:** [July 10, 2019, 6:08pm UTC](https://discourse.psychopy.org/t/pressing-key-duration/8451 "2019-07-10T18:08:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kamil12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/kamil12/32/5362_2.png) [@Kamil12](https://discourse.psychopy.org/u/Kamil12)\
**Post date:** [July 10, 2019, 6:08pm UTC](https://discourse.psychopy.org/t/pressing-key-duration/8451/1 "2019-07-10T18:08:39Z")

</div>

Hi. I would like to code a little program which would measure the duration of a key which is pressed. I have the whole program and the only thing I need is a module when people see a fixation point and when they press a spacebar then this fixation point will disappear and after they release a key I will get a duration. Is it possible in psychopy or I have to use another library?

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [July 11, 2019, 3:10am UTC](https://discourse.psychopy.org/t/pressing-key-duration/8451/2 "2019-07-11T03:10:45Z")

</div>

The current version of PsychoPy now provides a new `keyboard` hardware class that can be used in place of the older `event` functions:

[https://www.psychopy.org/api/hardware/keyboard.html](https://www.psychopy.org/api/hardware/keyboard.html)

Note that these functions provide a `waitRelease` parameter that allows you to measure the duration of a keypress as well as its initial onset time. The timing ability is also drastically improved.

See here for an example:

> [@Can't use the new keyboard component (from Psychtoolbox)](https://discourse.psychopy.org/t/cant-use-the-new-keyboard-component-from-psychtoolbox/7634/5):
>
> Sorry that psychtoolbox lib wasn’t included in the win64 standalone. It is in the next release (3.1.1). The idea of waitRelease is that, in a scenario where you want a duration to be reported we have to decide what to do about keys that are still currently held down (the press is incomplete - we don’t yet have all the data for those). With waitRelease=true only key presses that have been completed are returned, so all are guaranteed to have a duration value, whereas with waitRelease=False a ke…
