I would like to ask the user to respond to a question with a key press and then click the button below to move to the next question. In my code the key response is registering whether its left or right mouse. it would be of great help if someone could point out what is wrong?
> [keyIsDown1, RTkeyCode1] = KbCheck;
> Q_1=find(RTkeyCode1);
> EUR_rating=KbName(Q_1);
> rating.EUR=EUR_rating;
> timer1_end=0;
> [x1,y1,buttons1]=GetMouse(window);
>
> if IsInRect(x1,y1,rect58)
> Screen('FrameRect', window , [1 0 0], rect58,5)
> if any(buttons1)
> timer1_end=GetSecs;
> Q1=0;
> end
> end
Your question is unclear to me, but you need to run your code depending on if the user actually pressed the button, so you need to:
noResponse = true; %determine when to leave while loop, could also use break directly
while noResponse
[keyDown, keyCode] = KbCheck(-1);
if keyDown
% the rest of your logic should be here
if any(buttons); noResponse = false; end
end
WaitSecs('YieldSecs', 0.01); %throttle the loop a bit
end
Or use KbWait that saves you having to run the outer loop…
Thanks for the response. I didn’t mean that. Let me rephrase myself, I’m presenting a question which asks them to rate something and the user gives their answer by giving a key response, in this case they rate it by a number. after giving the response, the user need to click on a rect on the same screen,right below the question to move to the next question.