Slider marker won't stop moving after keyboard button press

I have created an experiment where participants use the 1 & 2 keyboard keys to move the slider marker left or right and the 3 key to confirm their selection (lock slider marker position). For some reason, once the 1 or 2 key is clicked, the slider marker will move in the correct direction but it continues to move in that direction even with the key is not being pressed. My slider width is ‘1’ and I have the following code specific for the button press:

I think the issue might be that you’re wanting to monitor for key lifts as well as key presses at the moment the if '3' in key_direction_resp.keys is going to continue identifying that 3 is in the list of pressed keys even after a lift has occurred. Here are 2 possible suggestions that might help.

  1. wrap a loop around your routine containing your slider and set nReps to be something huge like 1000. Set your keyboard to force end routine on press and in the End Routine tab execute your code where the slider marker is adjusted.

  2. Use custom code akin to this where the code monitors if a key duration has been returned (and that key has therefore been lifted)

Hopefully this helps!

Becca

Hi @Becca
Thank you for your response! Quick question about the first option-- if I use the keyboard press to for the end of the routine, won’t clicking the 1 or 2 key immediately end the current trial? Meaning that participants wont be able to move the slider to the location desired with the key press?

Maybe this helps with Beccas option 2:

I have just added a complete demo project for continuous mouse and key presses in my demo post here: PsychoPy Online Demos - #8 by Luke

(Gitlab Luke Boelling / continuousMouseAndKeyPressesDemo · GitLab)
In the last routine of the project I demonstrate how to move a ball left and right. This can easily be adapted for your slider code (looks very similar to your current code)

The main idea:
Add a keyboard component with options: all keys and non routine ending. This keyboard component keeps track of all presses and releases. Like Becca said: monitoring which Button has no duration (mean: was not yet released) is easy with a few lines of code.

hi @Luke
thank you for sharing! will look through your demo and see if i can add the changes to my code. much thanks to you both, will update on how it works!

hi @becca and @Luke
I tried to create custom code to fix this issue; however, I still have not figured out a way to indicate when the button has been pressed. I previously tried to use ==isPressed but this created an error. I have included a screenshot of my updated code. This move the slider marker; however, it still continually moves the slider marker rather than stopping when they key is released. I did realize though that it will only respond to the 1 and 2 keys the first time they are clicked. If they are clicked a second time during the trial, the slider marker will not move.

See attached a minimal working example with your desired behavior.
sliderKeyboard.psyexp (11.8 KB)

If you want to run it offline in Python you need to use PTB-Backend in your Keyboard-Component due to a bug in iohub-waitRelease-behavior (that should be fixed in the upcoming version BF: fix waitRelease=False behaviour for iohubKeyboard in hardware.keyboard by lboel · Pull Request #4846 · psychopy/psychopy · GitHub).

@Luke thank you so much! my issue was that I had not switched the keyboard component. Once I made this change my code work. Much thanks again!