# report keypress only once at a time during real time loop

**URL:** <https://psychtoolbox.discourse.group/t/report-keypress-only-once-at-a-time-during-real-time-loop/918>\
**Category:** Uncategorized\
**Created:** [March 13, 2003, 9:48am UTC](https://psychtoolbox.discourse.group/t/report-keypress-only-once-at-a-time-during-real-time-loop/918 "2003-03-13T09:48:39Z")\
**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:** [March 13, 2003, 9:48am UTC](https://psychtoolbox.discourse.group/t/report-keypress-only-once-at-a-time-during-real-time-loop/918/1 "2003-03-13T09:48:39Z")

</div>

Hey!  
  
I have a programmin problem and after a full-time-week of trial +   
lots of errors I'm asking for help. I'm working on a Win operated PC.  
  
I'd like to run a for-loop with a drifting grating. During that   
keypresses and the secs will be saved. My problem is now that it   
always returns one keypress several times because the loop is still   
running during the keypress. If I use 'while KbCheck; end' it   
returns the keypress only once but it pauses during that, which is   
not good. I also played around with CharAvail,touch etc.  
  
I use this loop:  
  
for i=1:1:n;  
 SCREEN(window,'WaitBlanking');  
 SCREEN('CopyWindow', wa(1+mod(i,frames1)),window,r,rr);  
 [keyIsDown,secs,keyCo de] = KbCheck;  
 responsesecs = secs;  
 if keyIsDown  
 char = KbName( keyCode);  
 if keyCode(right)   
 fprintf(fid,'right,%.3f \n',responsesecs-startSecs);  
 end  
 if keyCode(left)  
 fprintf(fid,'left,%.3f \n',responsesecs-startSecs);  
 end  
 end  
end  
  
  
  
I'd also like to run the loop with Rush, but there I have problems   
with the timing.Any ideas on that?  
  
Additionally I'd like to know if it is possible to combine two   
grating to a plaid (maybe by making a look-though-the-backgroud-  
grating), and if so, how?!  
  
Thanks sooo much for any suggestions.  
  
  
Best wishes,  
  
Timo
