The following works:

```
mymouse := Block[{}, pos = MousePosition["Graphics"];
If[pos =!= None, AppendTo[posList, pos]]]
posList = {};
plot = Plot[Sin[x], {x, 0, 4 Pi}]; (* your plot *)
Dynamic[Show[plot, ListLinePlot[posList, PlotStyle -> Red]]]
Dynamic[mymouse]
```

(This amazing artwork is copyrighted ©anderstood)

**Edit** Maybe this is a bit smoother?

```
mymouse := Block[{}, pos = MousePosition["Graphics"];
If[pos =!= None, AppendTo[posList, pos];
posList = DeleteDuplicates@posList;]]
(* If[pos =!= None && Not@MemberQ[postList,pos], AppendTo[posList, pos]; *)
posList = {};
plot = Plot[Sin[x], {x, 0, 4 Pi}];(*your plot*)Dynamic[
Show[plot, ListLinePlot[posList, PlotStyle -> Red]]]
Dynamic[mymouse]
```

And this to avoid the slow `AppendTo`

:

```
i = 1;
mymouse := Block[{}, pos = MousePosition["Graphics"];
If[pos =!= None, posList[[i]] = pos; i++;]]
posList = ConstantArray[{0, 0}, 1000];
plot = Plot[Sin[x], {x, 0, 4 Pi}];(*your plot*)Dynamic[
Show[plot, ListLinePlot[posList, PlotStyle -> Red]]]
Dynamic[mymouse]
```

1Thank you, this works good, but somehow my on my computer it is very slow: when I move the mouse I have to wait a while to see the curve. Can you also observe this? Another problem: if the mouse is not moved the code continuously stores the same coordinate. Can the code store only once this coordinates? PS: Nobody will be able exactly to repeat your copyrighted artwork, it is unique ;-) – lio – 2018-02-21T09:31:30.533

3@lio I edited, is it better? I tried on two PCs and is was OK, not perfect but OK. To improve that, you would need someone more knowledgeable than me...

`AppendTo`

is not recommended but I do not see how to avoid that. I added a third possibility just to see if its smoother, but it introduces the point`{0, 0}`

. – anderstood – 2018-02-22T00:25:37.297This is excellent for a project I am currently working on; I did not know about MousePosition! Is there an easy way to make this start recording points on the path after a mouseclick, and end after clicking again? – Steve – 2019-04-03T04:28:23.197

@Steve I don't have MMA readily available to try it, but I would start by reading https://reference.wolfram.com/language/ref/EventHandler.html.

– anderstood – 2019-04-03T14:53:25.487