I’m working on an experiment where the subject must make 6 responses (say, ‘f’ key for numbers and ‘j’ key for letters) based on a 3x2 matrix of numbers and letters. The trial terminates after the first 6 responses have been made and my critical DV is trial length (i.e. time it took to make the 6th response). I’ve created a counter that begins each routine at 0 that I call keyboard. Here is my code for updating every frame
if keyboard == 6:
continueRoutine = False
theseKeys = event.getKeys(keyList=['j','f'])
if len(theseKeys) > 0: # at least one key is pressed
keyboard = keyboard + 1
key_resp_2.keys.extend(theseKeys) # storing all keys
key_resp_2.rt.append(key_resp_2.clock.getTime())
This works in practice, but looking at the data it seems like sometimes the counter is too slow and collects more than 6 responses.
Is there a way to get around this? I know with mouse responses the line “while.mouse.isPressed…continue”, is helpful for this issue but I can’t find a similar bit of code for keyboard responses.