[Chapter 21] InputEvent

#

| Chapter 21 java.awt.event Reference |

# InputEvent

## Name

InputEvent

##

## Description

`InputEvent` is the root class for representing user input events. Input events are passed to listeners before the event source processes them. If one of the listeners consumes an event by using `consume()`, the event will not be processed by the event source peer.

## Class Definition

    public abstract class java.awt.event.InputEvent
       extends java.awt.event.ComponentEvent {
      // Constants
      public final static int ALT_MASK;
      public final static int BUTTON1_MASK;
      public final static int BUTTON2_MASK;
      public final static int BUTTON3_MASK;
      public final static int CTRL_MASK;
      public final static int META_MASK;
      public final static int SHIFT_MASK;
      // Instance Methods
      public void consume();
      public int getModifiers();
      public long getWhen();
      public boolean isAltDown();
      public boolean isConsumed();
      public boolean isControlDown();
      public boolean isMetaDown();
      public boolean isShiftDown();
    }

## Constants

### ALT_MASK

#### public final static int ALT_MASK

The ALT key mask. ORed with other masks to form modifiers setting of event.

### BUTTON1_MASK

#### public final static int BUTTON1_MASK

The mouse button 1 key mask. ORed with other masks to form modifiers setting of event.

### BUTTON2_MASK

#### public final static int BUTTON2_MASK

The mouse button 2 key mask. ORed with other masks to form modifiers setting of event. This constant is identical to `ALT_MASK`.

### BUTTON3_MASK

#### public final static int BUTTON3_MASK

The mouse button 3 key mask. ORed with other masks to form modifiers setting of event. This constant is identical to `ALT_MASK`.

### CTRL_MASK

#### public final static int CTRL_MASK

The Control key mask. ORed with other masks to form modifiers setting of event.

### META_MASK

#### public final static int META_MASK

The Meta key mask. ORed with other masks to form modifiers setting of event.

### SHIFT_MASK

#### public final static int SHIFT_MASK

The Shift key mask. ORed with other masks to form modifiers setting of event.

## Instance Methods

### consume

#### public void consume()

Description

  A consumed event will not be delivered to its source for default processing.

### getModifiers

#### public int getModifiers()

Returns

  The modifier flags, a combination of the `_MASK` constants.

Description

  Use this method to find out what modifier keys were pressed when an input event occurred.

### getWhen

#### public long getWhen()

Returns

  The time at which this event occurred.

Description

  The time of the event is returned as the number of milliseconds since the epoch (00:00:00 UTC, January 1, 1970). Conveniently, `java.util.Date` has a constructor that accepts such values.

### isAltDown

#### public boolean isAltDown()

Returns

  `true` if the Alt key was pressed; `false` otherwise.

### isConsumed

#### public boolean isConsumed()

Returns

  `true` if the event has been consumed; `false` otherwise.

### isControlDown

#### public boolean isControlDown()

Returns

  `true` if the Control key was pressed; `false` otherwise.

### isMetaDown

#### public boolean isMetaDown()

Returns

  `true` if the Meta key was pressed; `false` otherwise.

### isShiftDown

#### public boolean isShiftDown()

Returns

  `true` if the Shift key was pressed; `false` otherwise.

## See Also

`ComponentEvent`, `KeyEvent`, `MouseEvent`

FocusListener |  | ItemEvent