# KbWait ignoring keypresses

**URL:** <https://psychtoolbox.discourse.group/t/kbwait-ignoring-keypresses/265>\
**Category:** Uncategorized\
**Created:** [November 19, 2018, 4:50pm UTC](https://psychtoolbox.discourse.group/t/kbwait-ignoring-keypresses/265 "2018-11-19T16:50:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [November 19, 2018, 4:50pm UTC](https://psychtoolbox.discourse.group/t/kbwait-ignoring-keypresses/265/1 "2018-11-19T16:50:00Z")

</div>

Hi All,

I am presenting stimuli and asking people to give a keyboard response. The problem I am having is that KbWait(-1,2) is ignoring key presses: it will consistently ignore the first press but then will consistently notice the second key press I make (i.e., I need to press a key twice to get KbWait to recognize it). Oddly, this does not happen for the numeric keys (1!, 2@, etc.), it only happens for the alpha-numeric ones. Any ideas on how to fix this would be greatly appreciated. Code to reproduce the problem is below:

--------

[window, windowRect] = Screen('OpenWindow', 0,[],[]);

Screen('TextFont',window, 'Times New Roman');

Screen('TextSize', window, 18);

HideCursor(window);

centeredspotRect = CenterRect([0 0 0 0], windowRect);

Priority(1);

Screen('Preference', 'SkipSyncTests',1);

Screen('Preference','VisualDebugLevel',0);

Screen('Preference', 'SuppressAllWarnings', 1);

%KbName('UnifyKeyNames');

ykey = KbName('Y');

nkey = KbName('N');

key1 = '1!';

key2 = '2@';

key3 = '3#';

key4 = '4$';

key5 = '5%';

key6 = '6^';

key7 = '7&';

RestrictKeysForKbCheck([ykey nkey key1 key2 key3 key4 key5 key6 key7]);

DisableKeysForKbCheck(13);

black = BlackIndex(0);

Screen('DrawText', window, '+', centeredspotRect(1)-.01\*centeredspotRect(1), centeredspotRect(2)-.24\*centeredspotRect(2), black);

Screen('flip',window)

WaitSecs(1)

Screen('DrawText', window, 'Please Get Ready.', centeredspotRect(1)-.09\*centeredspotRect(1), centeredspotRect(2)-.24\*centeredspotRect(2), black);

Screen('flip',window)

WaitSecs(1)

Screen('DrawText', window, 'Cats', centeredspotRect(1)-.18\*centeredspotRect(1), centeredspotRect(2)-.24\*centeredspotRect(2), black);

Screen('DrawText', window, 'Dogs', centeredspotRect(1)-.18\*centeredspotRect(1), centeredspotRect(2)-.10\*centeredspotRect(2), black);

Screen('DrawText', window, 'Demons', centeredspotRect(1)-.18\*centeredspotRect(1), centeredspotRect(2)+.04\*centeredspotRect(2), black);

Screen('DrawText', window, 'Yes(Y) or No(N)?', centeredspotRect(1)-.04\*centeredspotRect(1), centeredspotRect(2)+.18\*centeredspotRect(2), black);

RestrictKeysForKbCheck([ykey nkey]);

[~,FlipTime] = Screen('flip',window);

KbWait(-1,2)

[~,First\_Answer] = KbWait(-1,2);

First\_Answer = find(First\_Answer);

First\_Answer\_Fluency = GetSecs - FlipTime;

sca

------------

Thank you in advance for your help.

-Michael
