Ask participants for button press?
Show older comments
Hi guys,
I programmed an experiment and I am rather new to Psychtoolbox and Matlab and one thing is not quite working. I began to try to code the sequence by myself and then I just copied a piece of code from the psychtoolbox tutorial page and it is still not working. That's why assume there might be another problem I haven`t thought about?
I display two pictures in my experiment and I want participants to answer with the left respectively right arrow key before the next pair of pictures is shown.
Here is what I did:
leftKey=KbName('LeftArrow');
rightKey=KbName('RightArrow');
escape=KbName('ESCAPE');
resp==true;
while resp==true;
[keyIsDown,secs,keyCode]=KbCheck;
if keyCode (escapeKey)
sca;
return
elseif keyCode(leftKey)
response=1;
resp=false;
elseif keyCode(rightKey)
response=2;
resp=false
end
end
Screen('Flip',window)
This works to escape but it does not register any answers :(.
I have also tried
while(~keyCode(leftKey))
[keyisDown,sec,keyCode]=KbCheck;
end
which unforuntnately does not switch to the next screen either.
And just to check whether left button presses are registered in any way, I wrote:
while (~keyCode(leftKey))
[keyisDown,sec,keyCode]=KbCheck;
end
... a left button press doesn't let me quit the loop either...
THANKS!!!!
3 Comments
Geoff Hayes
on 29 Sep 2016
Laurie - your comments indicate that the first set of code works fine for when the user presses the escape key but not when he or she presses the left or right arrow keys. Is this correct? If so, then put a breakpoint at the line
if keyCode (escapeKey)
and run your software. Press the left arrow key and check to see which element of keyCode is true. Does this match with
leftKey=KbName('LeftArrow');
Laurie Gerstenberger
on 30 Sep 2016
Mihaela Duta
on 11 Oct 2016
I would also suggest you add as a standard at the top of your experiment scripts the command
KbName('UnifyKeyNames');
As the help for KbName function states, this will ensure that at least the names of special keys (like cursor keys, function keys and such) will be shared between operating systems.
When getting inspiration from other people's scripts, or when migrating your own scripts to a computer with a different operating system that the one originally used to debelop the scripts, you may encounter issues with key name mapping. The above command will avoid such issues.
Answers (0)
Categories
Find more on Timing and presenting 2D and 3D stimuli in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!