Adding EEG Triggers to keyboard responses

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2020.1.3
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:
I’m trying to add EEG triggers/markers (via cpod) whenever I have a keyboard press (either button ‘1’ or ‘2’)

What did you try to make it work?:
I’ve tested the eeg trigger code separately and it works, but when i try to insert a code component to specify for the EEG trigger whenever a keyboard button is pressed, it doesn’t work. keyResponse is the name of my keyboard press. Code component as follow:

if keyResponse.keys == ‘1’:
for bm in range(1):
mask = 2 ** bm
print("activate_line bitmask: ", mask)
dev.activate_line(bitmask=mask)
elif keyResponse.keys == ‘2’:
for bm in range(1):
mask = 2 ** bm
print("activate_line bitmask: ", mask)
dev.activate_line(bitmask=mask)

What specifically went wrong when you tried that?:
The paradigm runs but i dont get the EEG trigger on my EEG recording software. I am however able to get a trigger if i just run the following:

for bm in range(1):
    mask = 2 ** bm
    print("activate_line bitmask: ", mask)
    dev.activate_line(bitmask=mask)

Hi There,

Is there a reason to communicate with your device via code component rather than the inbuild parallel/serial port components? (Details here)

If your keyboard response is ending the routine you can then have a second routine with a parallel/serial port at the start?

Becca