Mouse Buttons and Modifiers

Why is there so much confusion about mouse buttons and modifiers?

Looking over past postings there seems to be differing opinions about

how the mouse buttons work with modifiers in mouse events.

My specific question is how to use ALT as a modifier.

Using InputEvent.BUTTON*_MASK, *=1,2,3, you can determine which button

is pressed, and this works fine as well with SHIFT and CNTRL modifiers.

However, when ALT is held down both buttons 1 and 3 also set the

BUTTON2_MASK. I suppose that this is a mechanism designed to support

three button functions with two button mice. Holding down ALT lets you

produce a middle button signal. Great - if you want it!

Is it possible to disable this functionality so that ALT and the three

buttons can be used independently with no ambiguity?

[863 byte] By [SchatzmanJ] at [2007-9-26 3:01:14]
# 1

There is the MouseEvent.isAltDown() that returns a boolean value, so do:

public void MousePressed(MouseEvent me)

{

boolean mClick=(!me.isAltDown && ((me.getModifiers() & me.BUTTON2_MASK)!=0)))//middle mouse button

boolean altClick=(me.isAltDown && !((me.getModifiers() & me.BUTTON2_MASK)!=0))) //alt left or right click

}

Note: this code is untested, but it should work because I've done Alt-click and isAltDown worked for left and right click.

AnyoneEB at 2007-6-29 10:59:07 > top of Java-index,Desktop,Core GUI APIs...