1
$\begingroup$

I want my EventHandler to respond only to left mouse clicks and pass the right mouse click to the built in event handler.

I have tried

DynamicModule[{pt = {0, 0}}, 
 EventHandler[
  Graphics[{Disk[Dynamic[pt], .1]}, 
   PlotRange -> 1], {"MouseDown", 1} :> (pt = MousePosition["Graphics"]), PassEventsDown -> True]]

But the problem is that the point moves even on right clicks. Is this a bug? How can I make the point move only on left clicks and display the graphics pop up menu on right clicks (without moving)?

DynamicModule[{pt = {0, 0}}, 
 EventHandler[
  Graphics[{Disk[Dynamic[pt], .1]}, 
   PlotRange -> 1], {"MouseDown", 1} :> (pt = MousePosition["Graphics"]), PassEventsDown -> False]]

Responds only to left clicks as expected.

So to clarify: I want to have this menu, but without the point going to the position of the right click. The point should respond to left clicks only.

Mathematica graphics

I'm running MMA 9.0.0 on Win 7 64 bit.

$\endgroup$

1 Answer 1

2
$\begingroup$

What you need is, instead of MouseDown, "MouseClicked". MouseDown is always true, for left and right mouse button (stupid me)...

DynamicModule[{pt = {0, 0}}, 
   EventHandler[
      Graphics[{Disk[Dynamic[pt], .1]}, PlotRange -> 1], {"MouseClicked", 1} 
            :> (pt = MousePosition["Graphics"]), PassEventsDown -> True]]

enter image description here

$\endgroup$
9
  • $\begingroup$ @Ajasja DynamicModule[{pt = {0, 0}}, EventHandler[ Graphics[{Disk[Dynamic[pt], .1]}, PlotRange -> 1], {"MouseDown", 1} :> (pt = MousePosition["Graphics"]), PassEventsDown -> False]] This does exactly what you want; at least for me. Move on left clicks and don't move on right clicks, but display popup menu... $\endgroup$
    – Stefan
    Feb 13, 2013 at 11:24
  • $\begingroup$ So? What exactly is your problem then? Maybe it was too late yesterday....gosh...I don't get it. $\endgroup$
    – Stefan
    Feb 13, 2013 at 11:28
  • $\begingroup$ on what platform are you and what Mma version? $\endgroup$
    – Stefan
    Feb 13, 2013 at 11:35
  • $\begingroup$ so we have an identical setup and this works perfectly on mine, as you can see in my edit... $\endgroup$
    – Stefan
    Feb 13, 2013 at 11:39
  • $\begingroup$ Thanks! This is much better. Although there is still something fishy going on. Try to left click multiple times and the point will move again. $\endgroup$
    – Ajasja
    Feb 13, 2013 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.