InputEvent
's modifiers are stored as an int
value.
Each bit in the int
is a flag corresponding to a particular modifier.
The corresponding values for
these flags are given as public final static int
s in the InputEvent
class:
You can retrieve the modifiers for an event with the
getModifiers()
method:
public int getModifiers()
Use the bitwise &
operator to test whether a particular flag is set.
For example,
if (e.getModifiers() & InputEvent.BUTTON2_MASK != 0) {
System.out.println("Button 2 was pressed");
}