psychopy.org | Reference | Downloads | Github

Creating a mouse trail for trail tracing

URL of experiment: https://gitlab.pavlovia.org/vuandre1/tTraceTest3
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: https://www.emerald.com/insight/content/doi/10.1108/IJCS-12-2016-0002/full/html. 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:

trialMouse.leftButton.append(1)

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:

trialMouse.leftButton.append(buttons[0])

is replaced with:

trialMouse.leftButton.append(1)

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