# Missed keypress with KbStrokeWait

**URL:** <https://psychtoolbox.discourse.group/t/missed-keypress-with-kbstrokewait/3923>\
**Category:** Programming Help\
**Tags:** experiment-design\
**Created:** [July 8, 2021, 1:20pm UTC](https://psychtoolbox.discourse.group/t/missed-keypress-with-kbstrokewait/3923 "2021-07-08T13:20:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwagshul](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@mwagshul](https://psychtoolbox.discourse.group/u/mwagshul)\
**Post date:** [July 8, 2021, 1:20pm UTC](https://psychtoolbox.discourse.group/t/missed-keypress-with-kbstrokewait/3923/1 "2021-07-08T13:20:51Z")

</div>

Hi. I am using Psychtoolbox on Windows 10, for fMRI. The trigger pulse from our scanner is translated into a keypress (the “9” key), and I’m using KbStrokeWait to trigger my paradigm, with the following code:

KeyToPress=KbName(‘9(’);  
RestrictKeysForKbCheck(KeyToPress);  
KbStrokeWait;

This works most of the time, but occasionally it misses the trigger. If I look at this code at the command line, I see that occasionally, the terminal registers the “9”, but still waits for the next 9 before it returns to the prompt.

I’m assuming that this is happening because the keypress is very rapid and it happens between calls to KbWait, which is in an infinite loop.

Is there a way to hold the keypress in the buffer, so that I can retrieve it on the next call? Or some other way to fix this problem?

Thanks for any advice.

Best,

Mark

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [July 8, 2021, 3:07pm UTC](https://psychtoolbox.discourse.group/t/missed-keypress-with-kbstrokewait/3923/2 "2021-07-08T15:07:15Z")

</div>

`help KbTriggerWait` is what you want to use. If you appreciate this help and ongoing development and maintenance of Psychtoolbox, or require further assistance, please get your lab to buy a 150 Euros + Tax community membership with priority support:

[http://psychtoolbox.org/contribute](http://psychtoolbox.org/contribute)

Best,  
-mario

---

<div class="post-metadata">

**Author:** ![mwagshul](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@mwagshul](https://psychtoolbox.discourse.group/u/mwagshul)\
**Post date:** [July 8, 2021, 3:55pm UTC](https://psychtoolbox.discourse.group/t/missed-keypress-with-kbstrokewait/3923/3 "2021-07-08T15:55:17Z")

</div>

Thanks, and yes, I agree, we have gotten a lot out of this software, and we have the funding to support you guys!

![image001.jpg](https://global.discourse-cdn.com/free1/uploads/psychtoolbox/original/1X/fc4a6e075e037d216dec550780cd35d07ce043af.jpeg)

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [July 8, 2021, 6:53pm UTC](https://psychtoolbox.discourse.group/t/missed-keypress-with-kbstrokewait/3923/4 "2021-07-08T18:53:23Z")

</div>

Thats great to hear Mark! We direly need the funding, almost exclusive so that Mario, the blood and soul of PTB, can have a living wage. If you are able to afford more than one such membership (support hours), please do consider buying multiple 🙂
