Using keyboard press to move slider.marker continuously online and on local device

I have created an experiment that works well on my device and is in the process of being run online. The experiment keyboard keys to move the slider.marker left and right. Currently, the keyboard moves the slider.marker in set increments in either direction, is it possible to create a code that allows the slider.marker to move continuously when the keys are pressed down? I tried this code (3 pictures) in the begin exp tab, but it is JS so I am not sure if it works yet, as my experiment has not been put online yet. Is there an alternate code I can try that will work on both my local device and online? I also have this in my “each frame” tab. This code allows each key to indicate a certain direction.

"#creating option to confirm slider location
if ‘3’ in key_direction_resp.keys:
slider_locked = True

#setting left and right directions using button press
if not slider_locked:
if ‘1’ in key_direction_resp.keys:
slider_Objects18in.markerPos -= .1
elif ‘2’ in key_direction_resp.keys:
slider_Objects18in.markerPos += .1
#counting following frames
thisFrame += 1 "

Have a look at my interactive slider demo. I think I sorted continuous keyboard movement for it.

Thank you @wakecarter ! I see there are two scripts, java and python to do this. This experiment will be run online so I assume I should use the JS? Is there a set of lines that you recommend to use that is specific for keyboard presses to be continuous? As I will not be using mouse responses in my experiment. Could line 775 - 814 work? Again much thanks for your help!

Please open the Builder file

@wakecarter i have run into two issues:

  1. my experiment requires the ‘slider’ instead of the ‘rating’ slider style. I tried to change this by adding a code in the begin experiment tab (slider_style='slider), however this does not do the trick.

  2. secondly, my experiment uses the 1,2, and 3 keys. 1 moves the slider marker left, 2 moves the slider marker right and 3 confirm the slider marker location by ‘locking it.’ Upon running my experiment, when any of these keys are pressed, there is no movement in the slider marker position. Below is the code I have

@wakecarter update: i figured out how to fix my first issue with the slider type! However, the keyboard button presses are still giving me issues.

@wakecarter hello, what is the difference between your slider code and islider code? Also, I am still having a few issues with my device recognizing my button presses (1,2, and 3 key). Thank you!

My slider code uses the slider component as a base whereas my iSlider is completely created using code and other components.

Have you set keysWatched in Begin Routine (or Begin Experiment)?

keysWatched=['1', '2', '3']

Both of my sliders have a keyboard code component that is set to Both to cope with Python/JS differences.

In your code you have keysWatched meaning something else, or have an error in understanding my code.

if '3' in keysWatched will immediately lock the slider if you have keysWatched as the keys to watch rather than the keys that have actually been pressed.

I have this in my begin routine tab, which has a 1,2, and 3 for keys watched. Do I have to change this code or the every frame code to ensure that the slider is not locking before a key press?

You need to change the Each Frame code.

You have put keysWatched=[‘1’, ‘2’, ‘3’]

which means that if ‘3’ in keysWatched is true.

I see, I’ve deleted the keysWatched=[‘1’, ‘2’, ‘3’] from my begin routine. I am still running into the issue that I started with: the marker is still moving in increments rather than smoothly along the slider. I have tried changing my slider does not move smoothly along the slider_granularity =.1, sliding =slider_granulairty and slideSpeed=3. I’m assuming my error is with one of these 3 variables?

hi again @wakecarter , possibly could the reason the slider speed is going slowly and still in increments be because of the amount of dashes I have? My slider has 36 dashes.

You could count how many key presses take you from one end to the other. Certainly the increment for each key press is important.

since there are 36 dashes, is it possible to create a code that allows the slider to continually move along the 36 dashes when the keys are pressed rather than jumping from each tick mark to the next? or is it as simple as creating a variable: slider_increment = continuous? I am having trouble narrowing down the line in your builder that allows the left and right keys to produce continuous movement in each direction.

For smooth movement you need slide increment as continuous (or as high as you want for each key press)