#Psychopy does not have a build-in pause function.
#here is the codes you can use with the coder component in the builder view
#I have a list of audios to play, I want to be able to pause the experiment by clicking some key on the keyboard, in case the participant wants to take a break. I also want to be able to resume the experiment when the participant comes back.
#Here’s what I did
#first, I made a routine and added a loop with a condition file. (If you have no idea what I am talking about here, please visit http://www.psychopy.org/builder/builder.html first)
#second, I added a sound component to the routine.
#third, I added a coder component to the same routine.
#In the coder component, under the “each frame” tab, I added the following codes
pauseKey = event.getKeys() txt = visual.TextStim(win,text='paused, press R to resume') txt2 = visual.TextStim(win,text='press P to pause') txt2.draw() if 'p' in pauseKey: td = win._toDraw win._toDraw = [] # hides whatever was being auto-drawn while not event.getKeys(keyList=['r']): txt.draw() win.flip() win._toDraw = td # restore auto-draw pauseKey = NOT_STARTED pauseKey = [] if 'escape' in pauseKey: core.quit()