Add points to scatter plot by Mouse.down click using GLMakie

Id like to add points to a GLMakie plot when holding down the keyboard letter “a” and then holding down the left mouse button. The docs have a good demo on how to do this with a click (Point Picking). However when I change Mouse.press to Mouse.down the zoom action occurs. Any idea how to turn off the zoom action?

Here is my code:

using GLMakie

positions = Observable(rand(Point2f, 10))

fig, ax, p = scatter(positions)

on(events(fig).mousebutton, priority = 2) do event
    if event.button == Mouse.left && event.action == Mouse.down
        if Keyboard.d in events(fig).keyboardstate
            # Delete marker
            plt, i = pick(fig)
            if plt == p
                deleteat!(positions[], i)
                notify(positions)
                return Consume(true)
            end
        elseif Keyboard.a in events(fig).keyboardstate
            # Add marker
            push!(positions[], mouseposition(ax))
            notify(positions)
            return Consume(true)
        end
    end
    return Consume(false)
end

https://docs.makie.org/stable/examples/blocks/axis/#registering_and_deregistering_interactions

Thanks @jules . I have another question. id like continually add new points to the plot when the mouse button is pressed. Basically I am trying to paint over pixels in a 2D image. I have tried change Mouse.press to Mouse.pressed but that doesn’t seem to work.

Update: Look at the dragging example in the docs, duh. Point Picking

Changed the bottom dragging function to this,

    if dragging
        #positions[][idx] = mouseposition(ax)
        push!(positions[], mouseposition(ax))
        notify(positions)
        return Consume(true)
    end
    return Consume(false)
end

I would not use dragging state directly, because this will still fire if you drag the mouse over the axis from somewhere else. This often happens with sliders etc. You can just use the precomputed mouse events accessible via the axis interactions as explained here https://docs.makie.org/stable/examples/blocks/axis/#function_interaction

For example (I didn’t test this)

register_interaction!(ax, :painting_scatters) do event::MouseEvent, axis
    if event.type === MouseEventTypes.leftdrag
        # do your picking logic etc here
    end
end