# Collecting responses with PsychToolbox

**URL:** <https://psychtoolbox.discourse.group/t/collecting-responses-with-psychtoolbox/129>\
**Category:** Uncategorized\
**Created:** [January 7, 2017, 5:56pm UTC](https://psychtoolbox.discourse.group/t/collecting-responses-with-psychtoolbox/129 "2017-01-07T17:56:41Z")\
**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:** [January 7, 2017, 5:56pm UTC](https://psychtoolbox.discourse.group/t/collecting-responses-with-psychtoolbox/129/1 "2017-01-07T17:56:41Z")

</div>

Hello,  
I am trying to collect keyboard responses with PsychToolbox using KbCheck, but when I run the code the screen freezes and refuses to close. This script is intended to advance ONLY after keyboard input 'y' or 'n' (yes/no). I also want to collect which key response was made and the response time. Here is the code I am using to collect responses:
  
Screen('DrawText', window, 'XXXXX') %placeholder for of screen that is drawn  
Screen('Flip', window)
  
acceptedKeys = [KbName('y'), KbName('n')];  
responded = 0;
while responded == 0  
 [tmp,KeyTime,KeyCode] = KbCheck;  
 if KeyCode(acceptedKeys)  
 strResponse = KeyCode  
 responded = 1;  
 end  
 % time between iterations of KbCheck loop  
 WaitSecs(0.001);  
end

  

Screen('CloseAll');

  

Do you have any advice on why the screen is freezing? Thank you!  
  

Hailey  
Student, University of Oxford
