Joystick

Enums

Global joysticks capabilities.

Values:

enumerator sfJoystickCount

Maximum number of supported joysticks.

enumerator sfJoystickButtonCount

Maximum number of supported buttons.

enumerator sfJoystickAxisCount

Maximum number of supported axes.

enum sfJoystickAxis

Axes supported by SFML joysticks.

Values:

enumerator sfJoystickX

The X axis.

enumerator sfJoystickY

The Y axis.

enumerator sfJoystickZ

The Z axis.

enumerator sfJoystickR

The R axis.

enumerator sfJoystickU

The U axis.

enumerator sfJoystickV

The V axis.

enumerator sfJoystickPovX

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

enumerator sfJoystickPovY

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

Functions

sfBool sfJoystick_isConnected(unsigned int joystick)

Check if a joystick is connected.

Parameters:
  • joystick – Index of the joystick to check

Returns:

sfTrue if the joystick is connected, sfFalse otherwise

unsigned int sfJoystick_getButtonCount(unsigned int joystick)

Return the number of buttons supported by a joystick.

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

Parameters:
  • joystick – Index of the joystick

Returns:

Number of buttons supported by the joystick

sfBool sfJoystick_hasAxis(unsigned int joystick, sfJoystickAxis axis)

Check if a joystick supports a given axis.

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

Parameters:
  • joystick – Index of the joystick

  • axis – Axis to check

Returns:

sfTrue if the joystick supports the axis, sfFalse otherwise

sfBool sfJoystick_isButtonPressed(unsigned int joystick, unsigned int button)

Check if a joystick button is pressed.

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

Parameters:
  • joystick – Index of the joystick

  • button – Button to check

Returns:

sfTrue if the button is pressed, sfFalse otherwise

float sfJoystick_getAxisPosition(unsigned int joystick, sfJoystickAxis axis)

Get the current position of a joystick axis.

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

Parameters:
  • joystick – Index of the joystick

  • axis – Axis to check

Returns:

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

sfJoystickIdentification sfJoystick_getIdentification(unsigned int joystick)

Get the joystick information.

The result of this function will only remain valid until the next time the function is called.

Parameters:
  • joystick – Index of the joystick

Returns:

Structure containing joystick information.

void sfJoystick_update(void)

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.