1

在我的任务中,我一直允许使用数字键盘(例如“num_1”)以及键盘顶部的常规数字(例如“1”)进行响应。当我稍后使用 询问评级ratingScale时,我希望这两个选项都可用,但我不知道如何实现这一点。

按原样,ratingScale不接受使用数字键盘的响应。我可以用 更改它respKeys,但我必须提供“用于选择选项的键列表,以所需的顺序”。这意味着我不能让“1”和“num_1”都选择第一个评分(例如,respKeys = ['1','num_1, '2', 'num_2', ...]“1”会选择第一个评分,“num_1”会选择第二个评分,等等)。

我真的坚持要么respKeys = ['1','2','3','4','5']respKeys = ['num_1','num_2','num_3','num_4','num_5']

谢谢你的帮助!

4

1 回答 1

2

我认为没有任何内置方法可以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 上方的代码组件中。

于 2015-04-16T21:50:30.770 回答