Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.lwjgl.input
Class Mouse

    java.lang.Object
      org.lwjgl.input.Mouse

    public class Mouse

extends java.lang.Object

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.

Version:
  $Revision: 2739 $ $Id: Mouse.java 2739 2007-02-12 12:18:26Z elias_naur $
Author:
  cix_foo , elias_naur , Brian Matzon

Field Summary
`static int` | `EVENT_SIZE` Internal use - event size in bytes

Method Summary
`static void` | `create()` "Create" the mouse.
`static void` | `destroy()` "Destroy" the mouse.
`static int` | `getButtonCount()`
`static int` | `getButtonIndex(java.lang.String buttonName)` Get's a button's index.
`static java.lang.String` | `getButtonName(int button)` Gets a button's name
`static int` | `getDWheel()`
`static int` | `getDX()`
`static int` | `getDY()`
`static int` | `getEventButton()`
`static boolean` | `getEventButtonState()` Get the current events button state.
`static int` | `getEventDWheel()`
`static int` | `getEventDX()`
`static int` | `getEventDY()`
`static long` | `getEventNanoseconds()` Gets the time in nanoseconds of the current event.
`static int` | `getEventX()`
`static int` | `getEventY()`
`static Cursor` | `getNativeCursor()` Gets the currently bound native cursor, if any.
`static int` | `getX()` Retrieves the absolute position.
`static int` | `getY()` Retrieves the absolute position.
`static boolean` | `hasWheel()`
`static boolean` | `isButtonDown(int button)` See if a particular mouse button is down.
`static boolean` | `isCreated()`
`static boolean` | `isGrabbed()`
`static boolean` | `next()` Gets the next mouse event.
`static void` | `poll()` Polls the mouse for its current state.
`static void` | `setCursorPosition(int new_x, int new_y)` Set the position of the cursor.
`static void` | `setGrabbed(boolean grab)` Sets whether or not the mouse has grabbed the cursor (and thus hidden).
`static Cursor` | `setNativeCursor(Cursor cursor)` Binds a native cursor.
`static void` | `updateCursor()` Updates the cursor, so that animation can be changed if needed.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### EVENT_SIZE

    public static final int EVENT_SIZE

  Internal use - event size in bytes

  See Also:
    Constant Field Values

Method Detail

### getNativeCursor

    public static Cursor getNativeCursor()

  Gets the currently bound native cursor, if any.

  Returns:
    the currently bound native cursor, if any.

### setNativeCursor

    public static Cursor setNativeCursor(Cursor cursor)
                                  throws LWJGLException

  Binds a native cursor. If the cursor argument is null, the native cursor is disabled, as if native cursors were not supported. NOTE: The native cursor is not constrained to the window, but relative events will not be generated if the cursor is outside.

  Parameters:
    `cursor` - the native cursor object to bind. May be null.
  Returns:
    The previous Cursor object set, or null.
  Throws:
    `LWJGLException` - if the cursor could not be set for any reason

### setCursorPosition

    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:
    `x` - The x coordinate of the new cursor position in OpenGL coordinates relative to the window origin.
    `y` - The y coordinate of the new cursor position in OpenGL coordinates relative to the window origin.

### create

    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.

  Throws:
    `LWJGLException` - if the mouse could not be created for any reason

### isCreated

    public static boolean isCreated()

  Returns:
    true if the mouse has been created

### destroy

    public static void destroy()

  "Destroy" the mouse.

### poll

    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`.

  See Also:
    `next()`, `getEventButton()`, `getEventButtonState()`, `isButtonDown(int button)`, `getX()`, `getY()`, `getDX()`, `getDY()`, `getDWheel()`

### isButtonDown

    public static boolean isButtonDown(int button)

  See if a particular mouse button is down.

  Parameters:
    `button` - The index of the button you wish to test (0..getButtonCount-1)
  Returns:
    true if the specified button is down

### getButtonName

    public static java.lang.String getButtonName(int button)

  Gets a button's name

  Parameters:
    `button` - The button
  Returns:
    a String with the button's human readable name in it or null if the button is unnamed

### getButtonIndex

    public static int getButtonIndex(java.lang.String buttonName)

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

  Parameters:
    `buttonName` - The button name

### next

    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()`, `getEventDY()` and `getEventDZ()`.

  Returns:
    true if a mouse event was read, false otherwise
  See Also:
    `getEventButton()`, `getEventButtonState()`

### getEventButton

    public static int getEventButton()

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

### getEventButtonState

    public static boolean getEventButtonState()

  Get the current events button state.

  Returns:
    Current events button state.

### getEventDX

    public static int getEventDX()

  Returns:
    Current events delta x. Only valid when the mouse is grabbed.

### getEventDY

    public static int getEventDY()

  Returns:
    Current events delta y. Only valid when the mouse is grabbed.

### getEventX

    public static int getEventX()

  Returns:
    Current events absolute x. Only valid when the mouse is not grabbed.

### getEventY

    public static int getEventY()

  Returns:
    Current events absolute y. Only valid when the mouse is not grabbed.

### getEventDWheel

    public static int getEventDWheel()

  Returns:
    Current events delta z

### getEventNanoseconds

    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:
    The time in nanoseconds of the current event

### getX

    public static int getX()

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

  Returns:
    Absolute x axis position of mouse

### getY

    public static int getY()

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

  Returns:
    Absolute y axis position of mouse

### getDX

    public static int getDX()

  Returns:
    Movement on the x axis since last time getDX() was called. Only valid when the mouse is grabbed.

### getDY

    public static int getDY()

  Returns:
    Movement on the y axis since last time getDY() was called. Only valid when the mouse is grabbed.

### getDWheel

    public static int getDWheel()

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

### getButtonCount

    public static int getButtonCount()

  Returns:
    Number of buttons on this mouse

### hasWheel

    public static boolean hasWheel()

  Returns:
    Whether or not this mouse has wheel support

### isGrabbed

    public static boolean isGrabbed()

  Returns:
    whether or not the mouse has grabbed the cursor

### setGrabbed

    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` - whether the mouse should be grabbed

### updateCursor

    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

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2006 lwjgl.org. All Rights Reserved.