Class Gamepad
One connected game controller.
Buttons and axes use the standard layout every modern controller is mapped
to -- the Xbox layout, which is also what Steam Input presents for a Steam
Deck, a Steam Controller or a PlayStation pad. Query it with
#isButtonDown(int) and #getAxis(int), or be told about changes through a
GamepadListener registered with Gamepads.
Instances are owned by Gamepads and live for as long as the controller is
connected; #isConnected() turns false once it is gone. All state is written
and read on the EDT.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe number of axes.static final intThe left trigger, 0 (released) to 1 (fully pulled).static final intThe left stick, -1 (left) to 1 (right).static final intThe left stick, -1 (up) to 1 (down).static final intThe right trigger, 0 (released) to 1 (fully pulled).static final intThe right stick, -1 (left) to 1 (right).static final intThe right stick, -1 (up) to 1 (down).static final intThe bottom face button (A on Xbox, Cross on PlayStation).static final intThe right face button (B on Xbox, Circle on PlayStation).static final intThe back / view / select button.static final intThe number of buttons.static final intD-pad down.static final intD-pad left.static final intD-pad right.static final intD-pad up.static final intThe guide / home button.static final intThe left shoulder button.static final intPressing the left stick.static final intThe left trigger, reported as a button once pulled past halfway.static final intThe right shoulder button.static final intPressing the right stick.static final intThe right trigger, reported as a button once pulled past halfway.static final intThe start / menu button.static final intThe left face button (X on Xbox, Square on PlayStation).static final intThe top face button (Y on Xbox, Triangle on PlayStation). -
Method Summary
Modifier and TypeMethodDescriptionfloatgetAxis(int axis) The axis value with the dead zone applied: a stick inside the dead zone reads exactly 0, and the remaining travel is rescaled so the value still reaches 1 at the edge.floatThe stick dead zone, 0.15 by default.intgetIndex()The slot this controller occupies, 0 for the first one connected.getName()The name the device reports, for display only; it may be empty.floatgetRawAxis(int axis) The axis value exactly as the device reported it, with no dead zone.booleanisButtonDown(int button) True while the button is held.booleanFalse once the controller has been disconnected.voidrumble(float strong, float weak, int durationMillis) Rumbles the controller, on ports and controllers that support it; it is silently ignored everywhere else.voidsetDeadZone(float deadZone) Sets the stick dead zone, clamped to 0 ..
-
Field Details
-
BUTTON_A
public static final int BUTTON_AThe bottom face button (A on Xbox, Cross on PlayStation).- See Also:
-
BUTTON_B
public static final int BUTTON_BThe right face button (B on Xbox, Circle on PlayStation).- See Also:
-
BUTTON_X
public static final int BUTTON_XThe left face button (X on Xbox, Square on PlayStation).- See Also:
-
BUTTON_Y
public static final int BUTTON_YThe top face button (Y on Xbox, Triangle on PlayStation).- See Also:
-
BUTTON_LEFT_SHOULDER
public static final int BUTTON_LEFT_SHOULDERThe left shoulder button.- See Also:
-
BUTTON_RIGHT_SHOULDER
public static final int BUTTON_RIGHT_SHOULDERThe right shoulder button.- See Also:
-
BUTTON_BACK
public static final int BUTTON_BACKThe back / view / select button.- See Also:
-
BUTTON_START
public static final int BUTTON_STARTThe start / menu button.- See Also:
-
BUTTON_GUIDE
public static final int BUTTON_GUIDEThe guide / home button. Steam keeps this one for itself while a game runs under it, so do not rely on receiving it.- See Also:
-
BUTTON_LEFT_STICK
public static final int BUTTON_LEFT_STICKPressing the left stick.- See Also:
-
BUTTON_RIGHT_STICK
public static final int BUTTON_RIGHT_STICKPressing the right stick.- See Also:
-
BUTTON_DPAD_UP
public static final int BUTTON_DPAD_UPD-pad up.- See Also:
-
BUTTON_DPAD_DOWN
public static final int BUTTON_DPAD_DOWND-pad down.- See Also:
-
BUTTON_DPAD_LEFT
public static final int BUTTON_DPAD_LEFTD-pad left.- See Also:
-
BUTTON_DPAD_RIGHT
public static final int BUTTON_DPAD_RIGHTD-pad right.- See Also:
-
BUTTON_LEFT_TRIGGER
public static final int BUTTON_LEFT_TRIGGERThe left trigger, reported as a button once pulled past halfway.- See Also:
-
BUTTON_RIGHT_TRIGGER
public static final int BUTTON_RIGHT_TRIGGERThe right trigger, reported as a button once pulled past halfway.- See Also:
-
BUTTON_COUNT
public static final int BUTTON_COUNTThe number of buttons.- See Also:
-
AXIS_LEFT_X
public static final int AXIS_LEFT_XThe left stick, -1 (left) to 1 (right).- See Also:
-
AXIS_LEFT_Y
public static final int AXIS_LEFT_YThe left stick, -1 (up) to 1 (down).- See Also:
-
AXIS_RIGHT_X
public static final int AXIS_RIGHT_XThe right stick, -1 (left) to 1 (right).- See Also:
-
AXIS_RIGHT_Y
public static final int AXIS_RIGHT_YThe right stick, -1 (up) to 1 (down).- See Also:
-
AXIS_LEFT_TRIGGER
public static final int AXIS_LEFT_TRIGGERThe left trigger, 0 (released) to 1 (fully pulled).- See Also:
-
AXIS_RIGHT_TRIGGER
public static final int AXIS_RIGHT_TRIGGERThe right trigger, 0 (released) to 1 (fully pulled).- See Also:
-
AXIS_COUNT
public static final int AXIS_COUNTThe number of axes.- See Also:
-
-
Method Details
-
getIndex
public int getIndex()The slot this controller occupies, 0 for the first one connected. A slot freed by a disconnect is reused by the next controller. -
getName
The name the device reports, for display only; it may be empty. -
isConnected
public boolean isConnected()False once the controller has been disconnected. -
isButtonDown
public boolean isButtonDown(int button) True while the button is held.
Parameters
button: one of theBUTTON_*constants
-
getAxis
public float getAxis(int axis) The axis value with the dead zone applied: a stick inside the dead zone reads exactly 0, and the remaining travel is rescaled so the value still reaches 1 at the edge. Triggers are not subject to the dead zone.
Parameters
axis: one of theAXIS_*constants
-
getRawAxis
public float getRawAxis(int axis) The axis value exactly as the device reported it, with no dead zone. -
getDeadZone
public float getDeadZone()The stick dead zone, 0.15 by default. -
setDeadZone
public void setDeadZone(float deadZone) Sets the stick dead zone, clamped to 0 .. 0.9. Worn sticks rest a little off center; the dead zone stops that from reading as movement. -
rumble
public void rumble(float strong, float weak, int durationMillis) Rumbles the controller, on ports and controllers that support it; it is silently ignored everywhere else.
Parameters
-
strong: the low frequency (heavy) motor, 0 to 1 -
weak: the high frequency (light) motor, 0 to 1 -
durationMillis: how long the rumble lasts
-
-