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 (evt.getModifiers() & InputEvent.BUTTON2_MASK != 0) {
  System.out.println("Button 2 was pressed");

Previous | Next | Top | Cafe au Lait

Copyright 1997 Elliotte Rusty Harold
Last Modified March 16, 1997