Hello, I am attempting to allow a video to ONLY play when a key on the keyboard is pressed, and then the spacebar key is supposed to record when the participant is done pressing the other key. For instance, imagine a paused video and you must press the ‘c’ key for it to play AND continue playing, but once you are done watching, you can hit the spacebar key to move onto another video. I am rather new to programming, so any advice or assistance would be much appreciated.
— Run Routine “trial” —
while continueRoutine:
# get current time
t = routineTimer.getTime()
tThisFlip = win.getFutureFlipTime(clock=routineTimer)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *fixation* updates
if fixation.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
fixation.frameNStart = frameN # exact frame index
fixation.tStart = t # local t and not account for scr refresh
fixation.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(fixation, 'tStartRefresh') # time at next scr refresh
fixation.setAutoDraw(True)
if fixation.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > fixation.tStartRefresh + 1-frameTolerance:
# keep track of stop time/frame for later
fixation.tStop = t # not accounting for scr refresh
fixation.frameNStop = frameN # exact frame index
fixation.setAutoDraw(False)
# *video* updates
if video.status == NOT_STARTED and tThisFlip >= 1-frameTolerance:
# keep track of start time/frame for later
video.frameNStart = frameN # exact frame index
video.tStart = t # local t and not account for scr refresh
video.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(video, 'tStartRefresh') # time at next scr refresh
video.setAutoDraw(True)
if video.status == FINISHED: # force-end the routine
continueRoutine = False
# *response* updates
waitOnFlip = False
if response.status == NOT_STARTED and tThisFlip >= 1-frameTolerance:
# keep track of start time/frame for later
response.frameNStart = frameN # exact frame index
response.tStart = t # local t and not account for scr refresh
response.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(response, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'response.started')
response.status = STARTED
# keyboard checking is just starting
waitOnFlip = True
win.callOnFlip(response.clock.reset) # t=0 on next screen flip
win.callOnFlip(response.clearEvents, eventType='keyboard') # clear events on next screen flip
if response.status == STARTED and not waitOnFlip:
theseKeys = response.getKeys(keyList=['space'], waitRelease=False)
_response_allKeys.extend(theseKeys)
if len(_response_allKeys):
response.keys = _response_allKeys[0].name # just the first key pressed
response.rt = _response_allKeys[0].rt
# a response ends the routine
continueRoutine = False
# Run 'Each Frame' code from code
if video.status == FINISHED and checkvideo==1:
video.tStop=t
# videoframe=frameN
checkvideo=0
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineForceEnded = True
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in trialComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()