I am setting up an experiment where a sequence of stimuli is running
and the subject presses a keyboard key to respond to events. I would
like to know which frame of the stimulus sequence is showing when the
key is pressed. Here is a simple demo, where a press of the right
arrow key starts a dot travelling from left to right, and the frame
numbers corresponding to presses of the left arrow key are stored in
an array (bb). The program works fine except that each key press
results in a random number of entries (between 4 and 6) in the array
bb. For example, two presses of the left arrow key in the duration of
travelling dot may result in:
bb=[161 162 163 164 165 259 260 261 262 263];
Each key press results in a series of 5 entries. I can use the first
entry of each series as the stimulus frame corresponding to a key
press, but I'd like to have a cleaner result. I do have a
FlushEvents('keyDown');
in the loop, but it does not seem to do any thing and the keyDown
event lingers for 4 or 5 frames.
I am using a 2 GHz PC running Windows 2000, MatLab 6.1 and the lastest
PsychToolbox.
Thanks!
Lei
% travelling dot
white=255;
[w,wRect]=Screen(0,'OpenWindow',white);
srcRect=[0,0,100,100];
dstRect=CenterRect(srcRect,wRect);
dotRect0=CenterRect([0 0 12 12],srcRect);
[dot offRect]=Screen(w,'OpenOffscreenWindow',white,dstRect);
Screen(dot,'FillOval',black,dotRect0);
white=255;
black=0;
d0=OffsetRect(offRect,0,0);
rightKey = KbName('right');
leftKey = KbName('left');
escapeKey = KbName('esc');
bb=[];
while 1
[a,b,keyCode] = KbCheck;
if keyCode(rightKey)
for i=1:300
dotRect=OffsetRect(d0,i,0);
Screen(w,'WaitBlanking')
Screen('CopyWindow',dot,w,offRect,dotRect);
[a,b,keyCode] = KbCheck;
if keyCode(leftKey)
bb=[bb i];
end
FlushEvents('keyDown');
end
end
if keyCode(escapeKey)
break;
end
end
FlushEvents('keyDown');
Screen('CloseAll');
and the subject presses a keyboard key to respond to events. I would
like to know which frame of the stimulus sequence is showing when the
key is pressed. Here is a simple demo, where a press of the right
arrow key starts a dot travelling from left to right, and the frame
numbers corresponding to presses of the left arrow key are stored in
an array (bb). The program works fine except that each key press
results in a random number of entries (between 4 and 6) in the array
bb. For example, two presses of the left arrow key in the duration of
travelling dot may result in:
bb=[161 162 163 164 165 259 260 261 262 263];
Each key press results in a series of 5 entries. I can use the first
entry of each series as the stimulus frame corresponding to a key
press, but I'd like to have a cleaner result. I do have a
FlushEvents('keyDown');
in the loop, but it does not seem to do any thing and the keyDown
event lingers for 4 or 5 frames.
I am using a 2 GHz PC running Windows 2000, MatLab 6.1 and the lastest
PsychToolbox.
Thanks!
Lei
% travelling dot
white=255;
[w,wRect]=Screen(0,'OpenWindow',white);
srcRect=[0,0,100,100];
dstRect=CenterRect(srcRect,wRect);
dotRect0=CenterRect([0 0 12 12],srcRect);
[dot offRect]=Screen(w,'OpenOffscreenWindow',white,dstRect);
Screen(dot,'FillOval',black,dotRect0);
white=255;
black=0;
d0=OffsetRect(offRect,0,0);
rightKey = KbName('right');
leftKey = KbName('left');
escapeKey = KbName('esc');
bb=[];
while 1
[a,b,keyCode] = KbCheck;
if keyCode(rightKey)
for i=1:300
dotRect=OffsetRect(d0,i,0);
Screen(w,'WaitBlanking')
Screen('CopyWindow',dot,w,offRect,dotRect);
[a,b,keyCode] = KbCheck;
if keyCode(leftKey)
bb=[bb i];
end
FlushEvents('keyDown');
end
end
if keyCode(escapeKey)
break;
end
end
FlushEvents('keyDown');
Screen('CloseAll');