KbCheck used correctly?

Dear all,

using a Lenovo T400 (with Windows XP, Matlab R2009a, and Psychtoolbox 3,
) and struggling for what felt like years, you are my last hope:

I use KbCheck in a trial to get a precise (not necessary correct) answer
in response to a stimulus display (+10ms, otherwise I don't see any
display). However, every time I run the code it get stuck and the main
window tells me that Matlab is "busy". Maybe that's because of these
"stuck" keys which I would like to disable (if I only knew how to
identify) them ... .

So, my question is essentially twofold:
First: are there errors in my code I simply don't see and especially
concerning the KbCheck command?
Second: how can I identify stuck keys and disable them?

I also used KbWait which seems fine but 5secs is a too large measurement
error - I am sorry. I assume that KbWaitStroke or KbPressWait have
essentially the same measurement error.

Any suggestions are welcome - regards miriam

here the code:
ListenChar(2);
b={'A', 'E', 'U', 'D', 'P', 'W'};
z={'2','4','6','3','5','7'};
ze={'+','>','=','?','ç','@'};
i=1;
results=[];
rt=0;
c=0;
delta=0;
while i<3 ;
b1=RandSample(b);
zi=RandSample(z);
zei=RandSample(ze);
a=b1{1};
zi=zi{1};
zei=zei{1};
intro=Screen('OpenWindow',0, [], [50,50,750,750]);
Screen('TextFont',intro, 'Courier New');
Screen('TextSize',intro, 44);
Screen('TextStyle',intro, 1+2);
Screen('FrameRect',intro, [255, 0, 0],[100,100, 500, 500]);

Screen('DrawText',intro,a, 175, 100, [0, 0, 255]);
Screen('DrawText',intro,zi, 175, 250, [0, 255, 0]);
Screen('DrawText',intro,zei, 175, 400, [255, 0,0]);
pause(0.1 );
while KbCheck
end;
startSecs = GetSecs;
%rt1=KbStrokeWait([1]);
%rt1=KbWait;
%rt=rt1-startSecs;
%pause(5);


while 1
[keyIsDown,timeSecs,keyCode, DeltaSecs] = KbCheck;
if keyIsDown==1
c = KbName(keyCode);
rt = timeSecs - startSecs;
while KbCheck; end
if strcmp(c,'alt')%|| strcmp(c,'space')
break;
end
end
end
results(i,1)=rt;
fprintf('rt %d %f\n' ,i,rt);
results(i,2)=c;
i=i+1;
Screen('CloseAll');
end;
ListenChar(0);

--
Miriam Gade, Dr
University of Zurich
Departement of Psychology, Cognitive Psychology Unit
Binzmühlestrasse 14/22, CH-8050 Zurich
office: BIN 4.B.03
phone: +41 (0)44 635 74 61
http://www.psychologie.uzh.ch/fachrichtungen/allgpsy/Team/Gade_en.html
KbCheck is used correctly, but not Screen.

1. You don't open and close the window for each trial, but open it at the beginning of a session and close it at the end.

2. The Screen('Flip') command is missing for stimulus-onset. Where you have your pause(0.1) command you should have a Screen('Flip', intro); command for stimulus onset. The reason you see your stimulus at all is probably a side effect of pause() interacting with internal processing of window resize events for the newly created window -- it works by accident.

-> Have a look at a couple of the demos in the PsychDemos folder and the intro PDF file in the PsychDocumentation folder. Understanding of the 'Flip' command and the timestamps it returns is crucial, esp. if you try to measure RT's.

Then you have to make sure that the keys are recognized. Did you add a couple of print statements to check where your Matlab becomes busy in some endless loop?

If stuck keys would be the problem, the most efficient approach currently is to define a "white-list" of wanted keys, so all other keys are excluded from processing. This is simpler than our old approach of using DisableKeysForKbCheck for "black-listing" or excluding certain keys - Saves the detective work of finding out which keys are stuck.

help RestrictKeysForKbCheck

Precise is relative: Regular keyboard are not very accurate for RT measurements, at least not if you care for differences with 10 msecs granularity as opposed to 100 msecs granularity.

best,
-mario

--- In psychtoolbox@yahoogroups.com, Miriam Gade <m.gade@...> wrote:
>
> Dear all,
>
> using a Lenovo T400 (with Windows XP, Matlab R2009a, and Psychtoolbox 3,
> ) and struggling for what felt like years, you are my last hope:
>
> I use KbCheck in a trial to get a precise (not necessary correct) answer
> in response to a stimulus display (+10ms, otherwise I don't see any
> display). However, every time I run the code it get stuck and the main
> window tells me that Matlab is "busy". Maybe that's because of these
> "stuck" keys which I would like to disable (if I only knew how to
> identify) them ... .
>
> So, my question is essentially twofold:
> First: are there errors in my code I simply don't see and especially
> concerning the KbCheck command?
> Second: how can I identify stuck keys and disable them?
>
> I also used KbWait which seems fine but 5secs is a too large measurement
> error - I am sorry. I assume that KbWaitStroke or KbPressWait have
> essentially the same measurement error.
>
> Any suggestions are welcome - regards miriam
>
> here the code:
> ListenChar(2);
> b={'A', 'E', 'U', 'D', 'P', 'W'};
> z={'2','4','6','3','5','7'};
> ze={'+','>','=','?','ç','@'};
> i=1;
> results=[];
> rt=0;
> c=0;
> delta=0;
> while i<3 ;
> b1=RandSample(b);
> zi=RandSample(z);
> zei=RandSample(ze);
> a=b1{1};
> zi=zi{1};
> zei=zei{1};
> intro=Screen('OpenWindow',0, [], [50,50,750,750]);
> Screen('TextFont',intro, 'Courier New');
> Screen('TextSize',intro, 44);
> Screen('TextStyle',intro, 1+2);
> Screen('FrameRect',intro, [255, 0, 0],[100,100, 500, 500]);
>
> Screen('DrawText',intro,a, 175, 100, [0, 0, 255]);
> Screen('DrawText',intro,zi, 175, 250, [0, 255, 0]);
> Screen('DrawText',intro,zei, 175, 400, [255, 0,0]);
> pause(0.1 );
> while KbCheck
> end;
> startSecs = GetSecs;
> %rt1=KbStrokeWait([1]);
> %rt1=KbWait;
> %rt=rt1-startSecs;
> %pause(5);
>
>
> while 1
> [keyIsDown,timeSecs,keyCode, DeltaSecs] = KbCheck;
> if keyIsDown==1
> c = KbName(keyCode);
> rt = timeSecs - startSecs;
> while KbCheck; end
> if strcmp(c,'alt')%|| strcmp(c,'space')
> break;
> end
> end
> end
> results(i,1)=rt;
> fprintf('rt %d %f\n' ,i,rt);
> results(i,2)=c;
> i=i+1;
> Screen('CloseAll');
> end;
> ListenChar(0);
>
> --
> Miriam Gade, Dr
> University of Zurich
> Departement of Psychology, Cognitive Psychology Unit
> Binzmühlestrasse 14/22, CH-8050 Zurich
> office: BIN 4.B.03
> phone: +41 (0)44 635 74 61
> http://www.psychologie.uzh.ch/fachrichtungen/allgpsy/Team/Gade_en.html
>