Latency on keyboard response for Stroop trials

Hello !

For the context:
The main task of my experiment consists of 4 blocks with different rewards/penalties conditions (one per block) and in each block there is 15 intervals with a duration of 6 to 9 seconds (randomized) in which the participants are expected to make as many Stoop trials as they can. The correct responses per second are recorded. There is a fixation cross before and after each interval. At the end of each interval, the score is displayed.

My issue:
For some trials when I press one key to answer to the stimuli it doesn’t detect the answer, I have to press multiple times on the same key for it to be detected.
My practice session for participants is a simplified version of my main task that runs well, I don’t have any problem with it. However when it comes to the main task, there is some kind of latency for some trials.

Could someone help me fix this please ?

Do you have a keyboard component and Each Frame code related to key presses?

Yes I do, this is the keyboard component:

And this is the Each Frame code:

# Each Frame
if interval_clock.getTime() >= interval_duration:
    continueRoutine = False

# Récupérer les touches actuellement pressées
keys = event.getKeys(['r', 'v', 'b', 'j'])

if keys:
    current_key = keys[0]  # Définir current_key comme la première touche détectée
    
    # Traitement simple et direct
    event.clearEvents()  # Vider immédiatement le buffer
    # Générer nouveau stimulus, etc.
    
    # Maintenant vous pouvez utiliser current_key
    if current_key == corrAns:
        points += 10
    
    # Vérifier si la réponse est correcte
    if current_key == corrAns:
        points += 10
    
    # Générer un nouveau stimulus aléatoire
    word_idx = rd.randint(0, len(word_list)-1)
    stroop_trials.setText(word_list[word_idx])
    stroop_trials.setColor(color_list[word_idx])
    corrAns = corr_list[word_idx]
    
    # Effacer complètement le buffer clavier
    event.clearEvents()

That would explain it. You have two keyboard components working against each other.

Thank you for your answer !

I modified the code as suggested in the blog post:

# Each Frame
if interval_clock.getTime() >= interval_duration:
    continueRoutine = False

# Récupérer les touches actuellement pressées
keys = []
if key_resp.keys: # Keyboard component should store all keys and not force the end of the routine
    if len(key_resp.keys) > nKeys: # Add nKeys = 0 in Begin Routine
        keys = [key_resp.keys[-1]] # keys must be a list
        nKeys = len(key_resp.keys)

if keys:
    current_key = keys[0]  # Définir current_key comme la première touche détectée
    
    # Traitement simple et direct
    event.clearEvents()  # Vider immédiatement le buffer
    # Générer nouveau stimulus, etc.
    
    # Maintenant vous pouvez utiliser current_key
    if current_key == corrAns:
        points += 10
    
    # Vérifier si la réponse est correcte
    if current_key == corrAns:
        points += 10
    
    # Générer un nouveau stimulus aléatoire
    word_idx = rd.randint(0, len(word_list)-1)
    stroop_trials.setText(word_list[word_idx])
    stroop_trials.setColor(color_list[word_idx])
    corrAns = corr_list[word_idx]
    
    # Effacer complètement le buffer clavier
    event.clearEvents()

But I still get the latency, what should I do ? I also changed the keyboard backend to PsychToolbox.

I think you should delete event.clearEvents() which you have twice.

Why don’t you want the trial to end on a key press? When does it end?

You are adding 10 points twice for a correct answer.

1 Like