Josh
Native console access wrapper for Java

com.yifanlu.Josh
Class ConsoleEventMouse

java.lang.Object
  extended by com.yifanlu.Josh.ConsoleEvent
      extended by com.yifanlu.Josh.ConsoleEventMouse

public class ConsoleEventMouse
extends ConsoleEvent

Describes a mouse input event.

Since:
0.1
Version:
1.3, 05/29/10
Author:
Yifan Lu
See Also:
Windows' MOUSE_EVENT_RECORD structure, JoshInBuffer

Field Summary
static int DOUBLE_CLICK
          Constant value for mouse event flag.
static int FROM_LEFT_1ST_BUTTON_PRESSED
          Constant value for mouse button.
static int FROM_LEFT_2ND_BUTTON_PRESSED
          Constant value for mouse button.
static int FROM_LEFT_3RD_BUTTON_PRESSED
          Constant value for mouse button.
static int FROM_LEFT_4TH_BUTTON_PRESSED
          Constant value for mouse button.
static int MOUSE_HWHEELED
          Constant value for mouse event flag.
static int MOUSE_MOVED
          Constant value for mouse event flag.
static int MOUSE_WHEELED
          Constant value for mouse event flag.
static int RIGHTMOST_BUTTON_PRESSED
          Constant value for mouse button.
 
Fields inherited from class com.yifanlu.Josh.ConsoleEvent
CAPSLOCK_ON, ENHANCED_KEY, eventType, FOCUS_EVENT, KEY_EVENT, LEFT_ALT_PRESSED, LEFT_CTRL_PRESSED, MENU_EVENT, MOUSE_EVENT, NUMLOCK_ON, RIGHT_ALT_PRESSED, RIGHT_CTRL_PRESSED, SCROLLLOCK_ON, SHIFT_PRESSED, WINDOW_BUFFER_SIZE_EVENT
 
Constructor Summary
ConsoleEventMouse(ConsoleCoord mousePosition, int buttonState, int controlKeyState, int eventFlags)
          Creates a mouse event.
 
Method Summary
 boolean equals(java.lang.Object anObject)
          Compares two Objects, if both are ConsoleEventMouse and have the same values, they are equal.
 int getButtonState()
          Gets the mouse button pressed.
 int getControlKeyState()
          Gets any control keys pressed.
 int getEventFlags()
          Gets the type of mouse input (click, double click, etc).
 ConsoleCoord getMousePosition()
          Gets the current mouse position.
 int hashCode()
          Returns a hash code.
 void setButtonState(int buttonState)
          Sets the mouse button pressed.
 void setControlKeyState(int controlKeyState)
          Sets any control keys pressed.
 void setEventFlags(int eventFlags)
          Gets the type of mouse input (click, double click, etc).
 void setMousePosition(ConsoleCoord mousePosition)
          Sets the current mouse position.
 java.lang.String toString()
          A String representation of this object.
 
Methods inherited from class com.yifanlu.Josh.ConsoleEvent
getEventType
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

FROM_LEFT_1ST_BUTTON_PRESSED

public static final int FROM_LEFT_1ST_BUTTON_PRESSED
Constant value for mouse button.

See Also:
Constant Field Values

FROM_LEFT_2ND_BUTTON_PRESSED

public static final int FROM_LEFT_2ND_BUTTON_PRESSED
Constant value for mouse button.

See Also:
Constant Field Values

FROM_LEFT_3RD_BUTTON_PRESSED

public static final int FROM_LEFT_3RD_BUTTON_PRESSED
Constant value for mouse button.

See Also:
Constant Field Values

FROM_LEFT_4TH_BUTTON_PRESSED

public static final int FROM_LEFT_4TH_BUTTON_PRESSED
Constant value for mouse button.

See Also:
Constant Field Values

RIGHTMOST_BUTTON_PRESSED

public static final int RIGHTMOST_BUTTON_PRESSED
Constant value for mouse button.

See Also:
Constant Field Values

DOUBLE_CLICK

public static final int DOUBLE_CLICK
Constant value for mouse event flag.

See Also:
Constant Field Values

MOUSE_HWHEELED

public static final int MOUSE_HWHEELED
Constant value for mouse event flag.

See Also:
Constant Field Values

MOUSE_MOVED

public static final int MOUSE_MOVED
Constant value for mouse event flag.

See Also:
Constant Field Values

MOUSE_WHEELED

public static final int MOUSE_WHEELED
Constant value for mouse event flag.

See Also:
Constant Field Values
Constructor Detail

ConsoleEventMouse

public ConsoleEventMouse(ConsoleCoord mousePosition,
                         int buttonState,
                         int controlKeyState,
                         int eventFlags)
Creates a mouse event.

Parameters:
mousePosition - The location of the cursor, in terms of the console screen buffer's character-cell coordinates.
buttonState - The status of the mouse buttons. The least significant bit corresponds to the leftmost mouse button. The next least significant bit corresponds to the rightmost mouse button. The next bit indicates the next-to-leftmost mouse button. The bits then correspond left to right to the mouse buttons. A bit is 1 if the button was pressed. Use the constants defined in this class to set.
controlKeyState - The state of the control keys. Use the constants defined in ConsoleEvent to set.
eventFlags - The type of mouse event. If this value is zero, it indicates a mouse button being pressed or released. Use the constants defined in this class to set.
Method Detail

getMousePosition

public ConsoleCoord getMousePosition()
Gets the current mouse position.

Returns:
The location of the cursor, in terms of the console screen buffer's character-cell coordinates.

getButtonState

public int getButtonState()
Gets the mouse button pressed.

Returns:
The status of the mouse buttons. The least significant bit corresponds to the leftmost mouse button. The next least significant bit corresponds to the rightmost mouse button. The next bit indicates the next-to-leftmost mouse button. The bits then correspond left to right to the mouse buttons. A bit is 1 if the button was pressed. Use the constants defined in this class to set.

getControlKeyState

public int getControlKeyState()
Gets any control keys pressed. Use constants in ConsoleEvent to compare, and the OR operator to mix and match. For example:
if((ConsoleEventKeyboard)keyEvent.getControlKeyState() == (ConsoleEvent.CAPSLOCK_ON | LEFT_ALT_PRESSED));
would check if the caps lock is on AND left alt key is held.

Returns:
The state of the control keys.

getEventFlags

public int getEventFlags()
Gets the type of mouse input (click, double click, etc).

Returns:
The type of mouse event. If this value is zero, it indicates a mouse button being pressed or released. Use the constants defined in this class to set.

setMousePosition

public void setMousePosition(ConsoleCoord mousePosition)
Sets the current mouse position.

Parameters:
mousePosition - The location of the cursor, in terms of the console screen buffer's character-cell coordinates.

setButtonState

public void setButtonState(int buttonState)
Sets the mouse button pressed.

Parameters:
buttonState - The status of the mouse buttons. The least significant bit corresponds to the leftmost mouse button. The next least significant bit corresponds to the rightmost mouse button. The next bit indicates the next-to-leftmost mouse button. The bits then correspond left to right to the mouse buttons. A bit is 1 if the button was pressed. Use the constants defined in this class to set.

setControlKeyState

public void setControlKeyState(int controlKeyState)
Sets any control keys pressed. Use constants from ConsoleEvent.

Parameters:
controlKeyState - The state of the control keys.

setEventFlags

public void setEventFlags(int eventFlags)
Gets the type of mouse input (click, double click, etc).

Parameters:
eventFlags - The type of mouse event. If this value is zero, it indicates a mouse button being pressed or released. Use the constants defined in this class to set.

equals

public boolean equals(java.lang.Object anObject)
Compares two Objects, if both are ConsoleEventMouse and have the same values, they are equal.

Overrides:
equals in class java.lang.Object
Parameters:
anObject - Another ConsoleEventMouse object.
Returns:
true if all values are equal.

hashCode

public int hashCode()
Returns a hash code.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.

toString

public java.lang.String toString()
A String representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
The mouse position, button clicked, and the type of click.

Copyright © 2010 Yifan Lu