How to repeat a stimulus/response within a trial/routine?

Hi, I’m very new to PsychoPy and honestly I am just trying to see if this is worth learning for my purposes. I’m trying to build an experiment where the participant is answering math questions using a text box answer. At the same time, every 15-45s I need a visual stimulus of some sort to appear in which they will need to make a key response for. So far every program that has a timeline interface like PsychoPy has not been flexible enough for me to use. Would this be possible here? Based on what I do know about PsychoPy, I figured I would need a stimulus to loop within a routine every 15-45 seconds and each trial or routine would just be one math question.

Thank you!

Within the routine you would add a code component and use the “Each Frame” code to control the stimulus. This sounds a bit like an event-based Prospective Memory task, except that the event isn’t synchronous with the background task.

Imagine you set up your visual stimulus during the instructions using an image component called pm_image then you could use the following code:

Begin Experiment

myClock = core.Clock()

End Routine just before the maths loop starts

myClock.reset()
pm_delay = randint(31) + 15
showImage = False
nImages = 0

Each Frame within the math loop

keys = event.getKeys()
if myClock.getTime() > pm_delay and showImage == False:
     showImage = True
     nImages += 1
     pm_image.setAutoDraw(True)
elif showImage == True and 'space' in keys:
     thisExp.addData('RT'+str(nImages),round(myClock.getTime()*1000))
     showImage = False
     pm_image,setAutoDraw(False)
     myClock.reset()
     pm_delay = randint(31) + 15

There are better ways to do the keyboard response and you could save the RTs to a list instead of a separate column, but hopefully you get the idea.