# Recording mouse position coordinates in plots?

**URL:** https://discourse.julialang.org/t/recording-mouse-position-coordinates-in-plots/28848
**Category:** Visualization
**Tags:** pyplot, makie, inspectdr
**Created:** [September 17, 2019, 1:41pm UTC](https://discourse.julialang.org/t/recording-mouse-position-coordinates-in-plots/28848 "2019-09-17T13:41:18Z")
**Posts on this page:** 1
**Showing post:** 12

<div class="post-metadata">

### Author: ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)
#### Post date: [October 3, 2019, 3:26am UTC](https://discourse.julialang.org/t/recording-mouse-position-coordinates-in-plots/28848/12 "2019-10-03T03:26:28Z")

</div>

Correct @davide:

### First example

The first example **does not work** at the moment. I think it is supposed to work, but the `"button-press-event"` signal already has a connection in the InspectDR code. I think this is a bug with Gtk. I am almost certain you are supposed to be able to connect multiple callback functions to the same “signal”. I merely included the example in case you better understood how Gtk worked, and knew how to get around the problem.

### Second example

As for the second example: that one _ **will definitively** _ work. I call it a “hack” because you actually have to add your code (or possibly a **call** to your user-defined function) directly in InspectDR’s `src/gtk_input.jl` file.

### Sightly less hack-y

…But since we _ **are** _ talking Julia here, I suppose you could use the “dynamic patching” (guerrilla patch/monkey patch) technique to overwrite the function from your own code, instead of directly modifying the InspectDR code:

```julia-auto
using InspectDR
using Gtk

function InspectDR.handleevent_mousepress(::InspectDR.ISNormal, pwidget::InspectDR.PlotWidget, event::Gtk.GdkEventButton)
#	@show event.state, event.button, event.event_type
	InspectDR.focus_strip(pwidget, event.x, event.y)
	InspectDR.set_focus(pwidget) #In case not in focus

	if 3==event.button
		InspectDR.boxzoom_setstart(pwidget, event.x, event.y) #Changes state
	elseif 1==event.button
		if InspectDR.modifiers_pressed(event.state, InspectDR.MODIFIER_SHIFT)
			InspectDR.mousepan_setstart(pwidget, event.x, event.y) #Changes state
		elseif !InspectDR.modifiers_pressed(event.state, InspectDR.MODIFIERS_SUPPORTED) #Un-modified

		#!!! ADD CODE HERE !!!
@show pwidget.mouseover.pos #NOTE: Typically a Point2D struct, but might be nothing.

			InspectDR.handleevent_mousepress(pwidget, InspectDR.CtrlElement, event.x, event.y)
		end
	end
end

```

Note that I now had to add a direct reference to `InspectDR` for all function calls/structure definitions/etc defined in the InspectDR module. These functions/structures/… are not exported by InspectDR - so they are not otherwise available from your own function’s scope.

Hope that helps.

---

_[View the full topic](https://discourse.julialang.org/t/recording-mouse-position-coordinates-in-plots/28848)._
