I am currently programming an experiment in which participants have to synchronize their finger tapping with a visual metronome (a pulsating dot in the middle of the screen).
The presentation of the dot with a fixed frequency works fine.
Now I would like to let this stimulus appear and disappear until the participant has pressed a key 10 times (and thus have tried to synchronize their keystrokes with the pulsating dot 10 times).
I made a routine and set a loop around it with a high number of nReps (999), a number of repetitions which would certainly not be reached.
I included the code below to end the loop prematurely if the required number of keystrokes is reached.
Below you can find the code I tried, the flow, and key properties.
The dot is now showed only once. So, the program is waiting for a keystroke, but if I press the allowed key nothing happens (because the force end of routine option is not ticked). If I tick this box, the dot appears only if the key is pressed, which is exactly what I do not want, because the stimulus presentation and keystrokes should be independent of each other.
If I include only the code without the key component the stimulus is displayed for the amount of nReps which means the code I tried does not suffice to terminate the loop prematurely.
What I want to achieve is to keep track of the number of keystrokes and log the timing of each of them, independent of the stimulus presentation, and end the loop as soon as the required number of keystrokes is reached.
Every offered insight is much appreciated.
# define theseKeys theseKeys = event.getKeys(keyList=['k'])
# end loop after certain amount of keystrokes if len(theseKeys) == 10: trials.finished = True continueRoutine = False