From: Chris on 30 Jul 2010 14:55 Hi, I am trying to get reaction times from two key presses. I have code that works, but the goal of the program is to have two players press different keys as close to each other as possible (within 15ms of each other) and sometimes it doesn't record a second key press if they are too close. Is there a way to do this? Here is the code: while GetSecs < startSecs + duration %shows the image (at the bottom of this while loop %called greenCircle (function) for a specific amount of time. When they see the circle, they %have to press the buttons as close to the same time as possible. [ keyIsDown, t1, keyCode ] = KbCheck; %Player 1 if keyIsDown %while KbCheck; end %key1 = toc(tStart); key1 = GetSecs; w = find(keyCode); if w == keyCode(escapeKey) exit = 1; break; elseif keyCode(targetKey2) || keyCode(targetScan2) rt2 = key1 - startSecs; %rt2 = key1; elseif keyCode(targetKey1) || keyCode(targetScan1) rt1 = key1 - startSecs; %rt1 = key1; elseif w ~= keyCode(targetKey1) && w ~= keyCode(targetKey2)&& w~=keyCode(escapeKey) wrong(eventWrong, t2, window, target1, target2, frontcolor, readycolor, outline, gocolor, greencircle); end FlushEvents(['keyDown']); end %Player 2 [ keyIsDown, t2, keyCode ] = KbCheck; if keyIsDown %while KbCheck; end %key2= toc(kStart); key2 = GetSecs; w = find(keyCode); if w == keyCode(escapeKey) exit = 1; break; elseif keyCode(targetKey2) || keyCode(targetScan2) rt2 = key2 - startSecs; %rt2 = key2; elseif keyCode(targetKey1) || keyCode(targetScan1) rt1 = key2 - startSecs; %rt1 = key2; elseif w ~= keyCode(targetKey1) && w ~= keyCode(targetKey2)&& w~=keyCode(escapeKey) wrong(eventWrong, t2, window, target1, target2, frontcolor, readycolor, outline, gocolor, greencircle); end FlushEvents(['keyDown']); end %after two button presses, the program moves on. if rt1 ~= 0 && rt2 ~=0 break; end greenCircle(window, readycolor, outline, gocolor, greencircle); end
|
Pages: 1 Prev: [Q] Programatically set bookmarks in matlab editor? Next: indexing a matrix with index pairs |