Basic Way To Do EEG Response Triggers

Hello all, I have created EEG response triggers using the Parallel Out component and a really basic bit of code. Other threads I have found on this subject seem to be using quite a bit more complex coding, and so I was wondering if this is good way to accomplish this or if I’m going to have some timing errors in my data or something. I am still very new to coding and PsychoPy.

The triggers sent are dependent on how the particpant responds to a stimulus using a keyboard. The keyboard response ends the routine, so I just added another routine after the trial in the loop that consists of 1) code then 2) Parallel Out.

Here is the code:
*** Begin Experiment ***

pressed = False
resp_id = 0

*** Begin Routine ***

if key_resp.keys == 'y':
    resp_id = 1
    pressed = True
elif key_resp.keys == 'n':
    resp_id = 2
    pressed = True

The start time on the pport is set to 0s, the duration to 0.05s. Start data set to $resp_id. “Sync timing with screen refresh” and “Sync to screen” are both off. The keyboard response component also has “Sync timing with screen” off.

Hopefully this can help anyone else trying to do response triggers (unless something is wrong with my method, then don’t do this). Feedback welcome.

EDIT: I don’t need to have the “pressed” variable in the code. That accidentally got left in from when I was trying to do this another way.

PsychoPy version: 2022.2.2
OS: Win10
EEG Recorder: g.Recorder

triggertest.psyexp (13.3 KB)