Timestamp of trigger in NIRx does not correspond to button press time in Psychopy

Hello,

I am attempting an experiment which will function as a timer that will both record the amount of time between 2 button presses and send an event to our fNIRS recording upon each button press. The idea would that that this will record and display the time it takes a participant to complete a task as well as insert events into the fNIRS data for the task start and stop. Then my research assistants can record the time as shown on the screen of the experiment afterwards, rather than having to manage a timer while inserting event codes into the data on their own.

The experimenter will press the spacebar to bypass the intro screen, press spacebar again to start the experiment, press a third time to end the experiment.

My issue is that the timing of the button press (as identified per the .log file), the time elasped as recorded on the the screen, and the time between the event triggers all do not match, and I’m unsure the reason for this. For example, in a recent trial, the difference between the start of the trial and the end are:
Per on-screen display: 16.66 seconds
Per the log file (time between the button presses): 16.62 seconds
Per the time between triggers in the fNIRS data: 19.26 seconds

My experiment is also attached, but here is a list of when each trigger is programmed to be sent. I have 4 routines: setup, LapStart, LapEnd, and EndStudy

trigger 1 - coded in “each frame” of LapStart:

if key_resp.keys and not response_sent:
    # Get the key that was pressed
    pressed_key = key_resp.keys[-1] # Gets the most recent key press

    # Define the marker value (can be a string or integer, LSL handles various types)
    
    
    # Send the LSL marker
    outlet.push_sample(['1'])
    print(f"LSL marker sent: {1}") # For debugging in the output window
    
    # Mark the response as sent to avoid sending multiple triggers for the same keypress
    response_sent = True

trigger 2- coded in “end routine” of LapStart (to be honest i am not totally sure the function of this trigger, this experiment is based on code I copied from a different experiment I had as a reference)

outlet.push_sample(['99'])

trigger 3- coded in “each frame” of LapEnd:

if key_resp.keys and not response_sent:
    # Get the key that was pressed
    pressed_key = key_resp.keys[-1] # Gets the most recent key press

    # Define the marker value (can be a string or integer, LSL handles various types)
    
    
    # Send the LSL marker
    outlet.push_sample(['1'])
    print(f"LSL marker sent: {1}") # For debugging in the output window
    
    # Mark the response as sent to avoid sending multiple triggers for the same keypress
    response_sent = True 

When I look in my fNIRS data, I have 3 types of events: 1, 2, and 99. Event value 1 has 2 inputs, the second of which is the same as 99. Event value 2 is the latest value by some time. Regardless of which event code onset I use, I cannot get the elapsed time to equal what is printed to the screen or the time I calculate based on the button presses in the log file.

Thank you very much, and apologies if the solution is obvious- I do not have any prior experience with Python.

TUG1.psyexp (42.7 KB)