I have a script in Matlab (psychtoolbox) in which I have coded a visual analog scale, anchored at 0 and 100, on which participants move a marker by holding down the left and right arrow-keys. The participant has five-seconds to move the marker to the desired location before the experimental protocol moves on to the next stimuli.
In working to code something similar in PsychoPy, I have created the following test code:
from psychopy import visual, core
win = visual.Window([800,800])
# rating scale
scale = visual.RatingScale(win, low=0, high=100, size=2, tickMarks=['0','100'],
markerStart='50', marker='circle', textSize=.5, showValue=False,
showAccept=False, noMouse=True, maxTime = 5)
while scale.noResponse:
scale.draw()
win.flip()
win.close()
This code actually works pretty well to get started, but I have a problem with the way the keyboard input works. The marker only moves 1-point (between 0 and 100) every time the user presses and releases the key. The desired outcome is to have the marker move continuously as the left or right key is pressed. My thoughts are that I can accomplish this by editing the underlying code for PsychoPy, though I feel this is a little out of my comfort zone. Any help for alternative methods would be greatly appreciated. This is only a start for the code, so anything goes!
Thank you, Patrick
I think this query solves your issue: PsychoPy Key Down Code using ioHub
rating.markerPlacedAt is what you need to update every frame. Here's a stripped version of my (rather raw) adaptation of the each frame section:
for event_io in keyboard.getEvents():
if event_io.type == EventConstants.KEYBOARD_PRESS:
if event_io.key == u'right':
increment = 0.01 # move one step to the right
elif event_io.key == u'left':
increment = -0.01 # move one step to the left
if event_io.type == EventConstants.KEYBOARD_RELEASE:
increment = 0 # stop changing position
if 0 < rating.markerPlacedAt < 1:
rating.markerPlacedAt += increment