# Bug report: Keyboard Response event doesn't discard previous

**URL:** <https://discourse.psychopy.org/t/bug-report-keyboard-response-event-doesnt-discard-previous/7673>\
**Category:** Builder\
**Created:** [May 8, 2019, 4:15pm UTC](https://discourse.psychopy.org/t/bug-report-keyboard-response-event-doesnt-discard-previous/7673 "2019-05-08T16:15:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Buehner](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/marc_buehner/32/3476_2.png) [@Marc\_Buehner](https://discourse.psychopy.org/u/Marc_Buehner)\
**Post date:** [May 8, 2019, 4:15pm UTC](https://discourse.psychopy.org/t/bug-report-keyboard-response-event-doesnt-discard-previous/7673/1 "2019-05-08T16:15:40Z")

</div>

**OS** (e.g. Win10): Mac OS 10.14.4  
**PsychoPy version** (e.g. 1.84.x): 3.1.0  
\*\*Standard Standalone? (y)  
\*\*What are you trying to achieve?: Use keyboard response event to terminate a trial

\*\*What did you try to make it work?:  
The keyboard event is scheduled 5s into the trial to ensure subjects engage with the material before pressing SPACE

**What specifically went wrong when you tried that?:**  
Pressing SPACE BEFORE the 5s is up still advances the trial.  
Furthermore, repeatedly pressing space on one trial carries over into the next trial, i.e. the next trial then finishes after 5s (when the keyboard response event is scheduled), even when no key was pressed

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [May 8, 2019, 5:10pm UTC](https://discourse.psychopy.org/t/bug-report-keyboard-response-event-doesnt-discard-previous/7673/2 "2019-05-08T17:10:46Z")

</div>

Thanks @Marc_Buehner, looks like the `clearEvents` method is not clearing the event buffer. I will log an issue on GitHub to get this fixed. Are you running the developers version or standalone?

> <https://github.com/psychopy/psychopy/pull/2442>
>
> KB was calling clearEvents to clear the key buffer, which only cleared the event…s list, not the
> actual list of keys pressed. This means that keypresses persisted
> even with the option to discard previous keypresses before KB onset
> was selected. To fix, rather than have clearEvents call \_clearEvents,
> which other methods also call, the events and key list are cleared
> directly.

---

<div class="post-metadata">

**Author:** ![Marc\_Buehner](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/marc_buehner/32/3476_2.png) [@Marc\_Buehner](https://discourse.psychopy.org/u/Marc_Buehner)\
**Post date:** [May 17, 2019, 9:49am UTC](https://discourse.psychopy.org/t/bug-report-keyboard-response-event-doesnt-discard-previous/7673/3 "2019-05-17T09:49:08Z")

</div>

HI there – sorry I forgot to reply. I am running standalone.  
What’s the best way to manually clear the event buffer in the meantime until the bug is fixed?  
I tried event.clearEvents() on every frame but that didn’t seem to do the trick

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [May 17, 2019, 9:56am UTC](https://discourse.psychopy.org/t/bug-report-keyboard-response-event-doesnt-discard-previous/7673/4 "2019-05-17T09:56:27Z")

</div>

@Marc_Buehner, its fixed in [3.1.2](https://www.psychopy.org/download.html).

---

<div class="post-metadata">

**Author:** ![Linozeroos](https://avatars.discourse-cdn.com/v4/letter/l/46a35a/32.png) [@Linozeroos](https://discourse.psychopy.org/u/Linozeroos)\
**Post date:** [October 7, 2019, 1:50pm UTC](https://discourse.psychopy.org/t/bug-report-keyboard-response-event-doesnt-discard-previous/7673/5 "2019-10-07T13:50:18Z")

</div>

I’m having the same problem on Mac OS 10.14.4 and PsychoPy 3.1.5.  
I’m calling the .clearEvents() function on my keyboard object but the buffer is not cleared. It seems, only calling .getKeys() effectively clears the buffer.

---

<div class="post-metadata">

**Author:** ![enniin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/enniin/32/7588_2.png) [@enniin](https://discourse.psychopy.org/u/enniin)\
**Post date:** [March 24, 2020, 1:13pm UTC](https://discourse.psychopy.org/t/bug-report-keyboard-response-event-doesnt-discard-previous/7673/6 "2020-03-24T13:13:27Z")

</div>

I’m having the same issue. One (!) extra space carries over to next trial despite explicitly calling clearEvents() at end of each trial.

PsychoPy 3.2.4 standalone  
macOS 10.14.6
