Changing Custom Mouse Cursor Color When Clicked

I have a task where I am trying to hit a target inside a circle. When I click, the custom cursor “+” should turn green for 0.2 seconds and then I receive feedback. To achieve this, I have a custom code of:

fdbk_to_draw = []
vmend = visual.CustomMouse(win, visible=True)
green_pointer = visual.TextStim(win, text='+', height=0.04, color=(0, 255, 0))
vmend.pointer = green_pointer
#feedback
if mouse.isPressedIn(target):
    fdbk = 2
    fdbk_target = visual.TextStim(win=win, text='HIT', pos=[0.0, 0.0])
    fdbk_to_draw = fdbk_target
    vmend.draw()
    win.flip()
    core.wait(0.2)
elif mouse.isPressedIn(circle):
    fdbk = 1
    fdbk_circle = visual.TextStim(win=win, text='CLOSE', pos=[0.0, 0.0])
    fdbk_to_draw = fdbk_circle
    vmend.draw()
    win.flip()
    core.wait(0.2)
else:
    fdbk = 0
    fdbk_miss = visual.TextStim(win=win, text='MISS', pos=[0.0, 0.0])
    fdbk_to_draw = fdbk_miss
    vmend.draw()
    win.flip()
    core.wait(0.2)

In the next routine, I have:

circle.opacity = 0
circle.draw()
fdbk_to_draw.draw()
win.flip()

The problem I am running into right now is that the feedback is constantly staying at 0/MISS no matter where I click. For more confusion, the feedback actually works when the green_cursor custom mouse component is taken out. Any thoughts?

Could it be that setting the green cursor is resetting the isPressed parameter of the Mouse component? What happens if you create the CustomMouse after setting the feedback, but before presenting it?

Oh my goodness, you’re right. That fixed it. But why would the CustomMouse component reset the isPressed parameter?

I suppose as the way you change the colour is by creating a green cursor and assigning it, the CustomMouse considers it to be a new mouse, so hasn’t been pressed in anything yet. One alternative would be to set the pointer at the beginning and the change its colour using:

vmend.pointer.color = (0, 255, 0)

So that it retains the same pointer, just in a different colour.

1 Like