Recording button press '5' thought the whole experiment in new csv file

PsychoPy version v2024.1.4
What are you trying to achieve?:
My goal is to design an experiment for an fMRI study where participants view a series of face images and rate them on a scale from happy to sad using button presses numbered 1 to 3. Additionally, the fMRI system sends a ‘5’ key press every 2 seconds, and I need to log these signals in a separate CSV or Excel file for the entire duration of the experiment.

What did you try to make it work?:
Unfortunately, my initial attempt to create a single code to run throughout the experiment failed as I am new to Psychopy and coding. I couldn’t find a way to make it work for the entire duration of the experiment. Consequently, I decided to include a keyboard response in each routine, accepting only the ‘5’ key press and record this separately than the participant key presses. Although this solution may not ensure precise timing, it was the best workaround I could devise.

Currently, my focus is on recording the elapsed time since the start of the experiment (initiated by the ‘5’ key press) for each subsequent ‘5’ key press. I’ve started implementing this feature for the first routine, but my new data file (named date_participantID_sessionID_log_5) appears to be missing some key presses, and I am unable to advance to the next routine.

Is there a better way to record the ‘5’ key presses thought the experiment? If not, I would greatly appreciate some help with my current code.

Here is my experiment so for reference:
FRET_V1_sarah - log5.psyexp (68.9 KB)
FRET_V1_sarah - (86.5 KB)

Here is one of my conditions file for the inner loop:
station_1_conditions.xlsx (10.9 KB)