I'm trying to collect keyboard data, but I can't get KbWait to work. In the following code, I'm trying to wait for the participant to respond, check if their response is one of two acceptable answers, and then continue. It should only continue when the participant presses 'j' or 'f'.
response = []; while isempty(response)&&(GetSecs - FlipTimestamp) < 10 [keyIsDown, RTsecs, RTkeyCode, deltaSecs] = KbWait; if keyIsDown r=find(RTkeyCode);%this should be the code for the key pressed response=KbName(r);%Figure out what key was pressed rt=num2str(RTsecs-time); %subtract off timestamp from when window was flipped if response == 'f' match_response= false; end if response == 'j' match_response= true; end end end
However, KbWait never returns. When I try to run it from the command line, it doesn't work either. It just hangs up and refuses to return, and I have to interrupt the program.
It's been nine months since you posted this, so I imagine you've already found some sort of solution. But I was also having this problem, and here's what I discovered:
I went through my entire HID list: devices = PsychHID('Devices') As I examined each one's 'usageName' property, I found that multiple devices were considered to be 'Keyboard', even though I only have one actual keyboard connected.
I then tried each one's index as an argument for KbWait. When I got to the correct one, KbWait worked.