java.awt.event
Class InputEvent

java.lang.Object
  extended by java.util.EventObject
      extended by java.awt.AWTEvent
          extended by java.awt.event.ComponentEvent
              extended by java.awt.event.InputEvent
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
KeyEvent, MouseEvent

public abstract class InputEvent
extends ComponentEvent

This is the common superclass for all component input classes. These are passed to listeners before the component, so that listeners can consume the event before it does its default behavior.

Since:
1.1
See Also:
KeyEvent, KeyAdapter, MouseEvent, MouseAdapter, MouseMotionAdapter, MouseWheelEvent, Serialized Form

Field Summary
static int ALT_DOWN_MASK
          The ALT key extended modifier.
static int ALT_GRAPH_DOWN_MASK
          The ALT_GRAPH key extended modifier.
static int ALT_GRAPH_MASK
          This is the bit mask which indicates the alt-graph modifier is in effect.
static int ALT_MASK
          This is the bit mask which indicates the alt key is down.
static int BUTTON1_DOWN_MASK
          The mouse button1 key extended modifier.
static int BUTTON1_MASK
          This bit mask indicates mouse button one is down.
static int BUTTON2_DOWN_MASK
          The mouse button2 extended modifier.
static int BUTTON2_MASK
          This bit mask indicates mouse button two is down.
static int BUTTON3_DOWN_MASK
          The mouse button3 extended modifier.
static int BUTTON3_MASK
          This bit mask indicates mouse button three is down.
static int CTRL_DOWN_MASK
          The CTRL key extended modifier.
static int CTRL_MASK
          This is the bit mask which indicates the control key is down.
static int META_DOWN_MASK
          The META key extended modifier.
static int META_MASK
          This is the bit mask which indicates the meta key is down.
static int SHIFT_DOWN_MASK
          The SHIFT key extended modifier.
static int SHIFT_MASK
          This is the bit mask which indicates the shift key is down.
 
Fields inherited from class java.awt.event.ComponentEvent
COMPONENT_FIRST, COMPONENT_HIDDEN, COMPONENT_LAST, COMPONENT_MOVED, COMPONENT_RESIZED, COMPONENT_SHOWN
 
Fields inherited from class java.awt.AWTEvent
ACTION_EVENT_MASK, ADJUSTMENT_EVENT_MASK, COMPONENT_EVENT_MASK, consumed, CONTAINER_EVENT_MASK, FOCUS_EVENT_MASK, HIERARCHY_BOUNDS_EVENT_MASK, HIERARCHY_EVENT_MASK, id, INPUT_METHOD_EVENT_MASK, INVOCATION_EVENT_MASK, ITEM_EVENT_MASK, KEY_EVENT_MASK, MOUSE_EVENT_MASK, MOUSE_MOTION_EVENT_MASK, MOUSE_WHEEL_EVENT_MASK, PAINT_EVENT_MASK, RESERVED_ID_MAX, TEXT_EVENT_MASK, WINDOW_EVENT_MASK, WINDOW_FOCUS_EVENT_MASK, WINDOW_STATE_EVENT_MASK
 
Fields inherited from class java.util.EventObject
source
 
Method Summary
 void consume()
          Consumes this event.
 int getModifiers()
          This method returns the old-style modifiers in effect for this event.
 int getModifiersEx()
          Returns the extended modifiers (new-style) for this event.
static String getModifiersExText(int modifiers)
          Convert the extended modifier bitmask into a String, such as "Shift" or "Ctrl+Button1".
 long getWhen()
          This method returns the timestamp when this event occurred.
 boolean isAltDown()
          This method tests whether or not the alt key was down during the event.
 boolean isAltGraphDown()
          This method tests whether or not the alt-graph modifier was in effect during the event.
 boolean isConsumed()
          This method tests whether or not this event has been consumed.
 boolean isControlDown()
          This method tests whether or not the control key was down during the event.
 boolean isMetaDown()
          This method tests whether or not the meta key was down during the event.
 boolean isShiftDown()
          This method tests whether or not the shift key was down during the event.
 
Methods inherited from class java.awt.event.ComponentEvent
getComponent, paramString
 
Methods inherited from class java.awt.AWTEvent
getID, setSource, toString
 
Methods inherited from class java.util.EventObject
getSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SHIFT_MASK

public static final int SHIFT_MASK
This is the bit mask which indicates the shift key is down. It is recommended that SHIFT_DOWN_MASK be used instead.

See Also:
SHIFT_DOWN_MASK, Constant Field Values

CTRL_MASK

public static final int CTRL_MASK
This is the bit mask which indicates the control key is down. It is recommended that CTRL_DOWN_MASK be used instead.

See Also:
CTRL_DOWN_MASK, Constant Field Values

META_MASK

public static final int META_MASK
This is the bit mask which indicates the meta key is down. It is recommended that META_DOWN_MASK be used instead.

See Also:
META_DOWN_MASK, Constant Field Values

ALT_MASK

public static final int ALT_MASK
This is the bit mask which indicates the alt key is down. It is recommended that ALT_DOWN_MASK be used instead.

See Also:
ALT_DOWN_MASK, Constant Field Values

ALT_GRAPH_MASK

public static final int ALT_GRAPH_MASK
This is the bit mask which indicates the alt-graph modifier is in effect. It is recommended that ALT_GRAPH_DOWN_MASK be used instead.

See Also:
ALT_GRAPH_DOWN_MASK, Constant Field Values

BUTTON1_MASK

public static final int BUTTON1_MASK
This bit mask indicates mouse button one is down. It is recommended that BUTTON1_DOWN_MASK be used instead.

See Also:
BUTTON1_DOWN_MASK, Constant Field Values

BUTTON2_MASK

public static final int BUTTON2_MASK
This bit mask indicates mouse button two is down. It is recommended that BUTTON2_DOWN_MASK be used instead.

See Also:
BUTTON2_DOWN_MASK, Constant Field Values

BUTTON3_MASK

public static final int BUTTON3_MASK
This bit mask indicates mouse button three is down. It is recommended that BUTTON3_DOWN_MASK be used instead.

See Also:
BUTTON3_DOWN_MASK, Constant Field Values

SHIFT_DOWN_MASK

public static final int SHIFT_DOWN_MASK
The SHIFT key extended modifier.

Since:
1.4
See Also:
Constant Field Values

CTRL_DOWN_MASK

public static final int CTRL_DOWN_MASK
The CTRL key extended modifier.

Since:
1.4
See Also:
Constant Field Values

META_DOWN_MASK

public static final int META_DOWN_MASK
The META key extended modifier.

Since:
1.4
See Also:
Constant Field Values

ALT_DOWN_MASK

public static final int ALT_DOWN_MASK
The ALT key extended modifier.

Since:
1.4
See Also:
Constant Field Values

BUTTON1_DOWN_MASK

public static final int BUTTON1_DOWN_MASK
The mouse button1 key extended modifier.

Since:
1.4
See Also:
Constant Field Values

BUTTON2_DOWN_MASK

public static final int BUTTON2_DOWN_MASK
The mouse button2 extended modifier.

Since:
1.4
See Also:
Constant Field Values

BUTTON3_DOWN_MASK

public static final int BUTTON3_DOWN_MASK
The mouse button3 extended modifier.

Since:
1.4
See Also:
Constant Field Values

ALT_GRAPH_DOWN_MASK

public static final int ALT_GRAPH_DOWN_MASK
The ALT_GRAPH key extended modifier.

Since:
1.4
See Also:
Constant Field Values
Method Detail

isShiftDown

public boolean isShiftDown()
This method tests whether or not the shift key was down during the event.

Returns:
true if the shift key is down

isControlDown

public boolean isControlDown()
This method tests whether or not the control key was down during the event.

Returns:
true if the control key is down

isMetaDown

public boolean isMetaDown()
This method tests whether or not the meta key was down during the event.

Returns:
true if the meta key is down

isAltDown

public boolean isAltDown()
This method tests whether or not the alt key was down during the event.

Returns:
true if the alt key is down

isAltGraphDown

public boolean isAltGraphDown()
This method tests whether or not the alt-graph modifier was in effect during the event.

Returns:
true if the alt-graph modifier is down

getWhen

public long getWhen()
This method returns the timestamp when this event occurred.

Returns:
the timestamp when this event occurred

getModifiers

public int getModifiers()
This method returns the old-style modifiers in effect for this event. Note that this is ambiguous between button2 and alt, and between button3 and meta. Also, code which generated these modifiers tends to only list the modifier that just changed, even if others were down at the time. Consider using getModifiersEx instead. This will be a union of the bit masks defined in this class that are applicable to the event.

Returns:
the modifiers in effect for this event
See Also:
getModifiersEx()

getModifiersEx

public int getModifiersEx()
Returns the extended modifiers (new-style) for this event. This represents the state of all modal keys and mouse buttons at the time of the event, and does not suffer from the problems mentioned in getModifiers.

For an example of checking multiple modifiers, this code will return true only if SHIFT and BUTTON1 were pressed and CTRL was not:

 int onmask = InputEvent.SHIFT_DOWN_MASK | InputEvent.BUTTON1_DOWN_MASK;
 int offmask = InputEvent.CTRL_DOWN_MASK;
 return (event.getModifiersEx() & (onmask | offmask)) == onmask;
 

Returns:
the bitwise or of all modifiers pressed during the event
Since:
1.4

consume

public void consume()
Consumes this event. A consumed event is not processed further by the AWT system.

Overrides:
consume in class AWTEvent

isConsumed

public boolean isConsumed()
This method tests whether or not this event has been consumed.

Overrides:
isConsumed in class AWTEvent
Returns:
true if this event has been consumed

getModifiersExText

public static String getModifiersExText(int modifiers)
Convert the extended modifier bitmask into a String, such as "Shift" or "Ctrl+Button1". XXX Sun claims this can be localized via the awt.properties file - how do we implement that?

Parameters:
modifiers - the modifiers
Returns:
a string representation of the modifiers in this bitmask
Since:
1.4