Hello, everyone.
I am struggling to code a problem to record participants’ responses during the presentation of a moving stimulus (random dot kinematograms, RDK ). Since the RDK is a frame by frame changing paradigm, I put KbCheck into this loop. However, I can’t record the response. I have struggled with it all day with no solutions. Can anyone give me any advice?
Thank you very much
Provide information about your OS, matlab version and PTB version (you are fully up to date)? Do the keyboard demos work for you? If so, provide minimal code that doesn’t work (not your whole program)
Thank you for your reply.
My OS is Catalina (version10.15.7), Matlab is 2021a, and PTB is PTB-3. KbDemo works fine with my computer.
My code is:
keyIsDown = 0;
for frameNum=1:nFrames % nFrames = 60, that is, RDK lasts one seconds
DrawRDK in one frame;
Flip;
[ keyIsDown, sec, keyCode ] = KbCheck;
if keyIsDown
Record the keyCode and sec in my structure;
keyIsDown = 0;
end
end % end of for loop
It turns out the RDK stimulus works fine, but I can’t get any response even I press a key. When I debug it, it works if I keep pressing a key, so I can’t find any problems right now.
Thank you very much.
So if you put a disp('keyIsDown was TRUE!!!')
inside your if keyIsDown
loop do you ever see this message printed to the MATLAB window?
Try to pass -1
as a device number (KbCheck(-1)
) to make sure all keyboards are scanned.
And finally check that you don’t have a problem with ‘stuck keys’, see doc Kbcheck
for more details…
Dear Ian Max Andolina,
Thank you so much !!!
I took your advice and found my problem finally. It turned out my code in this “for loop” was correct. A minor problem far away from this loop existed, leading to no message when I put disp('keyIsDown was TRUE!!!')
. When I resolved that problem and used KbCheck(-1), everything went well.
Thank you so much! I have been stuck for two days because of this minor problem. You saved my day!
Best Wishes.