Trying to show a circle around selected stimuli after keypress on Pavlovia

Hi everyone,

Description of the problem
I have not yet made the experiment public.
I am trying to get people to select one of the correct faces shown on the screen
They have to use the left or right button on the keyboard to indicate which one is correct.
The one face that is selected gets outlined with a circle after a keypress.
However, if the keypress is too early the circle does not show.
It only shows after two key presses.

The snippet of my code is here as follows:

if (key_resp.status === PsychoJS.Status.STARTED) {
        let theseKeys = key_resp.getKeys({keyList: ['left', 'right'], waitRelease : false});
        _key_resp_allKeys = _key_resp_allKeys.concat(theseKeys);
        _key_resp_allKeys = _key_resp_allKeys.concat(theseKeys);

        if (_key_resp_allKeys.length > 0) {
          key_resp.keys = _key_resp_allKeys[_key_resp_allKeys.length - 1].name;  // just the last key pressed
          key_resp.rt = _key_resp_allKeys[_key_resp_allKeys.length - 1].rt;
          key_resp.duration = _key_resp_allKeys[_key_resp_allKeys.length - 1].duration;
          delay_complete = false;     
          circle.pos = pos_keys[key_resp.keys];
          console.log(circle.pos, 'circle position');
          console.log(key_resp.keys, 'key pressed');
          console.log(key_resp.rt, 'reaction time');
          if (t >= 4.0 + key_resp.rt
 && circle.status == PsychoJS.Status.NOT_STARTED){
            circle.setAutoDraw(true);  
            circle.frameNStart = frameN;  // exact frame index
            circle.tStart = t;  // (not accounting for frame time here)
          }
          frameRemains = 4.0 + key_resp.rt + 0.5 - psychoJS.window.monitorFramePeriod * 0.5;  // most of one frame period left
          if (t >= frameRemains && circle.status === PsychoJS.Status.STARTED){
            circle.setAutoDraw(false);
            ground_truth_image.setAutoDraw(false);
            reconstruction_image.setAutoDraw(false);
            continueRoutine = false;
          }
        }
      }

Here is the image attached. I have not figured out why I have to press the keys two times. Thanks in advance for your help!

Screenshot 2024-02-12 at 19.29.27