How to disable trial response during feedback?

I have a loop that includes:

  • trial, with slider that works with left and right arrow keys to move the marker, and down key to submit a response
  • feedback based on correct response

I would like the feedback to simply display for the specified duration (1 sec), with no response enabled. However, whenever the down key is pressed during feedback or while feedback is loading, it records the slider’s random starting position as the rating and, without ever showing the slider, simply shows the feedback. How can I ensure that the down key only triggers a slider response when the slider stimulus is being displayed?

Here is the code I have for the slider:

if slider_kbControl.markerPos is None:
    # sets to our first position (4 or 5)
    # and makes marker visible
    slider_kbControl.markerPos = random.randint(4,5)
#check keys (just the ones we want)
keysPressed = event.getKeys(['left', 'right', 'down'])
for key in keysPressed:
    if key == 'left':
        slider_kbControl.markerPos -= 1  # subtract 1
    elif key == 'right':
        slider_kbControl.markerPos += 1  # add 1
    elif key == 'down':
        # confirm rating by setting to current markerPos
        slider_kbControl.rating= slider_kbControl.markerPos
        continueRoutine = False

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2022.2.1
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?: loop with keyboard-based slider and feedback

What did you try to make it work?:
I’ve tried using defaultKeyboard instead of event.getKeys.
I’ve also tried having the slider code under a conditional (if slider_active ==True), with slider_active being set to false after a response is recorded - somehow the slider is still working even when slider_active is false.

What specifically went wrong when you tried that?:
I’ve been unable to prevent the down key from triggering a slider response when the slider stimulus is not being displayed.

What about putting this in the “begin routine” tab of your trial routine?

event.clearEvents()

That is, event.getKeys() returns any keys that have been pressed since the function was last called (e.g. it will include any responses made in the preceding feedback routine). So at the beginning of the trial clear the event buffer, so that only responses occurring since the start of the routine are gathered.

Thank you so much Michael, that works! :smile: