| Reference | Downloads | Github

Error - Using the "mouse.isPressedIn" function(online)

Hi all,

I’m currently in the process of converting my experiment to run online (Pavlovia), but I can’t seem to figure out how to get the “mouse.isPressedIn” function working there. I’m currently only familiar with using the Builder view, but I’m hoping there might be another way of doing this so I can get the online version of my experiment to run the same as the offline version.

In my offline experiment, I use the “mouse.isPressedIn” function to briefly change the colour of buttons when they are clicked - my white buttons will briefly flash black when they are clicked, to signify that they have indeed been clicked. Whilst this might seem purely aesthetical, I have found it helps my older adult participants to use the experiment when they receive some visual feedback and the buttons ‘light up’ when clicked.

To do this in the offline version, there’s a fairly simple (if inelegant) solution:

I have a regular, ‘unclicked’ white version of the button (image stim), and a second hidden, ‘clicked’ black version. The image stim are identical in size / position etc., they are just different colours. This hidden version of the button is only made visible when the mouse is clicked in on the ‘unclicked’ version:


I then use a separate code component to check if this ‘clicked’ version has run, and if so, continue on to the next page:

if Next_Clicked_1.status == FINISHED:
continueRoutine = False

I’m trying to replicate this online, but I keep getting the following error:

  • TypeError: Mouse_1.isPressedIn is not a function

I found this post which explains I might need to translate my code to JS (mouse.isPressedIn()). But I’m not exactly sure how to do that…and if I change the code within PsychoPy, will that stop my experiment running normally ‘offline’?

Any help would be appreciated!

Hi @Jamie, you may want to have a look at the Corsi blocks demo on Pavlovia. This uses a code component to change the color of the blocks when they are clicked. You will want to look at the code in “Every Frame” of the code component.

1 Like

Thanks for the tip!

It took me longer than I care to admit, but I was eventually able to extract the relevant bits of code from the Corsi blocks demo to get this working.

1 Like

Hi all! I’m having a similar problem with the mouse.isePressedIn error. The Corsi blocks demo is not particularly helpful. Could you please share how you solved this error?

I have investigated this in greater depth and created a solution, which you can see here: Code component to count mouse clicks