我想自动测试我的 PsychoPy Builder 实验,以涵盖各种正确/错误的回复。
我在帮助中找不到任何涉及此区域的内容。
有人有任何建议吗?
答案 0 :(得分: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()
你得到一个' a'密钥发生在.start()后的2.3秒,然后是' b'在.start()之后7.5秒,就像一个人当时按下那个键(可能不是帧精确但非常接近)。
答案 1 :(得分: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
}
然后,在试用循环中的某个代码块中,在“Begin Routine”选项卡上添加:
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'的列。你可以使用它来测试正确和不正确的场景