while 1
ch = GetChar
KbWait
if (ch>48) && (ch<53)
trial(j).RT = GetSecs - startTime ;
break;
end
end
here is my sample code, I am working on an Stroop Task, I am expecting to gatjer reaction time. Reaction time starts with stimulus presentation and end with key press. I use the code above to supress whole keyboard expect the numbers of 1-2-3-4. however, sometimes all keys can be pressed rather than just 1-2-3-4. I hav tried many times, it some times supresses keys sometimes it doesn't. I really do not understand the reason.
The GetChar() function waits for a keypress, or retrieves previously pressed keys from a queue: http://docs.psychtoolbox.org/GetChar . What may be happening is that you have previous keypresses in the queue which are being read by GetChar, even if they are not the most recent press.
However, it is recommended by the Psychtoolbox developers to not use the GetChar() function to collect response times. This is due to the timing prevision of GetChar() versus other functions such as KbCheck().
The following snippet could be used to poll the keyboard for a response time: