# KbWait Not Working

**URL:** <https://psychtoolbox.discourse.group/t/kbwait-not-working/3616>\
**Category:** Programming Help\
**Created:** [January 13, 2021, 12:27am UTC](https://psychtoolbox.discourse.group/t/kbwait-not-working/3616 "2021-01-13T00:27:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam0324](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@sam0324](https://psychtoolbox.discourse.group/u/sam0324)\
**Post date:** [January 13, 2021, 12:27am UTC](https://psychtoolbox.discourse.group/t/kbwait-not-working/3616/1 "2021-01-13T00:27:49Z")

</div>

PTB version: 3.0.17 - Flavor: beta - Corresponds to SVN Revision 11387  
I am using late 2018 MacBook Air, macOS Big Sur 11.1 and Matlab R2020b.

My problem is that KbWait does not wait or return anything.  
I want KbWait to wait for 5 seconds, so I passed 5 for the third argument (i.e., KbWait(-1, [], 5);).  
It appears that KbWait is immediately skipped for some reason.  
I have checked the security setting on my Mac and Matlab has the permission for input monitoring. KbDemo worked fine, so I am not sure why this is not working.

Could someone please explain what I am missing?  
Thank you.

```
ListenChar(2) % suppress key inputs in Matlab command line
while(1)
    Screen('Flip', win);
    disp('RIGHT BEFORE KBWAIT');
    [secs, keyCode, deltaSecs] = KbWait(-1, [], 5);
    % if there is key press, break out of this loop
    if keyCode
        disp('keypress detected');
        break;
    end
    disp('KBWAIT SKIPPED')
end

```

After running, command line just says:

‘’’  
RIGHT BEFORE KBWAIT  
KBWAIT SKIPPED  
‘’’

---

<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:** [January 13, 2021, 2:31am UTC](https://psychtoolbox.discourse.group/t/kbwait-not-working/3616/2 "2021-01-13T02:31:20Z")

</div>

You don’t specify wait time in seconds, but until when it should wait:

`KbWait(-1, [], 5);` ==\> `KbWait(-1, [], GetSecs + 5);`

This was free advice. We appreciate if labs contribute back financially. See `PsychPaidSupportAndServices` for info how you can contribute.  
-mario
