Hi, I'm new to psychtoolbox and I'm trying to write a simple task code. The task is to click a mouse button and a stimulus pop out and I also want my Space Key to be the exit button from the trial. I wrote a code but it doesn't work. When using getclick and KbCheck at once a loop, KeyIsDown variable always come to be zero so no keypress is detected. if I remove getclicks I can use keypress. How should I write the could? here's the code I wrote:
I would appreciate your help.
%% Task Details
% Buttom Press Task for Marmoset In Cage Training
% Event Time Data Will Save in current Folder
% Version 1 11/4/2016
%%
clear all
clc
Screen('Preference', 'SkipSyncTests', 1)
%% Evaluate Number of Trials & Expriment Details
Prompt={'Number Of Trials','Subject Name','Expriment Name','Expriment Day','Expriment Number'};
defaultAns={'','Baner','ButtomPressTask','1142016','(1)'};
Answers = inputdlg(Prompt,'Information',1,defaultAns);
nTrials = str2num(deal(Answers{1}));
%% Define Task Details
[window_ptr, screen_dimensions]=Screen(0,'OpenWindow',[200 200 200]);
target= [(screen_dimensions(3)/2)-200,(screen_dimensions(4)/2)-100,...
(screen_dimensions(3)/2)+200,(screen_dimensions(4)/2)+100];
Beep= MakeBeep(2000,1);
f=100; dt=1/(5*f); t=0:dt:1; s=sin(2*pi*f*t);
t0= GetSecs;
%% Main Task
SpaceKey=KbName('space')
EscapeKey=KbName('esc')
for t=1:nTrials; nTrials=t;
while 1
Screen('Flip',window_ptr);
[keyIsDown, secs, keyCode] = KbCheck;
if keyIsDown==1 && keyCode(Space)
sca;
break;
elseif keyIsDown==0 && GetClicks PressBottum(t)=GetSecs-t0; %column 1
Screen(window_ptr,'FillRect',[0 0 0],target);
Screen('Flip',window_ptr); TargetOnset(t)=GetSecs-t0; %column 2
sound(s); SoundOnset(t)=GetSecs-t0; %column 3
WaitSecs(1); EndTrial(t)=GetSecs-t0; %column 4
break;
end
end
end
sca;
%% Create & Save Event Time Matrix
EventTime=[PressBottum;TargetOnset;SoundOnset;EndTrial];
save([Answers{2,1},Answers{3,1},Answers{4,1},Answers{5,1}],'EventTime')