public class XInputDevice extends Object
getAllDevices() or getDeviceFor(int) methods to start using the devices.
Certain methods in this class are not thread-safe and are documented as such.
It is not recommended to share an instance of XInputDevice across multiple threads.
XInputComponents,
XInputComponentsDelta| Modifier and Type | Field and Description |
|---|---|
protected int |
playerNum |
| Modifier | Constructor and Description |
|---|---|
protected |
XInputDevice(int playerNum) |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(XInputDeviceListener listener)
Adds an event listener that will react to changes in the input.
|
protected boolean |
checkReturnCode(int ret) |
protected boolean |
checkReturnCode(int ret,
int... validRetCodes) |
static XInputDevice[] |
getAllDevices()
Returns an array containing all registered XInput devices.
|
XInputComponents |
getComponents()
Returns the state of the XInput controller components at the last poll.
|
XInputComponentsDelta |
getDelta()
Returns the difference between the last two states of the XInput controller components.
|
static XInputDevice |
getDeviceFor(int playerNum)
Returns the XInput device for the specified player.
|
XInputComponents |
getLastComponents()
Returns the state of the XInput controller components before the last poll.
|
static XInputLibraryVersion |
getLibraryVersion()
Retrieves the loaded XInput library version.
|
int |
getPlayerNum()
Returns the player number that this device represents.
|
static boolean |
isAvailable()
Determines if the XInput devices are available on this platform.
|
boolean |
isConnected()
Returns a boolean indicating whether this device is connected.
|
static boolean |
isGuideButtonSupported()
Determines if polling the Guide button is supported.
|
protected static ByteBuffer |
newBuffer(int capacity)
Creates a new direct ByteBuffer to be used for communicating with the native library.
|
boolean |
poll()
Reads input from the device and updates components.
|
void |
removeListener(XInputDeviceListener listener)
Removes a registered event listener
|
static void |
setPreProcessData(boolean preprocess)
Defines whether to perform additional precalculations to the data.
|
boolean |
setVibration(int leftMotor,
int rightMotor)
Sets the vibration of the controller.
|
public static boolean isAvailable()
true if the XInput devices are available, false if notpublic static XInputLibraryVersion getLibraryVersion()
XInputLibraryVersionpublic static boolean isGuideButtonSupported()
true if the Guide button state can be read, false otherwise.public static XInputDevice[] getAllDevices() throws XInputNotLoadedException
The XInputDevice objects are not thread-safe.
XInputNotLoadedException - if the native library failed to loadpublic static XInputDevice getDeviceFor(int playerNum) throws XInputNotLoadedException
The returned object should not be shared among multiple threads.
playerNum - the player numberXInputNotLoadedException - if the native library failed to loadpublic static void setPreProcessData(boolean preprocess)
lx, ly, rx, ry, lt and rt in XInputAxes
will be filled with non-zero float values ranging from -1 to 1 for the thumbsticks or 0 to 1 for the triggers,
based on the raw values. If disabled, only the raw values will be filled. By default, the float values are calculated.preprocess - whether to preprocess data into the XInputAxes's float fields (true) or
just use raw data (false)public void addListener(XInputDeviceListener listener)
listener - the listenerpublic void removeListener(XInputDeviceListener listener)
listener - the listenerpublic boolean poll()
This method is not thread-safe.
false if the device is not connectedIllegalStateException - if there is an error trying to read the device stateprotected boolean checkReturnCode(int ret)
protected boolean checkReturnCode(int ret,
int... validRetCodes)
public boolean setVibration(int leftMotor,
int rightMotor)
false if the device was not connected.
This method is not thread-safe.
leftMotor - the left motor speed, from 0 to 65535rightMotor - the right motor speed, from 0 to 65535false if the device was not connectedIllegalArgumentException - if either motor speed values lie out of the range 0..65535public XInputComponents getLastComponents()
public XInputComponents getComponents()
public XInputComponentsDelta getDelta()
public boolean isConnected()
true if the device is connected, false otherwisepublic int getPlayerNum()
protected static ByteBuffer newBuffer(int capacity)
capacity - the buffer capacityCopyright © 2018. All rights reserved.