Top Description Fields Constructors Methods
com.studiohartman.jamepad

public final Class ControllerState

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable

This class represents the state of a gamepad at a given moment. This includes the state of the axes and the buttons. This is probably how most people should deal with gamepads. The isConnected field is pretty important. This is how you determine if the controller you asked for is plugged in. If isConnected is false, all other fields will be zero or false. For some applications, you might not need to even bother checking isConnected. All fields are public, but immutable.
Author
William Hartman

Field Summary

Modifier and TypeField and Description
public final boolean
a

Whether or not the a button is pressed

public final boolean
aJustPressed

Whether or not the a button was just pressed

public final boolean
b

Whether or not the b button is pressed

public final boolean
back

Whether or not the back button is pressed

public final boolean
backJustPressed

Whether or not the back button was just pressed

public final boolean
bJustPressed

Whether or not the b button was just pressed

public final String
controllerType

A string describing the type of controller (i.e. "PS4 Controller" or "XInput Controller")

private static final ControllerState
public final boolean
dpadDown

Whether or not the down button on the dpad is pushed

public final boolean
dpadDownJustPressed

Whether or not the down button on the dpad was just pressed

public final boolean
dpadLeft

Whether or not the left button on the dpad is pushed

public final boolean
dpadLeftJustPressed

Whether or not the left button on the dpad was just pressed

public final boolean
dpadRight

Whether or not the right button on the dpad is pushed

public final boolean
dpadRightJustPressed

Whether or not the right button on the dpad was just pressed

public final boolean
dpadUp

Whether or not the up button on the dpad is pushed

public final boolean
dpadUpJustPressed

Whether or not the up button on the dpad was just pressed

public final boolean
guide

Whether or not the guide button is pressed.

public final boolean
guideJustPressed

Whether or not the guide button was just pressed

public final boolean
isConnected

Whether or not the controller is currently connected.

public final boolean
lb

Whether or not the left bumper is pressed

public final boolean
lbJustPressed

Whether or not the left bumper was just pressed

public final float
leftStickAngle

The angle of the left stick (for reference, 0 is right, 90 is up, 180 is left, 270 is down)

public final boolean
leftStickClick

Whether or not the left stick is clicked in

public final boolean
leftStickJustClicked

Whether or not the left stick was just is clicked in

public final float
leftStickMagnitude

The amount the left stick is pushed in the current direction.

public final float
leftStickX

The x position of the left stick between -1 and 1

public final float
leftStickY

The y position of the left stick between -1 and 1

public final float
leftTrigger

The position of the left trigger between 0 and 1

public final boolean
misc1

Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button

public final boolean
public final boolean
paddle1

Xbox Elite paddle P1

public final boolean
public final boolean
paddle2

Xbox Elite paddle P3

public final boolean
public final boolean
paddle3

Xbox Elite paddle P2

public final boolean
public final boolean
paddle4

Xbox Elite paddle P4

public final boolean
public final boolean
rb

Whether or not the right bumper is pressed

public final boolean
rbJustPressed

Whether or not the right bumper was just pressed

public final float
rightStickAngle

The angle of the right stick (for reference, 0 is right, 90 is up, 180 is left, 270 is down)

public final boolean
rightStickClick

Whether or not the right stick is clicked in

public final boolean
rightStickJustClicked

Whether or not the right stick was just is clicked in

public final float
rightStickMagnitude

The amount the right stick is pushed in the current direction.

public final float
rightStickX

The x position of the right stick between -1 and 1

public final float
rightStickY

The y position of the right stick between -1 and 1

public final float
rightTrigger

The position of the right trigger between 0 and 1

private static final long
public final boolean
start

Whether or not the start button is pressed

public final boolean
startJustPressed

Whether or not the start button was just pressed

public final boolean
touchpadButton

PS4/PS5 touchpad button

public final boolean
public final boolean
x

Whether or not the x button is pressed

public final boolean
xJustPressed

Whether or not the x button was just pressed

public final boolean
y

Whether or not the y button is pressed

public final boolean
yJustPressed

Whether or not the y button was just pressed

Constructor Summary

AccessConstructor and Description
private
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static ControllerState

Returns:

The ControllerState representing the disconnected controller.
getDisconnectedControllerInstance
()

Return a ControllerState that represents a disconnected controller.

pack-priv static ControllerState
getInstanceFromController(ControllerIndex
The ControllerIndex object whose state should be read.
c
)

Return a controller state based on the current state of the passed controller.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
public final boolean a

Whether or not the a button is pressed

aJustPressedback to summary
public final boolean aJustPressed

Whether or not the a button was just pressed

bback to summary
public final boolean b

Whether or not the b button is pressed

backback to summary
public final boolean back

Whether or not the back button is pressed

backJustPressedback to summary
public final boolean backJustPressed

Whether or not the back button was just pressed

bJustPressedback to summary
public final boolean bJustPressed

Whether or not the b button was just pressed

controllerTypeback to summary
public final String controllerType

A string describing the type of controller (i.e. "PS4 Controller" or "XInput Controller")

DISCONNECTED_CONTROLLERback to summary
private static final ControllerState DISCONNECTED_CONTROLLER
dpadDownback to summary
public final boolean dpadDown

Whether or not the down button on the dpad is pushed

dpadDownJustPressedback to summary
public final boolean dpadDownJustPressed

Whether or not the down button on the dpad was just pressed

dpadLeftback to summary
public final boolean dpadLeft

Whether or not the left button on the dpad is pushed

dpadLeftJustPressedback to summary
public final boolean dpadLeftJustPressed

Whether or not the left button on the dpad was just pressed

dpadRightback to summary
public final boolean dpadRight

Whether or not the right button on the dpad is pushed

dpadRightJustPressedback to summary
public final boolean dpadRightJustPressed

Whether or not the right button on the dpad was just pressed

dpadUpback to summary
public final boolean dpadUp

Whether or not the up button on the dpad is pushed

dpadUpJustPressedback to summary
public final boolean dpadUpJustPressed

Whether or not the up button on the dpad was just pressed

guideback to summary
public final boolean guide

Whether or not the guide button is pressed. For some controller/platform combinations this doesn't work. You probably shouldn't use this.

guideJustPressedback to summary
public final boolean guideJustPressed

Whether or not the guide button was just pressed

isConnectedback to summary
public final boolean isConnected

Whether or not the controller is currently connected. If the controller is disconnected, all other fields will be 0 or false.

lbback to summary
public final boolean lb

Whether or not the left bumper is pressed

lbJustPressedback to summary
public final boolean lbJustPressed

Whether or not the left bumper was just pressed

leftStickAngleback to summary
public final float leftStickAngle

The angle of the left stick (for reference, 0 is right, 90 is up, 180 is left, 270 is down)

leftStickClickback to summary
public final boolean leftStickClick

Whether or not the left stick is clicked in

leftStickJustClickedback to summary
public final boolean leftStickJustClicked

Whether or not the left stick was just is clicked in

leftStickMagnitudeback to summary
public final float leftStickMagnitude

The amount the left stick is pushed in the current direction. This probably between 0 and 1, but this can't be guaranteed due to weird gamepads (like the square holes on a Logitech Dual Action)

leftStickXback to summary
public final float leftStickX

The x position of the left stick between -1 and 1

leftStickYback to summary
public final float leftStickY

The y position of the left stick between -1 and 1

leftTriggerback to summary
public final float leftTrigger

The position of the left trigger between 0 and 1

misc1back to summary
public final boolean misc1

Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button

misc1JustPressedback to summary
public final boolean misc1JustPressed
paddle1back to summary
public final boolean paddle1

Xbox Elite paddle P1

paddle1JustPressedback to summary
public final boolean paddle1JustPressed
paddle2back to summary
public final boolean paddle2

Xbox Elite paddle P3

paddle2JustPressedback to summary
public final boolean paddle2JustPressed
paddle3back to summary
public final boolean paddle3

Xbox Elite paddle P2

paddle3JustPressedback to summary
public final boolean paddle3JustPressed
paddle4back to summary
public final boolean paddle4

Xbox Elite paddle P4

paddle4JustPressedback to summary
public final boolean paddle4JustPressed
rbback to summary
public final boolean rb

Whether or not the right bumper is pressed

rbJustPressedback to summary
public final boolean rbJustPressed

Whether or not the right bumper was just pressed

rightStickAngleback to summary
public final float rightStickAngle

The angle of the right stick (for reference, 0 is right, 90 is up, 180 is left, 270 is down)

rightStickClickback to summary
public final boolean rightStickClick

Whether or not the right stick is clicked in

rightStickJustClickedback to summary
public final boolean rightStickJustClicked

Whether or not the right stick was just is clicked in

rightStickMagnitudeback to summary
public final float rightStickMagnitude

The amount the right stick is pushed in the current direction. This probably between 0 and 1, but this can't be guaranteed due to weird gamepads (like the square holes on a Logitech Dual Action)

rightStickXback to summary
public final float rightStickX

The x position of the right stick between -1 and 1

rightStickYback to summary
public final float rightStickY

The y position of the right stick between -1 and 1

rightTriggerback to summary
public final float rightTrigger

The position of the right trigger between 0 and 1

serialVersionUIDback to summary
private static final long serialVersionUID
startback to summary
public final boolean start

Whether or not the start button is pressed

startJustPressedback to summary
public final boolean startJustPressed

Whether or not the start button was just pressed

touchpadButtonback to summary
public final boolean touchpadButton

PS4/PS5 touchpad button

touchpadButtonJustPressedback to summary
public final boolean touchpadButtonJustPressed
xback to summary
public final boolean x

Whether or not the x button is pressed

xJustPressedback to summary
public final boolean xJustPressed

Whether or not the x button was just pressed

yback to summary
public final boolean y

Whether or not the y button is pressed

yJustPressedback to summary
public final boolean yJustPressed

Whether or not the y button was just pressed

Constructor Detail

ControllerStateback to summary
private ControllerState(ControllerIndex c) throws ControllerUnpluggedException
ControllerStateback to summary
private ControllerState()

Method Detail

getDisconnectedControllerInstanceback to summary
pack-priv static ControllerState getDisconnectedControllerInstance()

Return a ControllerState that represents a disconnected controller. This object is shared.

Returns:ControllerState

The ControllerState representing the disconnected controller.

getInstanceFromControllerback to summary
pack-priv static ControllerState getInstanceFromController(ControllerIndex c)

Return a controller state based on the current state of the passed controller. If the controller a disconnected mid-read, the disconnected controller is returned, and the pre-disconnection read data is ignored.

Parameters
c:ControllerIndex

The ControllerIndex object whose state should be read.