In my task, I've been allowing responses using the numeric keypad (e.g 'num_1') as well as the regular numbers at the top of the keyboard (e.g. '1'). When I later ask for ratings using ratingScale
, I'd like both options to be available as well, but I don't know how to achieve this.
As is, ratingScale
does not accept responses with the numeric keypad. I can change this with respKeys
, but I would have to provide "A list of keys to use for selecting choices, in the desired order". This means I can't allow both '1' and 'num_1' to select the first rating (e.g. with respKeys = ['1','num_1, '2', 'num_2', ...]
'1' would select the first rating, 'num_1' the second, etc.).
Am I really stuck with either respKeys = ['1','2','3','4','5']
or respKeys = ['num_1','num_2','num_3','num_4','num_5']
?
Thanks for any help!
I don't think that there's any built-in ways for visual.RatingScale
to take multiple keyboard keys for the same scale location.
If you're using coder, a hack could be to use event.getKeys()
and visual.RatingScale.setMarkerPos()
. So for a simple case with a rating scale with three positions:
# Initiate psychopy stuff
from psychopy import visual, event
win = visual.Window()
scale = visual.RatingScale(win, low=1, high=3)
# A list of lists, each sublist being the keys which represents this location
keysLocation = [['1', 'num_1'], ['2', 'num_2'], ['3', 'num_3']]
respKeys = [key for keysLoc in keysLocation for key in keysLoc] # looks complicated but it simply flattens the list to be non-nested
# Present the ratingscale and wait for a response
currentPos = 1
while scale.noResponse:
response = event.getKeys(keyList=respKeys) # only accept respKeys
if response and response[0] in respKeys:
# Then loop through sublists and update currentPos to where the match is
for i, loc in enumerate(keysLocation):
if response[0] in loc:
currentPos = i
# Set the marker position and draw
scale.setMarkerPos(currentPos)
scale.draw()
win.flip()
My solution looks complicated but most of it is just about handling the keysLocation
list and searching it for matches. Sorry for the bad/ambiguous variable names but I couldn't come up with anything better right now.
This solution could probably also work in Builder. Just remove the "initiate psychopy" stuff, change scale
to the name of your RatingScale, and paste the code into a code component just above the RatingScale.