0

I use public boolean mouseDown(Event ev, int x, int y) to detect a click of the mouse.
I can distinguish between the right mouse button (ev.metaDown() is true) and the left and middle.

How can i differentiate the left from the middle button? Or if it is impossible with mouseDown, what should i use?

Burkhard
  • 14,596
  • 22
  • 87
  • 108

3 Answers3

1

mouseDown is deprecated. All you need is accessible by the MouseEvent.getButton. Track BUTTON3.

Ralph Bisschops
  • 1,888
  • 1
  • 22
  • 34
PW.
  • 3,727
  • 32
  • 35
  • What should be used instead? ev.getButton() does not exist since ev is an Event not an MouseEvent. – Burkhard Oct 12 '08 at 13:16
  • you should implement the MouseListener interface, look at the code sample on this page: http://java.sun.com/docs/books/tutorial/uiswing/events/mouselistener.html – PW. Oct 12 '08 at 13:36
  • 5
    That should be BUTTON2, not BUTTON3. BUTTON3 is the right button. – Michael Myers Nov 06 '08 at 21:38
  • BUTTON3 is the middle button, http://www.java-tips.org/other-api-tips/jogl/how-to-implement-a-simple-double-buffered-animation-with-mouse-e.html – PW. Nov 09 '08 at 20:46
1

Try using ALT_MASK:

This flag indicates that the Alt key was down when the event occurred. For mouse events, this flag indicates that the middle mouse button was pressed or released.

So your code might be:

if (ev.modifiers & Event.ALT_MASK != 0) {
    // middle button was pressed
}

Of course, all this is assuming you have a very good reason to use mouseDown in the first place, since it is deprecated. You should (probably) be using processMouseEvent instead, which gives you a MouseEvent to play with.

Michael Myers
  • 188,989
  • 46
  • 291
  • 292