带数字键盘的心理评级量表

psychopy ratingScale with numeric keypad

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

照原样,ratingScale 不接受使用数字键盘的响应。我可以用 respKeys 更改它,但我必须提供 "A list of keys to use for selecting choices, in the desired order"。这意味着我不能同时允许 '1' 和 'num_1' 到 select 第一评级(例如 respKeys = ['1','num_1, '2', 'num_2', ...] '1' 将 select 第一评级,'num_1' 第二个,等等)。

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

感谢您的帮助!

我不认为 visual.RatingScale 有任何内置方法可以为同一刻度位置获取多个键盘键。

如果您使用的是编码器,则可以使用 event.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 列表并在其中搜索匹配项。对不起 bad/ambiguous 变量名,但我现在想不出更好的办法。

此解决方案可能也适用于 Builder。只需删除 "initiate psychopy" 内容,将 scale 更改为您的 RatingScale 的名称,然后将代码粘贴到 RatingScale 上方的代码组件中。