Using Psychtoolbox KbCheck() functions, how can I test for a renewed keypress?

조회 수: 52 (최근 30일)
In my experiment, I would like to record participants' responses recorded as keypresses on every trial. I am recording responses with the following code, wherein KbActive is a variable containing all active response keys and responseGiven = 0 by default.
[keyIsDown, timeSecs, keyCode] = KbCheck([],kbActive);
if keyIsDown & responseGiven == 0 %no response registered so far
KbWait();
keyPressed = find(keyCode, 1);
keyName = kbLabels(keyPressed);
.....
end
Subjects are asked to press a button on every trial and each renewed button press should be registered. Using the current code, however, a response is also registered on each trial when continuously pressing down the button. Thus, instead of checking for a new response, the function just checks whether any key is down and does not differentiate whether the the key is pressed in the current trial, or whether it is still pressed for the previous trial, which would constitute an invalid response.
I considered using the function KbReleaseWait() to circumvent the problem of registering continuously pressed buttons as responses. However, using this function introduces another problem. When using this function, the experiment stops until the key is released, which introduces unintended timing inaccuracies in my experiment.
From the specifications and descriptions of KbCheck and related functions I am not certain whether I can check for renewed keyboard pressed on every trial using Psychtoolbox extensions. Could you help me clarifying this question?

채택된 답변

Jeff Miller
Jeff Miller 2023년 5월 15일
One approach is to check timeSecs. This will be very small if the key is continuously held down from the previous trial, but presumably much larger if the subject has made a new response to something that happened just before you called KbCheck.
  댓글 수: 3
Jeff Miller
Jeff Miller 2023년 5월 16일
No, sorry, I don't know of any such function. Someone on the Psychtoolbox discussion group might. If not, it should be possible to write one using KbCheck to tell you which keys are pressed at each instant. You would have to read and hold onto the set of keys that were already pressed at the beginning of the time frame, and then ignore these as you used KbCheck to check again repeatedly during your time frame. (Maybe you would accept them as new responses if they were released and then pressed again within the time frame).
Kristin
Kristin 2023년 5월 16일
Dear Jeff Miller, thanks for getting back to me on my question. The 'workaround' you suggest sounds useful and I will try to implement it that way.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by