psychopy.org | Reference | Downloads | Github

Hiding mouse cursor in the pavlovia online experiment

URL of experiment: [https://pavlovia.org/run/AkaiRed/lr_2afc/html/] (press ‘g’ to start)
Version of PsychoPy: PsychoPy3 v2020.1.3
Description of the problem:

Hi Everyone.
I’m building an online experiment (thanks to the devlopers, it was so easy and fluent)
and looking for a way to hide mouse cursor during the experiment.
It doesn’t show up on my local settings, the problem occurs only when I run online exp.

[Hide mouse cursor in online experiment]
I’ve checked the post above, tried solution in the first post but it didn’t work.

[Setting mouse position online]
Also I was able to find a comment from Jon to the slightly different problem.
Jon confirmed that it’s not possible to re-position mouse cursor in psychopy web experiment.
My problem is more simple, not repositioning the cursor but just hiding it during the experiment.

One more thing, those posts are up to date and we have v2020.1.3 now.
Even if there were no control for the cursor in the previous version of psychopy, there may be now.

In short, does anyone know if there is a way to hide a mouse cursor in online experiment?

1 Like

I don’t believe it’s changed in PsychoPy, but I think you might be able to make a code component that will do it. Try adding this javascript code to the beginning of the routine where you want to hide it, or if that doesn’t work, on each frame in that routine:

document.body.style.cursor='none';

You may need to add the following code in the next routine to un-hide it:

document.body.style.cursor='auto';
6 Likes

Hi Jonathan. I’ve tried your solution and it works perfectly! Thank you so much.
Your code is even better because I can customize visibility of the cursor in routine-based manner.

Though the function itself has not been added in the updated version of PsychoPy,
adjusting JS code directly from the Builder wasn’t possible before the release of v2020.
Your advise was helpful because of this new feature, so it’s kind of v2020 specific.
Thanks again, those who suffered from the ever-lasting cursor will be free now! : )

1 Like

Hello,

Is this code specifically for online experiments? Question is that I am trying to make this code work on the builder version but it gives me an error saying:

“document.body.style.cursor=‘none’;
NameError: name ‘document’ is not defined”

The experiment I am currently working on has a polygon component that is used as a color change for the background (based on this post here).

Could the polygon be the possible reason why the code is not working on the builder?

Also, I have not tested it on Pavlovia right now, but will be able to do so next week. Just wanted to find out possible reasons why it is currently not working on the builder or if I am doing something wrong.

Any feedback is appreciated :slight_smile:

Thank you!

Yes, I’m afraid it is online-only. It is Javascript code that directly interacts with the browser, so it only works when studies are run in a web-browser. When they are run locally using Python code, it does nothing. However, PsychoPy should hide the cursor by default when running locally, especially if you make it run full-screen.

Thank you for the prompt reply! I will test out the code on Pavlovia next week and let you know if I come across any issues.

Unfortunately, the mouse cursor is not hidden by default when running locally even running it on full-screen as you have stated. I also tried to make the mouse cursor hide by unchecking the option “Show mouse” under the Screen section of the Experiment Settings and still no luck. That is how I found your post and for which I am very grateful! So thank you!

I will come back if I come across any issues with the code.

Hi! to make a mouse cursor invisible for offline experiments use:

Mouse.setVisible(False)

Where ‘Mouse’ is the name of your mouse component :slight_smile:

1 Like

Hello,

Thank you for helping me out! At first, I only added the code and it gave me the same name error of “Mouse is not defined.” And when I did define the mouse, it kept giving me the same error.

However, after attempting so many times, I realized that code is character sensitive so the capitalization of letters matters! And thus, the code works, when I actually defined it keeping the same letters/capitalization:

Mouse = mouse
Mouse.setVisible(False)

where ‘mouse’ (lowercase m) is the name of my mouse component.

Once again, thank you so much for the help!!

Hello, so to hide the cursor while running both online and offline what I did for the code component is to make it “both” instead of the automatic “auto → JS”. This way you can write out the python code that hides the mouse offline while also editing/writing the JS code on the right side for it to run offline. I did this and my experiment runs both offline and in Pavlovia!

Just as a refresher to hide the mouse use this Py code on the left side:

win.mouseVisible = False

And write this out on the right (JS) side:

document.body.style.cursor='none';

To make the mouse visible:

win.mouseVisible = True
document.body.style.cursor='auto';

Hope this helps!

6 Likes

document.body.style.cursor='none';
Did not work for me.

I used this instead:
document.documentElement.style.cursor = 'none';

As well as:
document.documentElement.style.cursor = 'auto';