我正在使用.isPressedIn()函数查看鼠标是否处于目标形状。但是,每当您单击目标形状时,它都会说响应不正确。但是,只要在目标形状中按住鼠标按钮,就会说鼠标在目标上被单击。我不确定如何修复鼠标按钮释放。我尝试使用CustomMouse,但我无法在形状内单击(除非我弄错了)。任何建议将不胜感激。
谢谢!
stimDuration = 5 #stimuli are on the screen for 5 seconds
potential_target = [shape1, shape2, shape3] #shapes that may be a target
target = random.sample(potential_target, 1) #randomly select a target
myMouse = event.Mouse() #define mouse
if clock.getTime() >= stimDuration
ResponsePrompt.draw() #message to indicate to participant to select target
win.flip()
core.wait(2)
if myMouse.isPressedIn(target[0]):
print "correct"
else:
print "incorrect"
答案 0 :(得分:2)
问题是,行myMouse.isPressedIn(target[0])
会在运行该行时准确检查鼠标的状态。由于它前面有一个core.wait(2)
,它在这两秒内没有对鼠标点击做出反应,因此只收集你的鼠标响应,你仍然会在两秒后将其按住。
我会在myMouse.isPressedIn
周围进行紧密循环,每秒运行数千次。所以跳过你的第一行:
ResponsePrompt.draw() # message to indicate to participant to select target
win.flip() # show that message
while True: # keep looping. We will break this loop on a mouse press
if myMouse.isPressedIn(target[0]): # check if click is within shape
print "correct"
break # break loop if this condition was met
elif myMouse.getPressed(): # check if there was any mouse press at all, no matter location
print "incorrect"
break # break while loop if this condition was met
答案 1 :(得分:1)
在该代码中,您使用的是表达式if myMouse.isPressedIn(target[0])
,但仅在经过一段时间(stimDuration
)后才评估表达式。这意味着isPressedIn()
通常会在实际点击发生后很好地进行评估。此时,鼠标可能不再在target[0]
范围内,或者可能不再被主体按下。所以我认为你所看到的是正确的(预期的)行为。
因此,要获得所需的行为,您需要跟踪是否在每个帧的形状中按下了鼠标。
此外,我不确定您如何使用您发布的代码。有些看起来适合每一帧,但有些看起来应该只运行一次(开始例程)。您可能希望对此进行审核 - 不应每帧都对事情进行初始化(例如target
或myMouse
)。