An 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:
InputEvent.SHIFT_MASK
InputEvent.CTRL_MASK
InputEvent.META_MASK
InputEvent.ALT_MASK
InputEvent.BUTTON1_MASK
InputEvent.BUTTON2_MASK
InputEvent.BUTTON3_MASK
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 (evt.getModifiers() & InputEvent.BUTTON2_MASK != 0) {
System.out.println("Button 2 was pressed");
}