# Makie mouse click position

**URL:** <https://discourse.julialang.org/t/makie-mouse-click-position/9062>\
**Category:** Visualization\
**Tags:** question, makie\
**Created:** [February 14, 2018, 4:11pm UTC](https://discourse.julialang.org/t/makie-mouse-click-position/9062 "2018-02-14T16:11:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 14, 2018, 4:11pm UTC](https://discourse.julialang.org/t/makie-mouse-click-position/9062/1 "2018-02-14T16:11:49Z")

</div>

Can someone please show me how to get the location of a mouse left click on a `Makie.jl` `scene` ?  
Here’s what I have now:

```julia-auto
using Makie
img = rand(100,100)
scene = Scene(resolution = (100, 100))
heatmap(img)
Makie.add_mousebuttons(scene)
pos = lift_node(scene, :mouseposition) do mpos
    if ispressed(scene, Mouse.left)
        return mpos
    end
end

```

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [February 14, 2018, 5:10pm UTC](https://discourse.julialang.org/t/makie-mouse-click-position/9062/2 "2018-02-14T17:10:13Z")

</div>

Have you seen:[https://github.com/JuliaPlots/Makie.jl/blob/master/docs/src/examples/scattermouse.jl](https://github.com/JuliaPlots/Makie.jl/blob/master/docs/src/examples/scattermouse.jl) ?

So I guess you’re looking for something like:

```julia
using Makie, GeometryTypes, Colors

img = rand(100,100)
scene = Scene()
heatmap(img)
center!(scene, 0.2)
cam = scene[:screen].cameras[:orthographic_pixel]
Makie.add_mousebuttons(scene)
pos = lift_node(scene, :mouseposition) do mpos
    if ispressed(scene, Mouse.left)
        return to_world(Point2f0(mpos), cam)
    end
    Point2f0(Inf)
end
scatter(lift_node(x-> Point2f0[x], pos), markersize = 10)

```

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 14, 2018, 5:17pm UTC](https://discourse.julialang.org/t/makie-mouse-click-position/9062/3 "2018-02-14T17:17:16Z")

</div>

> [@sdanisch](#):
>
> Have you seen:[https://github.com/JuliaPlots/Makie.jl/blob/master/docs/src/examples/scattermouse.jl](https://github.com/JuliaPlots/Makie.jl/blob/master/docs/src/examples/scattermouse.jl) ?

I have, but I couldn’t figure out how to get the mouse position from just one click.

Also, in your example here (thank you btw), I can’t get the position without needing to move the mouse first, while holding down the mouse button. All I want is to click somewhere on the image and get the location of that click (in some variable I can access - a `Signal` perhaps).

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [February 14, 2018, 5:26pm UTC](https://discourse.julialang.org/t/makie-mouse-click-position/9062/4 "2018-02-14T17:26:09Z")

</div>

Ah!  
You need to turn around on what node you “listen” to:

```nohighlight
using Makie, GeometryTypes, Colors

img = rand(100,100)
scene = Scene()
heatmap(img)
center!(scene, 0.2)
cam = scene[:screen].cameras[:orthographic_pixel]
Makie.add_mousebuttons(scene)
clicks = to_node(Point2f0[])
pos = lift_node(scene, :mousebuttons) do buttons
    if length(buttons) == 1 && first(buttons) == Mouse.left
        pos = to_world(Point2f0(to_value(scene, :mouseposition)), cam)
        # awkward! one push! for adding to clicks, another to update the node!
        push!(clicks, push!(to_value(clicks), pos))
    end
    return 
end
scatter(clicks, markersize = 10)

```

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 14, 2018, 5:27pm UTC](https://discourse.julialang.org/t/makie-mouse-click-position/9062/5 "2018-02-14T17:27:57Z")

</div>

Awesome opossum!!

Thank you!

---

<div class="post-metadata">

**Author:** ![gszep](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gszep/32/14836_2.png) [@gszep](https://discourse.julialang.org/u/gszep)\
**Post date:** [December 29, 2020, 7:14pm UTC](https://discourse.julialang.org/t/makie-mouse-click-position/9062/6 "2020-12-29T19:14:39Z")

</div>

what is the modern equivalent of this? I keep getting the exception  
` **cannot resize array with shared data** `

```julia
polygon = Node([SVector(0.0,0.0),SVector(5.0,0.0),SVector(5.0,5.0)])
poly!(ax, polygon, color=RGBA(0,1,0,0.1), strokecolor=:black)
	
on(scene.events.keyboardbuttons) do button
		
	if ispressed(button, Keyboard._1)
		polygon[] = append!(polygon[],[SVector(mouseevents.obs.val.data...)])
	end
end

```

---

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [October 15, 2021, 4:50am UTC](https://discourse.julialang.org/t/makie-mouse-click-position/9062/7 "2021-10-15T04:50:16Z")

</div>

> [@sdanisch](#):
>
> Have you seen:[https://github.com/JuliaPlots/Makie.jl/blob/master/docs/src/examples/scattermouse.jl](https://github.com/JuliaPlots/Makie.jl/blob/master/docs/src/examples/scattermouse.jl) ?

No, link is dead?

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [October 15, 2021, 8:07am UTC](https://discourse.julialang.org/t/makie-mouse-click-position/9062/8 "2021-10-15T08:07:45Z")

</div>

I couldn’t find that specific example, but here is something from the docs to get you started:

[https://makie.juliaplots.org/stable/documentation/events/#mouse\_interaction](https://makie.juliaplots.org/stable/documentation/events/#mouse_interaction)

---

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [October 15, 2021, 8:12am UTC](https://discourse.julialang.org/t/makie-mouse-click-position/9062/9 "2021-10-15T08:12:24Z")

</div>

Thx @yakir12, I also found the examples folder now under [Makie.jl/docs/examples at master · JuliaPlots/Makie.jl (github.com)](https://github.com/JuliaPlots/Makie.jl/tree/master/docs/examples), but without the said example.
