Hide mouse cursor in builder?

I have an experiment where subjects respond with the mouse only at the end of each trial. I have a separate routine for this response period, which includes a mouse event. The problem is, the mouse cursor is displayed throughout the entire trial, and I would like it to only display at the start of the last routine.

Is there any way to do this in Builder? Or do I have to go to the Coder view?

As a more general question, if I make a change in Coder, then that change does not carry over to the Builder, correct? So I couldnā€™t make behind-the-scenes changes in Coder, then continue to use Builder to finish up the task?

4 Likes

Insert a Code component in Builder and try something like this in the Begin routine tab:

win.mouseVisible = True

and in the End routine tab:

win.mouseVisible = False

Generally, no. A code component in Builder allows you to execute small amounts of code at relevant times, while still staying within the graphical Builder environment.

Yes, there is no way to translate the arbitrary Python code you could write and turn it back into a graphical representation. So going from Builder to Coder is very much a one-way street.

But you will likely find that using a code component within Builder allows you to achieve 99% of what you might need to do with custom code, and actually stops a lot of errors by automatically inserting the code at the right place. i.e. you get to have your cake and eat it, by using custom code but remaining within the Builder environment.

3 Likes

Thank you! That solution worked beautifully.

And yes, that makes perfect sense about the Coder vs. Builder. I have been using the code components, but ran into some issues with not knowing where the code is executed relative to the drawing of the stimuli, etc. I guess the solution is to occasionally peek at the Coder view and figure out through trial-and-error.

I could program the whole thing in Coder, but I like how Builder constrains things for me. Thatā€™s what I donā€™t like about Psychtoolbox-- itā€™s infinitely flexible, which means everyone is free to write terrible code to accomplish simple things. :slight_smile:

Just one quick follow-up question:

If I didnā€™t ask in the forum, where would be the best place to find the solution to this problem? The API section under documentation? I tried browsing through but never stumbled across the win.mouseVisible option.

Yes, in similar situations, I tend to put in a comment string like # XXX in my code component and then do a quick search for XXX in the Coder view to quickly locate it in the compiled script.

Yes, start with the API. No one will ever complain if you do your homework there first and then follow-up with unresolved questions here on the forum :wink:
In this case, check out the page for the Window class:
http://www.psychopy.org/api/visual/window.html#psychopy.visual.Window

Hi,
I have a similar problem but when I tried this recommendation, it did not work in my case.
I have the rating component in the same routine and that the rating is done as the last activity in the routine. I still see the mouse cursor right from the beginning of the experiment till the end. Please help me to make the mouse cursor visible only during the rating period. I have included the screenshot.

I finally got it by taking out the rating component and making it a routine on its own. I also inserted this code instead [your_mouse = event.Mouse(visible = False)] and it worked. Thanks

For me, the mouse cursor is hidden at the start of the experiment as long as ā€˜Show mouseā€™ is unchecked in Experiment Settings > Screen, but the mouse cursor becomes visible when the program executes a movie component and remains visible for the remainder of the experiment.

Inserting a code component in the same routine as the movie component and using ā€˜win.mouseVisible = Falseā€™ (or ā€˜your_mouse = event.Mouse(visible = False)ā€™, as suggested above) fails to hide the mouse cursor, regardless of whether this line of code is added to ā€˜Begin Experimentā€™, ā€˜Begin Routineā€™, or ā€˜Each Frameā€™.

Has anybody else seen this behaviour when using a movie component?

Hi @Michael,

I am trying to do the same on Pavlovia i.e. I want to hide the cursor at the beginning of a routine but display it again as the routine ends. But the code does not work.

Also, is it required to insert a ā€˜mouseā€™ component in the routine for it to work?

yes, I have the problem and donā€™t know how to solve it. The ā€˜show mouseā€™ tickbox in settings is unticked. And the mouse not visible, but as soon as the first movie is played it appears on the screen. Would be nice to find a way to hide the mouse during movie playback. Does anyone have advise on this?

Did you ever find a solution? I am having this exact problem at the moment and cannot get the mouse to disappear during video routines at all. Unfortunately as it is a visual perception experiment this is actually the only routine where I NEED the cursor to be gone!

Iā€™ve tried messing around with the code components putting them in different points, making sure my monitor/full-screen/show mouse settings are all correct, re-setting my preferences, re-installing psychopy and nothing has worked - the ā€˜show mouseā€™ option doesnā€™t seem to do anything at all on any experiment I create, even without video stimuli but the code here works for everything BUT video stimuli. :sob: :sob: :sob:

I have not been able to find a way to hide the mouse cursor in an experiment that includes a movie component. The mouse cursor can be hidden at the start of the experiment, but it reappears as soon as the movie loads. When the movie componentā€™s ā€˜movie fileā€™ drop-down is set to ā€˜set every repeatā€™, the movie does not load until the movie component starts (this is another unresolved bug and it causes a delay in the onset of the movie: Loading times for routines with videos are slow) and the mouse cursor reappears when the movie component starts (first as a blue circle and then, when the movie has loaded, as a white arrow). When the ā€˜movie fileā€™ drop-down is instead set to ā€˜constantā€™, the movie loads at the start of the experiment and the cursor is therefore visible throughout the experiment.

I have, however, found a workaround that involves setting the position of the mouse cursor so that it is off-screen and therefore not visible. See: Resetting mouse position to center after rating. In each routine after the movie was loaded, and in which you want the cursor to be hidden, it is necessary to create a Mouse component and then add a code component after it that sets the position of the Mouse component using the setPos() method. The position of the Mouse component should be set to coordinates that are off-screen. The coordinates to use depend on the units that have been chosen for the window (I think in Properties ā†’ Screen), and I think in all cases (0,0) is the centre of the screen (psychopy.event - for keypresses and mouse clicks ā€” PsychoPy v2021.2). For example, if you are using ā€˜normā€™ units, then the top right corner of the screen has coordinates of (1,1) and the following line of code will cause the mouse cursor to be positioned in this corner (in the code, ā€˜myMouseā€™ should be replaced with the name of your Mouse component):

myMouse.setPos(newPos=(1,1))

The tip of the white arrow cursor will be located at the top right corner of the screen and the body of the arrow will not be visible because of its shape (the body of the arrow is below and to the right of its tip). The bottom left or bottom right corners of the screen would work just as well. If you specify coordinates that are outside the screen area (e.g. (2,2) or (100,100)), I think the cursor ends up in the same corner (e.g. at (1,1)).

I added this code to the Begin Routine tab and the Each Frame tab of the code component. Adding it to the Each Frame tab ensures that the mouse cursor is returned to the required position whenever the user attempts to move it. The cursor will briefly appear on the screen when the user moves the mouse to bring it on-screen, but will quickly move back off-screen. I added a Mouse component and a code component to each routine in which I wanted to hide the mouse cursor.

Note that the Mouse component also has a setVisible() method, but this doesnā€™t work in conjunction with a Movie component. In other words, neither win.mouseVisible = False nor myMouse.setVisible(False) works, and as far as I know the cursor cannot be hidden, only moved off-screen.

Hi Surabhi,

it is probably too late now, but in pavlovia, you can hide and unhide the mouse cursor using the javascript code snippets below

//Hide the mouse cursor
document.body.style.cursor=ā€˜noneā€™;

//unhide mouse cursor:
document.body.style.cursor=ā€˜autoā€™;

(from Wakefieldā€™s crib sheet)

2 Likes

Iā€™m currently using PsychoPy v2022.1.4 and I canā€™t seem to get the mouse visibility working. I have both the ā€œshow mouseā€ button unchecked and win.mouseVisible = False in a begin experiment routine, but the mouse is still visible throughout the experiment. Any resolutions that Iā€™m missing?

Unfortunately it seems to be an ongoing problem. Downgrading to a previous version is the best option for now Iā€™m afraid

In case people have been searching the forum like I did initiallyā€¦