Building a keyboard slider that works online

OS (Win10):
PsychoPy version (v2021.1.4):
What are you trying to achieve?:
Trying to build a slider whose marker moves with arrow keys and people can select their answer with the RETURN key.

What did you try to make it work?:
Followed the solution provided by @jon here: Rating scale reponse failure via keyboard

if slider_kbControl.markerPos is None:
    # sets to our first position (or a random number?)
    # and makes marker visible
    slider_kbControl.markerPos = 3

#check keys (just the ones we want)
keysPressed = defaultKeyboard.getKeys(['left', 'right', 'return'])
for key in keysPressed:
    if key == 'left':
        slider_kbControl.markerPos -= 0.5  # subtract 0.5
    elif key == 'right':
        slider_kbControl.markerPos += 0.5  # add 0.5
    elif key == 'return':
        # confirm rating by setting to current markerPos
        slider_kbControl.rating= slider_kbControl.markerPos

What specifically went wrong when you tried that?:
The slider does not work ONLINE. No marker is shown and the keyboard method for responding is not working. The response is recorded (and the routine ends) only when a mouse click happens.

Have a look at my interactive slider demo which works with arrow keys and mouse hover.

Hi @wakecarter, thanks for the quick reply. I’ve had a look at your demo, but unfortunately, I get some errors concerning “slider_granularity” being not defined (I’ve basically copy-pasted your codes in my experiment.

Also, did I get it right that I just need one of the two routines in your demo (trial or iSlide)?

Sorry, I’m new to PsychoPy, and I’m really trying everything I can to make it work.

Cheers

You also need the contents of the start routine. However, you do only need trial or iSlider.

Yes, I’ve also included the contents of the start routine, that is why I don’t know what is going on. But if that is the only solution, I will try again. I might be doing something in the wrong way.

Thank you.

Check that slider_granularity is set in Begin Experiment in a code component that is either above the slider or in an earlier routine.

Thank you @wakecarter, that was it!

I also just discovered that the online experiments only work with the UK keyboard (not the Italian one, as left and right keys correspond to up and down). Probably that’s why I wasn’t able to make it work with all the material I previously found on this forum.

Thank you again!

If the issue is that left is up and right is down on an Italian keyboard you can always code it for both eventualities.

Yes, I will try and do that, thank you :slight_smile: