| Reference | Downloads | Github

Creating a mouse trail for trail tracing

URL of experiment: Andrew Vu / tTraceTest3 · GitLab
OS: Win10
PsychoPy version: v2020.1.3
Standard Standalone?: Yes

What are you trying to achieve?:
Currently trying to create a mouse trail that follows the mouse movement for our group’s experimental trial, which is a trail tracing experiment. An example of what we are trying to replicate can be seen in this paper: Specifically having our end result look like ‘Figure 5’ in the paper would be best (as seen below).

What did you try to make it work?:
So far, the “Brush” component in the builder provides the closest result to what our group is looking for; a line that follows the mouse movement.

What specifically went wrong when you tried that?:
What would be optimal for us is if the line was automatically generated without any need for mouse clicks. As of now, the left mouse button needs to be held down in order to create the line. Having a way for the line to be continuously created from the start of the trial routine to the end without a need for participants to press any buttons is what we are looking for.

Any help is appreciated.

1st update: My first thought in solving this problem was to implement the following line into the ‘Each Frame’ section of my trial code component:


The idea was to create a fake held-down left-mouse button response during the trial, which might cause the ‘brush’ to turn on at all times. However, the code only appears to append a ‘1’ to the ‘trialMouse.leftButton’ array every other frame, causing an array that looks like ‘[0, 1, 0, 1, 0,…]’ and no lines are created.

Some more testing revealed that if:


is replaced with:


then the array becomes an array of '1’s but the ‘brush’ component does not appear to be affected at all (as in no lines are created). This might indicate that the ‘brush’ is controlled by something else, or that ‘trialMouse.leftButton’ does not serve the function of creating a mouse click as I have assumed.

I am still not completely sure whether the “faking a click” idea is a dead end or not yet though .

That was a good try, but I just checked the code for the Brush class: it does its own active check of the mouse to see if the button is currently pressed, so that approach won’t work:

Now the cool thing about Python is that you could “monkey patch” that function, overriding it to just always return True, regardless of what the mouse button state is. I have no idea if that is a feasible approach in JavaScript - hopefully someone else can chime in here.

But you have raised a good point that this functionality (of drawing without the mouse button being pressed) would be something that many people could want. I’ll look at adding that option to the (Python) code for a future release, and another developer will hopefully be able to add it to PsychoJS as well.

1 Like

This feature has been submitted in this pull request:

It may be too late in the development cycle for this to be included in the next release (which is due at the end of this month). And at this stage, it is implemented only for local Python experiments (not online).

1 Like