我认为没有任何内置方法可以visual.RatingScale
为同一比例位置获取多个键盘键。
如果您使用的是编码器,则可以使用 hackevent.getKeys()
和visual.RatingScale.setMarkerPos()
. 因此,对于一个具有三个位置的评级量表的简单案例:
# 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()
我的解决方案看起来很复杂,但其中大部分只是处理keysLocation
列表并搜索匹配项。很抱歉变量名不好/模棱两可,但我现在想不出更好的办法。
该解决方案可能也适用于 Builder。只需删除“启动精神病”的东西,更改scale
为您的 RatingScale 的名称,然后将代码粘贴到 RatingScale 上方的代码组件中。