Key hold function in PsychoPy (for Visual Analogue Scale)

Hi, I have created a visual analogue scale in the PsychoPy builder. Each marker position on the sliding scale corresponds to a value 0-100. However, PsychoPy does not seem to allow you to hold down the left/right keys to move the marker along the scale. Instead, you have to press the left/right key repeatedly which means my participants may have to press it up to 50 times to get the marker to the correct position. I have read countless posts and even turned to Claude.ai and chatgpt to get help with this with no luck. (I am very new to coding). I will include my current code below which basically just allows me to use the keyboard to adjust the slider. CAN ANYONE HELP ME ADJUST MY CODE TO ALLOW KEY HOLD TO MOVE MY SLIDER? Cheers :slight_smile:

Begin routine:

slider.markerPos = 50

Each frame:

keysPressed = event.getKeys(keyList=[‘left’, ‘right’])

for key in keysPressed:

if key == 'left':

    slider.markerPos -= slider.granularity

elif key == 'right':

    slider.markerPos += slider.granularity

End routine:

thisExp.addData(‘slider_rating’, slider.getRating())

To continuously trigger an effect while a key is held down, what you need to do is:

  • Get keys that are pressed (without having to wait for them to be released, and without clearing them after checking)
  • Clear keys which are released

Which I think translates into code as (in Each Frame):

keysPressed = kb.getKeys(waitRelease=False, clear=False)
kb.getKeys(waitRelease=True, clear=True)

(assuming you have a psychopy.hardware.keyboard.KeyboardDevice object called kb)

I have example based on this method called Key-Down in PsychoPy Online Demos