Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

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

share|improve this answer
    
@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... –  Stefan Feb 13 '13 at 11:24
    
So? What exactly is your problem then? Maybe it was too late yesterday....gosh...I don't get it. –  Stefan Feb 13 '13 at 11:28
    
on what platform are you and what Mma version? –  Stefan Feb 13 '13 at 11:35
    
so we have an identical setup and this works perfectly on mine, as you can see in my edit... –  Stefan Feb 13 '13 at 11:39
    
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. –  Ajasja Feb 13 '13 at 15:21
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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