This looks like some sort of conflict between having a graphical Builder keyboard component (I’m guessing called key_resp_2
) and your code. Since you are checking for keypresses yourself (via event.getKeys(keyList=['j','f'])
), you have no need for a graphical keyboard component as well. Simply delete that component.
What might be happening is that the graphical component collects keypresses that you miss, and then you add up to 6 more to its list .keys
. If so, the list should have a minimum of 6 entries that you detect, plus a variable number (0, 1, 2, …) of additional entries collected by the keyboard component before or after your code runs on each screen refresh. As you don’t detect them, you also aren’t counting them.
So just store your collected key presses and reaction times in your own lists. At the end of the routine, you will need to save these in the data manually using
thisExp.addData('keys', your_key_list_variable)
and similarly for the RTs. Or, more conveniently, you might even want to save each keypress and RT into its own column: that will be easier to analyse, rather than having them all collected together into a single column, which would then need to be split apart at the analysis stage.
e.g.
theseKeys = event.getKeys(keyList=['j','f'])
if len(theseKeys) > 0: # at least one key is pressed
keyboard = keyboard + 1
# store current time in column rt_1, rt_2, etc:
thisExp.addData('rt_' + str(keyboard), t)
# store response:
thisExp.addData('key_' + str(keyboard), theseKeys[0])
# if 6 keys have been pressed, stop:
if keyboard == 6:
continueRoutine = False
I’ve shifted the check whether 6 keypresses have happened to inside the keypress detection code, or else finishing the routine will always happen one screen refresh period late (not the end of the world, but it is good to pay attention to these things).