CSFML
Enumerations | Functions
Joystick.h File Reference
`#include <SFML/Window/Export.h>`
`#include <SFML/Window/JoystickIdentification.h>`

Go to the source code of this file.

## Enumerations

enum | { sfJoystickCount = 8, sfJoystickButtonCount = 32, sfJoystickAxisCount = 8 }
| Global joysticks capabilities. More...
enum | sfJoystickAxis { sfJoystickX, sfJoystickY, sfJoystickZ, sfJoystickR, sfJoystickU, sfJoystickV, sfJoystickPovX, sfJoystickPovY }
| Axes supported by SFML joysticks. More...

## Functions

CSFML_WINDOW_API sfBool | sfJoystick_isConnected (unsigned int joystick)
| Check if a joystick is connected. More...
CSFML_WINDOW_API unsigned int | sfJoystick_getButtonCount (unsigned int joystick)
| Return the number of buttons supported by a joystick. More...
CSFML_WINDOW_API sfBool | sfJoystick_hasAxis (unsigned int joystick, sfJoystickAxis axis)
| Check if a joystick supports a given axis. More...
CSFML_WINDOW_API sfBool | sfJoystick_isButtonPressed (unsigned int joystick, unsigned int button)
| Check if a joystick button is pressed. More...
CSFML_WINDOW_API float | sfJoystick_getAxisPosition (unsigned int joystick, sfJoystickAxis axis)
| Get the current position of a joystick axis. More...
CSFML_WINDOW_API sfJoystickIdentification | sfJoystick_getIdentification (unsigned int joystick)
| Get the joystick information. More...
CSFML_WINDOW_API void | sfJoystick_update (void)
| Update the states of all joysticks. More...

## Enumeration Type Documentation

## ◆ anonymous enum

anonymous enum

Global joysticks capabilities.

Enumerator
sfJoystickCount | Maximum number of supported joysticks.
sfJoystickButtonCount | Maximum number of supported buttons.
sfJoystickAxisCount | Maximum number of supported axes.

Definition at line 39 of file Joystick.h.

## ◆ sfJoystickAxis

enum sfJoystickAxis

Axes supported by SFML joysticks.

Enumerator
sfJoystickX | The X axis.
sfJoystickY | The Y axis.
sfJoystickZ | The Z axis.
sfJoystickR | The R axis.
sfJoystickU | The U axis.
sfJoystickV | The V axis.
sfJoystickPovX | The X axis of the point-of-view hat.
sfJoystickPovY | The Y axis of the point-of-view hat.

Definition at line 51 of file Joystick.h.

## Function Documentation

## ◆ sfJoystick_getAxisPosition()

CSFML_WINDOW_API 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]

## ◆ sfJoystick_getButtonCount()

CSFML_WINDOW_API 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

## ◆ sfJoystick_getIdentification()

CSFML_WINDOW_API 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.

## ◆ sfJoystick_hasAxis()

CSFML_WINDOW_API 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

## ◆ sfJoystick_isButtonPressed()

CSFML_WINDOW_API 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

## ◆ sfJoystick_isConnected()

CSFML_WINDOW_API 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

## ◆ sfJoystick_update()

CSFML_WINDOW_API 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.