Top Description Fields Constructors Methods
org.lwjgl.input

public Class Mouse

extends Object
Class Inheritance
Imports
java.nio.ByteBuffer, .IntBuffer, java.security.AccessController, .PrivilegedAction, java.util.HashMap, .Map, org.lwjgl.BufferUtils, .LWJGLException, .LWJGLUtil, .Sys, org.lwjgl.opengl.Display, .InputImplementation


A raw Mouse interface. This can be used to poll the current state of the mouse buttons, and determine the mouse movement delta since the last poll. n buttons supported, n being a native limit. A scrolly wheel is also supported, if one such is available. Movement is reported as delta from last position or as an absolute position. If the window has been created the absolute position will be clamped to 0 - width | height.
Authors
cix_foo , elias_naur , Brian Matzon
Version
$Revision$ $Id$

Field Summary

Modifier and TypeField and Description
private static int
absolute_x

Mouse absolute X position in pixels without any clipping

private static int
absolute_y

Mouse absolute Y position in pixels without any clipping

private static final int
BUFFER_SIZE

Buffer size in events

private static int
buttonCount

Number of buttons supported by the mouse

private static final Map<String, Integer>
buttonMap

hashmap of button names, for fast lookup

private static String[]
buttonName

Button names.

private static ByteBuffer
buttons

The mouse buttons status from the last poll

private static boolean
private static IntBuffer
coord_buffer

Buffer to hold the deltas dx, dy and dwheel

private static boolean
created

Has the mouse been created?

private static Cursor
currentCursor

The current native cursor, if any

private static int
dwheel

Delta Z

private static int
dx

Delta X

private static int
dy

Delta Y

private static final boolean
emulateCursorAnimation

Whether we need cursor animation emulation

private static int
private static int
event_dx

The current delta of the mouse in the event queue

private static int
private static long
public static final int
EVENT_SIZE

Internal use - event size in bytes

private static int
event_x

The current absolute position of the mouse in the event queue

private static int
private static int
eventButton

The current mouse event button being examined

private static boolean
eventState

The current state of the button being examined in the event queue

private static int
grab_x

The position of the mouse it was grabbed at

private static int
private static boolean
hasWheel

Does this mouse support a scroll wheel

private static InputImplementation
private static boolean
initialized

Lazy initialization

private static boolean
private static int
last_event_raw_x

The last absolute mouse event position (before clipping) for delta computation

private static int
private static ByteBuffer
readBuffer

The mouse button events from the last read

private static int
x

Mouse absolute X position in pixels

private static int
y

Mouse absolute Y position in pixels

Constructor Summary

AccessConstructor and Description
private
Mouse()

Mouse cannot be constructed.

Method Summary

Modifier and TypeMethod and Description
private static void
create(InputImplementation impl)

"Create" the mouse with the given custom implementation.

public static void
create()

"Create" the mouse.

public static void
destroy()

"Destroy" the mouse.

public static int

Returns:

Number of buttons on this mouse
getButtonCount
()

public static int
getButtonIndex(String
The button name
buttonName
)

Get's a button's index.

public static String

Returns:

a String with the button's human readable name in it or null if the button is unnamed
getButtonName
(int
The button
button
)

Gets a button's name

public static int

Returns:

Movement of the wheel since last time getDWheel() was called
getDWheel
()

public static int

Returns:

Movement on the x axis since last time getDX() was called.
getDX
()

public static int

Returns:

Movement on the y axis since last time getDY() was called.
getDY
()

public static int

Returns:

Current events button. Returns -1 if no button state was changed
getEventButton
()

public static boolean

Returns:

Current events button state.
getEventButtonState
()

Get the current events button state.

public static int

Returns:

Current events delta z
getEventDWheel
()

public static int

Returns:

Current events delta x.
getEventDX
()

public static int

Returns:

Current events delta y.
getEventDY
()

public static long

Returns:

The time in nanoseconds of the current event
getEventNanoseconds
()

Gets the time in nanoseconds of the current event.

public static int

Returns:

Current events absolute x.
getEventX
()

public static int

Returns:

Current events absolute y.
getEventY
()

pack-priv static InputImplementation
public static Cursor

Returns:

the currently bound native cursor, if any.
getNativeCursor
()

Gets the currently bound native cursor, if any.

pack-priv static boolean
getPrivilegedBoolean(final String property_name)

Gets a boolean property as a privileged action.

public static int

Returns:

Absolute x axis position of mouse
getX
()

Retrieves the absolute position.

public static int

Returns:

Absolute y axis position of mouse
getY
()

Retrieves the absolute position.

public static boolean

Returns:

Whether or not this mouse has wheel support
hasWheel
()

private static void
initialize()

Static initialization

public static boolean

Returns:

true if the specified button is down
isButtonDown
(int
The index of the button you wish to test (0..getButtonCount-1)
button
)

See if a particular mouse button is down.

public static boolean
public static boolean

Returns:

true if the mouse has been created
isCreated
()

public static boolean

Returns:

whether or not the mouse has grabbed the cursor
isGrabbed
()

public static boolean

Returns:

true if mouse is inside display, false otherwise.
isInsideWindow
()

Retrieves whether or not the mouse cursor is within the bounds of the window.

public static boolean

Returns:

true if a mouse event was read, false otherwise
next
()

Gets the next mouse event.

public static void
poll()

Polls the mouse for its current state.

private static void
read()

private static void
public static void
public static void
setCursorPosition(int
The x coordinate of the new cursor position in OpenGL coordinates relative to the window origin.
new_x
,
int
The y coordinate of the new cursor position in OpenGL coordinates relative to the window origin.
new_y
)

Set the position of the cursor.

public static void
setGrabbed(boolean
whether the mouse should be grabbed
grab
)

Sets whether or not the mouse has grabbed the cursor (and thus hidden).

public static Cursor

Returns:

The previous Cursor object set, or null.
setNativeCursor
(Cursor
the native cursor object to bind. May be null.
cursor
)

Binds a native cursor.

public static void
updateCursor()

Updates the cursor, so that animation can be changed if needed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

absolute_xback to summary
private static int absolute_x

Mouse absolute X position in pixels without any clipping

absolute_yback to summary
private static int absolute_y

Mouse absolute Y position in pixels without any clipping

BUFFER_SIZEback to summary
private static final int BUFFER_SIZE

Buffer size in events

buttonCountback to summary
private static int buttonCount

Number of buttons supported by the mouse

buttonMapback to summary
private static final Map<String, Integer> buttonMap

hashmap of button names, for fast lookup

buttonNameback to summary
private static String[] buttonName

Button names. These are set upon create(), to names like BUTTON0, BUTTON1, etc.

buttonsback to summary
private static ByteBuffer buttons

The mouse buttons status from the last poll

clipMouseCoordinatesToWindowback to summary
private static boolean clipMouseCoordinatesToWindow
coord_bufferback to summary
private static IntBuffer coord_buffer

Buffer to hold the deltas dx, dy and dwheel

createdback to summary
private static boolean created

Has the mouse been created?

currentCursorback to summary
private static Cursor currentCursor

The current native cursor, if any

dwheelback to summary
private static int dwheel

Delta Z

dxback to summary
private static int dx

Delta X

dyback to summary
private static int dy

Delta Y

emulateCursorAnimationback to summary
private static final boolean emulateCursorAnimation

Whether we need cursor animation emulation

event_dwheelback to summary
private static int event_dwheel
event_dxback to summary
private static int event_dx

The current delta of the mouse in the event queue

event_dyback to summary
private static int event_dy
event_nanosback to summary
private static long event_nanos
EVENT_SIZEback to summary
public static final int EVENT_SIZE

Internal use - event size in bytes

event_xback to summary
private static int event_x

The current absolute position of the mouse in the event queue

event_yback to summary
private static int event_y
eventButtonback to summary
private static int eventButton

The current mouse event button being examined

eventStateback to summary
private static boolean eventState

The current state of the button being examined in the event queue

grab_xback to summary
private static int grab_x

The position of the mouse it was grabbed at

grab_yback to summary
private static int grab_y
hasWheelback to summary
private static boolean hasWheel

Does this mouse support a scroll wheel

implementationback to summary
private static InputImplementation implementation
initializedback to summary
private static boolean initialized

Lazy initialization

isGrabbedback to summary
private static boolean isGrabbed
last_event_raw_xback to summary
private static int last_event_raw_x

The last absolute mouse event position (before clipping) for delta computation

last_event_raw_yback to summary
private static int last_event_raw_y
readBufferback to summary
private static ByteBuffer readBuffer

The mouse button events from the last read

xback to summary
private static int x

Mouse absolute X position in pixels

yback to summary
private static int y

Mouse absolute Y position in pixels

Constructor Detail

Mouseback to summary
private Mouse()

Mouse cannot be constructed.

Method Detail

createback to summary
private static void create(InputImplementation impl) throws LWJGLException

"Create" the mouse with the given custom implementation. This is used reflectively by AWTInputAdapter.

Exceptions
LWJGLException:
if the mouse could not be created for any reason
createback to summary
public static void create() throws LWJGLException

"Create" the mouse. The display must first have been created. Initially, the mouse is not grabbed and the delta values are reported with respect to the center of the display.

Exceptions
LWJGLException:
if the mouse could not be created for any reason
destroyback to summary
public static void destroy()

"Destroy" the mouse.

getButtonCountback to summary
public static int getButtonCount()
Returns:int

Number of buttons on this mouse

getButtonIndexback to summary
public static int getButtonIndex(String buttonName)

Get's a button's index. If the button is unrecognised then -1 is returned.

Parameters
buttonName:String

The button name

getButtonNameback to summary
public static String getButtonName(int button)

Gets a button's name

Parameters
button:int

The button

Returns:String

a String with the button's human readable name in it or null if the button is unnamed

getDWheelback to summary
public static int getDWheel()
Returns:int

Movement of the wheel since last time getDWheel() was called

getDXback to summary
public static int getDX()
Returns:int

Movement on the x axis since last time getDX() was called.

getDYback to summary
public static int getDY()
Returns:int

Movement on the y axis since last time getDY() was called.

getEventButtonback to summary
public static int getEventButton()
Returns:int

Current events button. Returns -1 if no button state was changed

getEventButtonStateback to summary
public static boolean getEventButtonState()

Get the current events button state.

Returns:boolean

Current events button state.

getEventDWheelback to summary
public static int getEventDWheel()
Returns:int

Current events delta z

getEventDXback to summary
public static int getEventDX()
Returns:int

Current events delta x.

getEventDYback to summary
public static int getEventDY()
Returns:int

Current events delta y.

getEventNanosecondsback to summary
public static long getEventNanoseconds()

Gets the time in nanoseconds of the current event. Only useful for relative comparisons with other Mouse events, as the absolute time has no defined origin.

Returns:long

The time in nanoseconds of the current event

getEventXback to summary
public static int getEventX()
Returns:int

Current events absolute x.

getEventYback to summary
public static int getEventY()
Returns:int

Current events absolute y.

getImplementationback to summary
pack-priv static InputImplementation getImplementation()
getNativeCursorback to summary
public static Cursor getNativeCursor()

Gets the currently bound native cursor, if any.

Returns:Cursor

the currently bound native cursor, if any.

getPrivilegedBooleanback to summary
pack-priv static boolean getPrivilegedBoolean(final String property_name)

Gets a boolean property as a privileged action.

getXback to summary
public static int getX()

Retrieves the absolute position. It will be clamped to 0...width-1.

Returns:int

Absolute x axis position of mouse

getYback to summary
public static int getY()

Retrieves the absolute position. It will be clamped to 0...height-1.

Returns:int

Absolute y axis position of mouse

hasWheelback to summary
public static boolean hasWheel()
Returns:boolean

Whether or not this mouse has wheel support

initializeback to summary
private static void initialize()

Static initialization

isButtonDownback to summary
public static boolean isButtonDown(int button)

See if a particular mouse button is down.

Parameters
button:int

The index of the button you wish to test (0..getButtonCount-1)

Returns:boolean

true if the specified button is down

isClipMouseCoordinatesToWindowback to summary
public static boolean isClipMouseCoordinatesToWindow()
isCreatedback to summary
public static boolean isCreated()
Returns:boolean

true if the mouse has been created

isGrabbedback to summary
public static boolean isGrabbed()
Returns:boolean

whether or not the mouse has grabbed the cursor

isInsideWindowback to summary
public static boolean isInsideWindow()

Retrieves whether or not the mouse cursor is within the bounds of the window. If the mouse cursor was moved outside the display during a drag, then the result of calling this method will be true until the button is released.

Returns:boolean

true if mouse is inside display, false otherwise.

nextback to summary
public static boolean next()

Gets the next mouse event. You can query which button caused the event by using getEventButton() (if any). To get the state of that key, for that event, use getEventButtonState. To get the current mouse delta values use getEventDX() and getEventDY().

Returns:boolean

true if a mouse event was read, false otherwise

See Also
org.lwjgl.input.Mouse#getEventButton(), org.lwjgl.input.Mouse#getEventButtonState()
pollback to summary
public static void poll()

Polls the mouse for its current state. Access the polled values using the get methods. By using this method, it is possible to "miss" mouse click events if you don't poll fast enough. To use buffered values, you have to call next for each event you want to read. You can query which button caused the event by using getEventButton. To get the state of that button, for that event, use getEventButtonState.

Note

This method does not query the operating system for new events. To do that, Display.processMessages() (or Display.update()) must be called first.

See Also
org.lwjgl.input.Mouse#next(), org.lwjgl.input.Mouse#getEventButton(), org.lwjgl.input.Mouse#getEventButtonState(), org.lwjgl.input.Mouse#isButtonDown(int button), org.lwjgl.input.Mouse#getX(), org.lwjgl.input.Mouse#getY(), org.lwjgl.input.Mouse#getDX(), org.lwjgl.input.Mouse#getDY(), org.lwjgl.input.Mouse#getDWheel()
readback to summary
private static void read()
resetMouseback to summary
private static void resetMouse()
setClipMouseCoordinatesToWindowback to summary
public static void setClipMouseCoordinatesToWindow(boolean clip)
setCursorPositionback to summary
public static void setCursorPosition(int new_x, int new_y)

Set the position of the cursor. If the cursor is not grabbed, the native cursor is moved to the new position.

Parameters
new_x:int

The x coordinate of the new cursor position in OpenGL coordinates relative to the window origin.

new_y:int

The y coordinate of the new cursor position in OpenGL coordinates relative to the window origin.

setGrabbedback to summary
public static void setGrabbed(boolean grab)

Sets whether or not the mouse has grabbed the cursor (and thus hidden). If grab is false, the getX() and getY() will return delta movement in pixels clamped to the display dimensions, from the center of the display.

Parameters
grab:boolean

whether the mouse should be grabbed

setNativeCursorback to summary
public static Cursor setNativeCursor(Cursor cursor) throws LWJGLException

Binds a native cursor. If the cursor argument is null, any currently bound native cursor is disabled, and the cursor reverts to the default operating system supplied cursor.

Note

The native cursor is not constrained to the window, but relative events will not be generated if the cursor is outside.

Parameters
cursor:Cursor

the native cursor object to bind. May be null.

Returns:Cursor

The previous Cursor object set, or null.

Exceptions
LWJGLException:
if the cursor could not be set for any reason
updateCursorback to summary
public static void updateCursor()

Updates the cursor, so that animation can be changed if needed. This method is called automatically by the window on its update, and shouldn't be called otherwise