Custom mouse cursor

309 views
Skip to first unread message

Devin Gill

unread,
Feb 22, 2015, 2:45:52 AM2/22/15
to psychop...@googlegroups.com


Hi all,

I'm attempting to include a custom mouse cursor (from a png image) in my experiment (specifically only for the routine where the cursor is visible) and simply need to collect the x,y coordinates as the response.  I found some sample code (psychopy.visual.custommouse/), but I'm not knowledgeable enough to figure out how/where to proceed.  Any assistance would be greatly appreciated, thanks!

Best,
Devin Gill
ok.py

Jeremy Gray

unread,
Feb 22, 2015, 7:48:07 AM2/22/15
to psychop...@googlegroups.com
Hi Devin,

There's a simple example illustrating CustomMouse in Coder > Demos > Input > customMouse.py

You should be able to use any PsychoPy stimulus having .draw() and .setPos() methods as a custom mouse. In the demo, I used a .png file (= the default custom mouse, solid white pointer) and also a TextStim (the letter O). The line of code that controls the switch to the new mouse appearance (the O) is

    vm.pointer = new_pointer

where new_pointer is

    new_pointer = visual.TextStim(myWin, text='o')

--Jeremy


--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/5543b943-0817-4208-b39d-20164aacd8b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Devin Gill

unread,
Feb 24, 2015, 12:52:01 AM2/24/15
to psychop...@googlegroups.com
Hi Jeremy,

Thanks very much for the quick response and information.  I'm very close to a solution to this problem.  I believe what is holding me back is that in an earlier routine, I specify  event.Mouse(visible=False) so that the mouse is not visible during the routine in which my stimulus is displayed (because regardless of what I specified in the builder mode, the mouse was always present).  In the 'response' routine I created, after 'conitinueRoutine=True, I specify event.Mouse(visible=True) to make the mouse visible again.  After that, I included 

 vm = visual.CustomMouse(win, leftLimit=None, topLimit=None, rightLimit=None, bottomLimit=None, 
            showLimitBox=True, clickOnUp=True)
        
        new_pointer = visual.ImageStim(win, image='cursor.png')

        vm.pointer = new_pointer
    
        vm.draw()

I'm certain this is where I've made some mistake as the result is the regular mouse pointer flickering and after a click, the intended cursor image is displayed on screen.  Please forgive my lack of knowledge on this topic, but once again, any insights would be greatly appreciated.

As a side note, something I did not include in my first post, I am running version 1.82.01 if that makes a difference.

Best,
Devin
Fear2.py

Jeremy Gray

unread,
Feb 24, 2015, 4:58:19 AM2/24/15
to psychop...@googlegroups.com
Try doing this part in the Begin routine section (so that its outside of the while continueRoutine loop, and is not done every frame):

 vm = visual.CustomMouse(win, leftLimit=None, topLimit=None, rightLimit=None, bottomLimit=None, 
            showLimitBox=True, clickOnUp=True)
        
        new_pointer = visual.ImageStim(win, image='cursor.png')
        vm.pointer = new_pointer

and only this part every frame:
 
        vm.draw()

--Jeremy

Devin Gill

unread,
Feb 24, 2015, 12:29:59 PM2/24/15
to psychop...@googlegroups.com
Hi Jeremy,

Thanks once again for the quick response!  It seems as if the flickering issue of the regular pointer went away, however, the arrow is still present.   Interestingly, upon a mouse click, the new_pointer appears only for a second, does not (appear to) correspond to the arrow location, and cannot be moved via the mouse.  It seems as if the vm.draw() is occurring after the mouse response event, because the loop proceeds after the new_pointer appears/disappears.  I've played with moving the event.Mouse(visible=True) to both inside (both before or after vm.draw()) and outside(before) the 'while continueRoutine' loop to no avail.  I'm stumped!


The code below gives me the previously described state (regular mouse arrow visible and new_pointer drawn after mouse click which then disappears after a second).

#-------Start Routine "Response"-------
    continueRoutine = True
    
    vm = visual.CustomMouse(win, leftLimit=None, topLimit=None, rightLimit=None, bottomLimit=None, 
        showLimitBox=True, clickOnUp=True)
        
    new_pointer = visual.ImageStim(win, image='cursor.png')

    vm.pointer = new_pointer
    event.Mouse(visible=True)
   
    while continueRoutine:
        
        vm.draw()

Devin Gill

unread,
Feb 24, 2015, 8:03:51 PM2/24/15
to psychop...@googlegroups.com
Good news!  It turns out the additional image I was being displayed on top of the vm.draw() and thus was covering the new_pointer.  The problem is solved!  Thanks again for your assistance Jeremy!


On Tuesday, February 24, 2015 at 2:58:19 AM UTC-7, Jeremy wrote:

Jeremy Gray

unread,
Feb 24, 2015, 8:11:40 PM2/24/15
to psychop...@googlegroups.com
Great!

--Jeremy

--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages