View on GitHub

DSFML

dsfml.window.joystick

A module containing the Joystick class.

abstract class Joystick;
Give access to the real-time state of the joysticks.

Joystick provides an interface to the state of the joysticks.

It only contains static functions, so it's not meant to be instanciated. Instead, each joystick is identified by an index that is passed to the functions of this class.

This class allows users to query the state of joysticks at any time and directly, without having to deal with a window and its events. Compared to the JoystickMoved, JoystickButtonPressed and JoystickButtonReleased events, Joystick can retrieve the state of axes and buttons of joysticks at any time (you don't need to store and update a boolean on your side in order to know if a button is pressed or released), and you always get the real state of joysticks, even if they are moved, pressed or released when your window is out of focus and no event is triggered.

JoystickCount
Maximum number of supported joysticks.

JoystickButtonCount
Maximum number of supported buttons.

JoystickAxisCount
Maximum number of supported axes.

enum Axis: int;
Axes supported by SFML joysticks.

X
The X axis.

Y
The Y axis.

Z
The Z axis.

R
The R axis.

U
The U axis.

V
The V axis.

PovX
The X axis of the point-of-view hat.

PovY
The Y axis of the point-of-view hat.

static uint getButtonCount(uint joystick);
Return the number of buttons supported by a joystick.

If the joystick is not connected, this function returns 0.





Params:
uint joystick Index of the joystick.

Returns:
Number of buttons supported by the joystick.

static float getAxisPosition(uint joystick, Axis axis);
Get the current position of a joystick axis.

If the joystick is not connected, this function returns 0.





Params:
uint joystick Index of the joystick.
Axis axis Axis to check.

Returns:
Current position of the axis, in range [-100 .. 100].

static bool hasAxis(uint joystick, Axis axis);
Check if a joystick supports a given axis.

If the joystick is not connected, this function returns false.





Params:
uint joystick Index of the joystick.
Axis axis Axis to check.

Returns:
True if the joystick supports the axis, false otherwise.

static bool isButtonPressed(uint joystick, uint button);
Check if a joystick button is pressed.

If the joystick is not connected, this function returns false.





Params:
uint joystick Index of the joystick.
uint button Button to check.

Returns:
True if the button is pressed, false otherwise.

static bool isConnected(uint joystick);
Check if a joystick is connected.

Params:
uint joystick Index of the joystick.

Returns:
True if the joystick is connected, false otherwise.

static void update();
Update the states of all joysticks.

This function is used internally by SFML, so you normally don't have to call it explicitely.

However, you may need to call it if you have no window yet (or no window at all): in this case the joysticks states are not updated automatically.