Mouse Button Modifiers

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 ints 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");
}

Previous | Next | Top
Last Modified March 16, 1997
Copyright 1997 Elliotte Rusty Harold
elharo@sunsite.unc.edu