If this template helps then use it. If not then just delete and start from scratch.
OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): Psychopy 3
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?:
I’m new to psychopy and python so sorry if I missed anything and/or the question is too simple.
I will show participants sequences of video clips. While watching, participants rate the valence of each video continously on a 0-100 scale.
Three things I’m confused:
- I have a slider and I’m trying to add a code component so that participants can either use the “left” and “right” keys, OR the mouse to move the marker continuously (without tapping or clicking), which means they should either press and hold keys, OR simply move the mouse without clicking to move the slider. How could I accomplish this? Either the keyboard plan or the mouse plan would work.
- And if it is possible, how could I record the continuous ratings for each video clip (and timestamp the ratings)?
- How could I set the starting position of the marker in the current trial to the end position of the previous trial?
What did you try to make it work?:
For the “keyboard” plan:
I’ve tried the code in this post: Controlling slider with keyboard which showed how to use left and right keys to move slider.
# Begin routine event.clearEvents('keyboard') slider.markerPos = 50 # Each frame keys = event.getKeys() if len(keys): if 'left' in keys: slider.markerPos = slider.markerPos - 1 elif 'right' in keys: slider.markerPos = slider.markerPos + 1
There are two problems with this one:
- Need to tap the keys again and again to move the marker, but what I want is “press and hold”.
- The slider starts at a specific place, but I want it to start at the end position of a previous trial. I tried sth like “slider.markerPos = slider.markerPos” in the Begin routine tab but the marker won’t show up this time.
I’ve tried to modify the code provided this this stack overflow post PsychoPy - Move RatingScale marker continuously on key-down as below. But the experiment won’t run without throwing an error.
# Begin experiment from psychopy.iohub import launchHubServer, EventConstants io = launchHubServer(experiment_code='key_evts', psychopy_monitor_name='default') keyboard = io.devices.keyboard # Begin routine increment = 0 # initial value of increment # Each frame for event_io in keyboard.getEvents(): if event_io.type == EventConstants.KEYBOARD_PRESS: if event_io.key == u'right': increment = 1 # move one step to the right elif event_io.key == u'left': increment = -1 # move one step to the left if event_io.type == EventConstants.KEYBOARD_RELEASE: increment = 0 # stop changing position if 0 < slider.markerPos < 100: slider.markerPos += increment
I’ve also tried the “press and hold keys” JS in this post Press and Hold Key to Move Slider by modifying some parameters, but the experiment won’t even run and I’m not getting any error.
For the mouse plan:
I’ve tried the code in this post Is it possible to make a slider object only interactable by dragging the marker?. The code works but I need to click on the mouse to drag. What I want is simply moving the mouse to move the slider.
I’ve searched online for many days and still have no clue about how I could realize this, and record the continuous ratings from the keys/mouse (and timestamp the ratings), and set the starting position of the marker in the current trial to the end position of the previous trial? Any help would be appreciated!