Last key press trigger delayed until beginning of next loop - parallel port

I am running an MEG experiment using psychopy. It is a motor learning task so participants learn 4-element finger-press sequences. They have 2 sequences to learn and each sequence is associated with an image (sequence cue), so far I have added in a trigger for the sequence cue which works well.

Then on the next routine I have added a trigger for the go cue (a hand that tells the participant they can now perform the sequence) and then for each key press.

The order of triggers: sequence cue, go cue, key presses.

The first problem: The last key press made (4th one) is triggered on the go cue of the next trial so only 3 presses and the go cue appear in each trial.

The second problem: The trigger for the go cue also appears for each key press as well.

What I have tried to do to solve this: I tried to move the parallel port in the builder below the keypresses and turn the sync to screen off as suggested in this post (Screen refresh delay in sending parallel port response triggers) and I have changed the code for the keypresses from the begin routine tab into the each frame tab. This is the code I use to trigger each key press which works:
if key_respB.keys == ‘7’:

if key_respB.keys == ‘8’:

if key_respB.keys == ‘9’:

if key_respB.keys == ‘0’:

Key press 7 is triggered on channel 5, 8 on channel 6, 9 on channel 7 and 0 on channel 8.

Although, when I move it to the each frame tab I still have the problem of the last key press being in the next trial on the go cue and each trigger appears on the same channel for the key presses.

This is what the builder looks like at the moment:

Any help would be much appreciated!

Thank you,

I have found a way to partly solve this:

I turned off the sync to screen and sync to screen timing for the key presses and changed the parallel port code to condition: key_respB.keys


When I make these changes it sends a separate trigger for each key press all in the same trial, however now even if I get the sequence correct the feedback gives me 0 because the correct answers list contains a None at the end e.g. if correct sequence is 7, 8, 9, 0 it shows that the correct sequence was 7, 8, 9, 9, None. When I sync the timing to the screen this doesn’t occur but then the previous issue I had comes back. If anyone knows a way to solve this, let me know.

Thank you!