The documentation for LocatorPane says that LocatorPane is a special case of EventHandler, and gives the following code:
DynamicModule[{pt = {0, 0}},
Deploy@EventHandler[
Framed@Graphics[Disk[Dynamic[pt]], PlotRange -> 10],
"MouseDown" :> (pt = MousePosition["Graphics"]),
"MouseDragged" :> (pt = MousePosition["Graphics"])
]
]
I want to recreate the LocatorAutoCreate functionality of LocatorPane[] using EventHandler[]. That is, I want to create a graphic in which, when the user presses some key in combination with a mouse press, the mouse position is appended to the list of points being plotted. Here is my first attempt:
Dynamic[Deploy@
EventHandler[
Framed@ListPlot[pts, PlotRange -> {{-10, 10}, {-10, 10}}],
{"MouseDown" :> (pts = Append[pts, MousePosition["Graphics"]])}
]
]
This causes the mouse position to be appended when a user presses the mouse down.
Here are my two questions that I cannot find the answer to:
How do you represent a compound event (e.g. pressing down a key and pressing the mouse down simultaneously) within EventHandler[]?
How do you use a key press event when the expression (first argument of EventHandler[]) is a graphics object?
For example, this code works as intended
EventHandler[InputField[], {"KeyDown", "x"} :> Print["x has been pressed"]]
but the following code does not
Dynamic[Deploy@
EventHandler[Framed@ListPlot[pts, PlotRange -> {{-10, 10}, {-10, 10}}],
{"KeyDown","x"} :> (pts = Append[pts, MousePosition["Graphics"]])}
]
]