Presenting images that were onscreen during keypress

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

OS (e.g. Win10): Mojave
PsychoPy version (e.g. 1.84.x): 3.2.4
Standard Standalone? (y/n) If not then what?: Y
What are you trying to achieve?:
I’m trying to create an experiment where participants are first presented with a sequential stream of shapes (images). During the stream of shapes, participants are instructed to press the space bar at any time of their choosing. After the stream, participants are then presented with the shape that was onscreen during their keypress and 4 other shapes. Participants must identify which shape was onscreen during their keypress.

What did you try to make it work?:
I’m having trouble presenting the shape that was onscreen during the participants’ keypress. I have tried using a code element to tell psychopy, if a keypress was made during this time window, then present this specific shape.

What specifically went wrong when you tried that?:
However, this solution wouldn’t work if I wanted to randomise the presentation of the shape stimuli.

Can anyone offer any advice on how this could be coded?

Thank you!