java.awt.event

Class InputEvent

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

UNKNOWN: updated to 1.4

Field Summary
static intALT_DOWN_MASK
The ALT key extended modifier.
static intALT_GRAPH_DOWN_MASK
The ALT_GRAPH key extended modifier.
static intALT_GRAPH_MASK
This is the bit mask which indicates the alt-graph modifier is in effect.
static intALT_MASK
This is the bit mask which indicates the alt key is down.
static intBUTTON1_DOWN_MASK
The mouse button1 key extended modifier.
static intBUTTON1_MASK
This bit mask indicates mouse button one is down.
static intBUTTON2_DOWN_MASK
The mouse button2 extended modifier.
static intBUTTON2_MASK
This bit mask indicates mouse button two is down.
static intBUTTON3_DOWN_MASK
The mouse button3 extended modifier.
static intBUTTON3_MASK
This bit mask indicates mouse button three is down.
static intCTRL_DOWN_MASK
The CTRL key extended modifier.
static intCTRL_MASK
This is the bit mask which indicates the control key is down.
static intMETA_DOWN_MASK
The META key extended modifier.
static intMETA_MASK
This is the bit mask which indicates the meta key is down.
static intSHIFT_DOWN_MASK
The SHIFT key extended modifier.
static intSHIFT_MASK
This is the bit mask which indicates the shift key is down.
Method Summary
voidconsume()
Consumes this event.
intgetModifiers()
This method returns the old-style modifiers in effect for this event.
intgetModifiersEx()
Returns the extended modifiers (new-style) for this event.
static StringgetModifiersExText(int modifiers)
Convert the extended modifier bitmask into a String, such as "Shift" or "Ctrl+Button1".
longgetWhen()
This method returns the timestamp when this event occurred.
booleanisAltDown()
This method tests whether or not the alt key was down during the event.
booleanisAltGraphDown()
This method tests whether or not the alt-graph modifier was in effect during the event.
booleanisConsumed()
This method tests whether or not this event has been consumed.
booleanisControlDown()
This method tests whether or not the control key was down during the event.
booleanisMetaDown()
This method tests whether or not the meta key was down during the event.
booleanisShiftDown()
This method tests whether or not the shift key was down during the event.

Field Detail

ALT_DOWN_MASK

public static final int ALT_DOWN_MASK
The ALT key extended modifier.

Since: 1.4

ALT_GRAPH_DOWN_MASK

public static final int ALT_GRAPH_DOWN_MASK
The ALT_GRAPH key extended modifier.

Since: 1.4

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

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

BUTTON1_DOWN_MASK

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

Since: 1.4

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

BUTTON2_DOWN_MASK

public static final int BUTTON2_DOWN_MASK
The mouse button2 extended modifier.

Since: 1.4

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

BUTTON3_DOWN_MASK

public static final int BUTTON3_DOWN_MASK
The mouse button3 extended modifier.

Since: 1.4

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

CTRL_DOWN_MASK

public static final int CTRL_DOWN_MASK
The CTRL key extended modifier.

Since: 1.4

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

META_DOWN_MASK

public static final int META_DOWN_MASK
The META key extended modifier.

Since: 1.4

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

SHIFT_DOWN_MASK

public static final int SHIFT_DOWN_MASK
The SHIFT key extended modifier.

Since: 1.4

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

Method Detail

consume

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

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

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

getWhen

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

Returns: the timestamp when this event occurred

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

isConsumed

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

Returns: true if this event has been consumed

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

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