# Hiding mouse for some componenets within the same routine

**URL:** <https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400>\
**Category:** Coding\
**Tags:** mouse\
**Created:** [December 8, 2021, 9:53pm UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400 "2021-12-08T21:53:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Novicepy](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@Novicepy](https://discourse.psychopy.org/u/Novicepy)\
**Post date:** [December 8, 2021, 9:53pm UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/1 "2021-12-08T21:53:15Z")

</div>

Hello all, I checked the similar topics but it seems that the problem is not solved yet. I have different components within the same routine and I want to hide the mouse when some of the components are presented but make the mouse visible in the rest. Is that possible?  
right now I am using locally but I will transfer the study to pavlovia.

Thanks

---

<div class="post-metadata">

**Author:** ![tandy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tandy/32/9246_2.png) [@tandy](https://discourse.psychopy.org/u/tandy)\
**Post date:** [December 9, 2021, 6:54am UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/2 "2021-12-09T06:54:19Z")

</div>

I use this code to show/hide the mouse for different routines:

Show mouse (Phyton / Javascript)

```auto
win.mouseVisible = False / document.body.style.cursor = "none";

```

Hide mouse (Phyton / Javascript)

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

```

You can add some additional condition inside each routine to show the mouse at specific times (e.g. from 3 to 5 seconds after the routine starts)

---

<div class="post-metadata">

**Author:** ![Novicepy](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@Novicepy](https://discourse.psychopy.org/u/Novicepy)\
**Post date:** [December 9, 2021, 7:19am UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/3 "2021-12-09T07:19:06Z")

</div>

Hey, thanks for the answer but this didnt work when I pasted to either of the locations (begin exp begin routine etc.).  
Also could you please show how to restrict the time? Like I want it to be invisible from 0 to 1.5 secs

---

<div class="post-metadata">

**Author:** ![tandy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tandy/32/9246_2.png) [@tandy](https://discourse.psychopy.org/u/tandy)\
**Post date:** [December 9, 2021, 7:36am UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/4 "2021-12-09T07:36:45Z")

</div>

Let’s say that you want the mouse to be invisible from 0 to 1.5 secs

Phyton Code

Begin Routine tab

```auto
myClock = core.Clock() 
win.mouseVisible = False

```

Each Frame tab

```auto
if myClock.getTime() >= 1.5:
    win.mouseVisible = True

```

Javascript Code

Begin Routine tab

```auto
myClock = new util.Clock();
document.body.style.cursor = "none";

```

Each Frame tab

```auto
if ((myClock.getTime() >= 1.5)) {
    document.body.style.cursor='auto';
}

```

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 9, 2021, 9:15am UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/5 "2021-12-09T09:15:01Z")

</div>

Personally I prefer to use flags to stop a command being repeated every frame

Begin Routine

```auto
myClock = core.Clock() 
win.mouseVisible = False
showMouse = False

```

Each Frame

```auto
if showMouse == False and myClock.getTime() >= 1.5:
    win.mouseVisible = True
    showMouse = True

```

---

<div class="post-metadata">

**Author:** ![Novicepy](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@Novicepy](https://discourse.psychopy.org/u/Novicepy)\
**Post date:** [December 9, 2021, 7:25pm UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/6 "2021-12-09T19:25:14Z")

</div>

Perfectly worked! Thanks a lot

---

<div class="post-metadata">

**Author:** ![Novicepy](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@Novicepy](https://discourse.psychopy.org/u/Novicepy)\
**Post date:** [December 26, 2021, 11:38am UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/7 "2021-12-26T11:38:13Z")

</div>

Hey there,

Sorry for writing under solved question but the code gave an error in the online version. This is the error:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/e/9e3a29114082843253bbdee9deb200490eeacada.png)

I am coding and psychopy novice I would be really appreciated if you tell me how to change a JS code step by step.

Thank you,  
Bests

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 26, 2021, 11:53am UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/8 "2021-12-26T11:53:41Z")

</div>

myClock = new util.Clock();

---

<div class="post-metadata">

**Author:** ![Novicepy](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@Novicepy](https://discourse.psychopy.org/u/Novicepy)\
**Post date:** [December 26, 2021, 11:55am UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/9 "2021-12-26T11:55:03Z")

</div>

should I set the coding as Both and change the JS code?

or  
In a video I saw that they do the following:  
Before experiment  
in JS part say

```auto
var core.Clock() = new util.Clock(); 

```

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 26, 2021, 11:58am UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/10 "2021-12-26T11:58:09Z")

</div>

I’ve always used a Both component in Begin Experiment without the word var

---

<div class="post-metadata">

**Author:** ![Novicepy](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@Novicepy](https://discourse.psychopy.org/u/Novicepy)\
**Post date:** [December 26, 2021, 12:24pm UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/11 "2021-12-26T12:24:35Z")

</div>

> [@wakecarter](#):
>
> myClock = new util.Clock();

I set it Both inserted this to the begin Exp JS part. However, I am receiving the same error in Pavlovia

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 26, 2021, 12:31pm UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/12 "2021-12-26T12:31:42Z")

</div>

Have you use Ctrl-Shift-R or an incognito tab or a different browser or a different device to view the latest version?

---

<div class="post-metadata">

**Author:** ![Novicepy](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@Novicepy](https://discourse.psychopy.org/u/Novicepy)\
**Post date:** [December 26, 2021, 12:41pm UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/13 "2021-12-26T12:41:19Z")

</div>

No, I am trying it from google chrome on laptop, no incognition tab

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 26, 2021, 12:49pm UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/14 "2021-12-26T12:49:55Z")

</div>

[quote=“wakecarter, post:12, topic:26400”]  
use Ctrl-Shift-R  
[/quote] in Chrome to run the latest version. You can’t get a core.Clock constructor error with your latest code if it doesn’t mention core.Clock

---

<div class="post-metadata">

**Author:** ![Novicepy](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@Novicepy](https://discourse.psychopy.org/u/Novicepy)\
**Post date:** [December 26, 2021, 1:04pm UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/15 "2021-12-26T13:04:50Z")

</div>

tried Ctrl-Shift-R, still receiving the error.

Am I doing something wrong while changing the code?

set both \> begin exp \> only in JS part write `myClock = new util.Clock();` \> ok

in begin routine I should keep

```auto
myClock = core.Clock() 
win.mouseVisible = False
showMouse = False

```

right? or should i remove it?

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 26, 2021, 1:07pm UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/16 "2021-12-26T13:07:52Z")

</div>

Please could you show a screenshot of your code component.

Did you **add** the JS version of creating a clock to the JS side instead of **replacing** the Python version?

---

<div class="post-metadata">

**Author:** ![Novicepy](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@Novicepy](https://discourse.psychopy.org/u/Novicepy)\
**Post date:** [December 26, 2021, 1:10pm UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/17 "2021-12-26T13:10:41Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/8/5/85d7c2c20ac18d87104eb0147bd590f2cf5270b9.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/7/2/72a032102ff85ec803e38fec472ba36dd7d37933.png)

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 26, 2021, 1:12pm UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/18 "2021-12-26T13:12:19Z")

</div>

It would be easier to view if you removed the empty lines.

Yes you do appear to have added instead of replaced.

---

<div class="post-metadata">

**Author:** ![Novicepy](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@Novicepy](https://discourse.psychopy.org/u/Novicepy)\
**Post date:** [December 26, 2021, 1:16pm UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/19 "2021-12-26T13:16:25Z")

</div>

should I change  
`new core.Clock()` to `new util.new util.Clock();` on the JS side here?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/7/2/72a032102ff85ec803e38fec472ba36dd7d37933.png)

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 26, 2021, 1:45pm UTC](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400/20 "2021-12-26T13:45:32Z")

</div>

I would say yes but you appear to have new twice and util twice in your proposed edit. Please look at my initial post or my crib sheet for the syntax.

[Next page](https://discourse.psychopy.org/t/hiding-mouse-for-some-componenets-within-the-same-routine/26400.md?page=2)
