Ending Trial after Two Key Responses

Hi, I am designing an experiment where participants are required to enter two key responses to complete a trial. (sequence of key presses does not matter and both keys must be correct). This is the code I am using to record data.


However, I am facing two problems currently.

  1. The trial would not end after participants have input two responses, it only proceeds after the duration for the keyboard component I have set.
  2. The experiment would close itself if there is no responses after the set duration. I would like it to proceed to the next trial instead in this case.
    I have no experience in coding at all but I dont think I can implement two key responses just using builder. I appreciate any help I can get.

Hello,

add the following code to the Each frame tab of a code-component that follows your key-board-component.

if len(key_resp.keys) == 2:
    continueRoutine = False

Note that you have to adjust the keyboad-name. I used the PsychoPy-default keyboard-component name.

In you code above, it seems that you want to store the correctness of the answer as well, don’t you?

Best wishes Jens

Hello,

in case you want to save the correctness of your key-presses, add the following code to the End routine tab of your code-component.

if key_resp.keys == ['1', '2'] or key_resp.keys == ['2', '1']:
    key_resp.corr = 1
else:
    key_resp.corr = 0

thisExp.addData("key_resp.corr", key_resp.corr)

In this example, 1 and 2, are correct answers. Order does not matter. Both answer have to correct to be counted as correct.

Best wishes Jens

Thank you, i will try that out. I found a workaround with the builder where i only store data of the first key press while the second key press will end the routine. However, participants would then have to press the first key first, if not it will end the routine without logging the other key press. With your solution, I can implement it properly now.

Everything is working as intended now except that the data produced set all the responses as false (resp.corr = 0) despite routines being correct. Here are some screenshots.
excelufovinfo

excelufov2
the data file.

Hello Woon

ok, the problem is that you compare resp.keys to the strings corrAns1 and corrAns2. resp.keys is however s, right, down, up, left or right. I used just ‘1’ and ‘2’ as an example. You need to change the if-else construction to

if resp.keys == [str(corrAns1), str(corrAns2)] or resp.keys == [str(corrAns2), str(corrAns1)]:
    resp.corr = 1
else:
    resp.corr = 0

Best wishes Jens

Thank you so much for your help, it works perfectly now!

Best,
Woon