1

我想自动化我的PsychoPy Builder实验的测试,以涵盖正确/错误响应的混合。

我在此区域的帮助中找不到任何内容。

有没有人有什么建议?

4

2 回答 2

1

对像这样的基于键盘的测试有内置但没有详细记录的支持,但不是鼠标:class psychopy.hardware.emulator.ResponseEmulator(threading.thread)

请参阅http://www.psychopy.org/api/hardware/emulator.html并向下滚动以查看 ResponseEmulator。这用于内部测试,不仅仅用于 fMRI 模拟器。也许它需要更多的知名度!

我认为它会是这样的:

from psychopy.hardware.emulator import ResponseEmulator
simulated_responses = [(2.3, 'a'), (7.5, 'b')]
responder = ResponseEmulator(simulated_responses)
responder.start()

你会在 .start() 之后 2.3 秒得到一个“a”键,然后在 .start() 之后 7.5 秒出现一个“b”键,就好像当时有人按下了那个键(可能不是帧-准确但非常接近)。

于 2015-02-10T12:03:40.543 回答
0

为了记录,通过一些冲浪+实验,我想出了以下适合我的账单。1/ 添加代码块以导入以下库:

import win32api 
import win32con 
import time

然后为您要查找的输入定义键码,例如:

VK_CODE = {
'enter':0x0D,
'esc':0x1B,
'spacebar':0x20,
'pageup':0x21,
'pagedown':0x22,
'end':0x23,
'home':0x24,
'left':0x25,
'up':0x26,
'right':0x27,
'down':0x28,
'0':0x30,
'1':0x31,
'2':0x32,
'3':0x33,
'4':0x34,
'5':0x35,
'6':0x36,
'7':0x37,
'8':0x38,
'9':0x39,
'a':0x41,
'b':0x42,
'c':0x43,
'd':0x44,
'e':0x45,
'f':0x46,
'g':0x47,
'h':0x48,
'i':0x49,
'j':0x4A,
'k':0x4B,
'l':0x4C,
'm':0x4D,
'n':0x4E,
'o':0x4F,
'p':0x50,
'q':0x51,
'r':0x52,
's':0x53,
't':0x54,
'u':0x55,
'v':0x56,
'w':0x57,
'x':0x58,
'y':0x59,
'z':0x5A,
'numpad_0':0x60,
'numpad_1':0x61,
'numpad_2':0x62,
'numpad_3':0x63,
'numpad_4':0x64,
'numpad_5':0x65,
'numpad_6':0x66,
'numpad_7':0x67,
'numpad_8':0x68,
'numpad_9':0x69,
'multiply':0x6A,
'add':0x6B,
'separator':0x6C,
'subtract':0x6D,
'decimal':0x6E,
'divide':0x6F,
'f1':0x70,
'f2':0x71,
'f3':0x72,
'f4':0x73,
'f5':0x74,
'f6':0x75,
'f7':0x76,
'f8':0x77,
'f9':0x78,
'f10':0x79,
'f11':0x7A,
'f12':0x7B
}

然后,在试用循环中某处的代码块中,在“开始例程”选项卡上添加:

frame_counter = 0

并在“每一帧”选项卡上添加这个

frame_counter +=1

# usually at 60 frames per second , so below we wait for ~1 second 
# 'autoResp' below is the column name in your excel results file
# you can change this to whatever you want
#
# *IMPORTANT* Below, 
# -replace 'thisTrial' with the name you gave to your trial loop
# -'autoResp' is the column namein the csv file with the desired AUTOMATIC 
#       keyboard responses in

if frame_counter > 60:
    this_resp = VK_CODE[thisTrial['autoResp']]
    win32api.keybd_event( this_resp, 0, 0, 0)
    time.sleep(.05) # wait a while before doing the key_up ...
    win32api.keybd_event( this_resp,0 ,win32con.KEYEVENTF_KEYUP ,0) 
    frame_counter=0

请参阅上面代码片段中的代码注释。

然后,这会从您的 csv 文件中提取“自动”按键(在本例中名为“autoResp”的列。注意,您可以使用它来测试正确和不正确的场景

于 2015-02-10T10:45:47.577 回答