2

I am using the .isPressedIn() function see if the mouse click is in a target shape. However, whenever you click on the target shape, it will say the response is incorrect. However, whenever you hold the mouse button down in the target shape, it will say the mouse was clicked on the target. I'm not sure how to fix the mouse button release. I tried using CustomMouse, but I am unable to get that to click inside a shape (unless I am mistaken). Any suggestions would be greatly appreciated.

Thanks!

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"
Jonas Lindeløv
  • 5,442
  • 6
  • 31
  • 54
lo_rabb
  • 109
  • 2
  • 10
  • I think we need a bit more info here to help you. Could you update your question with some more code: what is target[0]? Do you run the if-else test in a loop and if yes, is that loop filled with other relevant stuff? Also, a part of a click is to hold the button down for a very short time, so I just want to make completely sure that you say that a click on the shape prints 'incorrect' while holding the button on the exact same location prints 'correct'? – Jonas Lindeløv Jun 05 '15 at 19:06
  • I have updated the code. The code currently prints "incorrect" unless you hold down the mouse button constantly. – lo_rabb Jun 05 '15 at 20:11

2 Answers2

2

The problem is that the line myMouse.isPressedIn(target[0]) checks the state of the mouse exactly when that line is run. Since it is preceeded by a core.wait(2) it does not react to mouse clicks in those two seconds and consequently only collects the mouse response of you still hold it down after two seconds.

I would instead have a tight loop around the myMouse.isPressedIn which runs thousands of times per second. So skipping your first lines:

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
Jonas Lindeløv
  • 5,442
  • 6
  • 31
  • 54
1

In that code, you are using the expression if myMouse.isPressedIn(target[0]), but are only evaluating that expression after some time has elapsed (stimDuration). This means that isPressedIn() will be typically be evaluated well after the actual click happened. At that point, the mouse may no longer be within target[0], or may not longer be being pressed down by the subject. So I think what you are seeing is the correct (expected) behavior.

So to obtain the behavior that you want, you need to do keep track of whether then mouse was pressed in the shape on every frame.

Also, I am not sure how you are using the code you posted. Some looks appropriate for every frame, but some looks like it should be run only once (Begin routine). You might want to review that--things should not be initialized every frame (like target or myMouse).

jrgray
  • 415
  • 3
  • 9