Space bar to continue routine, only after a button press

Hi all, im using psychoPy builder for an experiment where the participant can press either 1 or 2 when an image appears. Then, they must press space bar to continue to the next item in the routine. The problem of my current setup is that space bar allows to continue regardless if a choice has been made, and I want the button press of 1 or 2 to be required to continue.

I found a nice exakmple with this experiment that uses a rating scale here; however, I am not sure how to apply this to my example.

Like the user in the above link, I am using a keyboard component for this, which is apparently not the right way to go about it.

Is it possible to tell psychopy to only continue the routine if a 1 or 2 has been pressed, by pressing spacebar? Second, is it possible to this and have only the last key stroke of 1 or 2 be passed on to my data output?

Hi all, bumping this post up. Is there any other information that would be helpful to get some help on this problem?

Sincerely,

Alex

Hi there - if you’re using Builder, the following components work for me:

  • Image component for the image with an infinite duration
  • Keyboard component named key_resp (or whatever other name) with:
    • An infinite duration
    • Unchecked ‘Force end of Routine’ as this would make any of the allowed keypresses end the trial
    • '1', '2' as the ‘Allowed Keys’
  • A code component under the ‘Each Frame’ tab (as you want to run this code during the routine, on each frame, as per the documentation here) with the following snippet:
response = key_resp.getKeys() # grab keypresses
if '1' in key_resp.keys or '2' in key_resp.keys: # first check
    if response and 'space' in response: # next, check subsequent spacebar press
        continueRoutine = False # end routine

Hope that helps.

1 Like

Thank you sooooo much! This did the trick :smiley: