- sf
- Joystick
Give access to the real-time state of the joysticks. More...
#include <Joystick.hpp>
Classes | |
struct | Identification |
Structure holding a joystick's identification. More... | |
Public Types | |
enum | { Count = 8, ButtonCount = 32, AxisCount = 8 } |
Constants related to joysticks capabilities. More... | |
enum | Axis { X, Y, Z, R, U, V, PovX, PovY } |
Axes supported by SFML joysticks. More... | |
Static Public Member Functions | |
static bool | isConnected (unsigned int joystick) |
Check if a joystick is connected. More... | |
static unsigned int | getButtonCount (unsigned int joystick) |
Return the number of buttons supported by a joystick. More... | |
static bool | hasAxis (unsigned int joystick, Axis axis) |
Check if a joystick supports a given axis. More... | |
static bool | isButtonPressed (unsigned int joystick, unsigned int button) |
Check if a joystick button is pressed. More... | |
static float | getAxisPosition (unsigned int joystick, Axis axis) |
Get the current position of a joystick axis. More... | |
static Identification | getIdentification (unsigned int joystick) |
Get the joystick information. More... | |
static void | update () |
Update the states of all joysticks. More... | |
Give access to the real-time state of the joysticks.
sf::Joystick provides an interface to the state of the joysticks.
It only contains static functions, so it's not meant to be instantiated. 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, sf::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.
SFML supports:
Unlike the keyboard or mouse, the state of joysticks is sometimes not directly available (depending on the OS), therefore an update() function must be called in order to update the current state of joysticks. When you have a window with event handling, this is done automatically, you don't need to call anything. But if you have no window, or if you want to check joysticks state before creating one, you must call sf::Joystick::update explicitly.
Usage example:
Definition at line 41 of file Joystick.hpp.
anonymous enum |
Constants related to joysticks capabilities.
Enumerator | |
---|---|
Count | Maximum number of supported joysticks. |
ButtonCount | Maximum number of supported buttons. |
AxisCount | Maximum number of supported axes. |
Definition at line 49 of file Joystick.hpp.
enum sf::Joystick::Axis |
Axes supported by SFML joysticks.
Enumerator | |
---|---|
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. |
Definition at line 60 of file Joystick.hpp.
|
static |
Get the current position of a joystick axis.
If the joystick is not connected, this function returns 0.
joystick | Index of the joystick |
axis | Axis to check |
|
static |
Return the number of buttons supported by a joystick.
If the joystick is not connected, this function returns 0.
joystick | Index of the joystick |
|
static |
Get the joystick information.
joystick | Index of the joystick |
|
static |
Check if a joystick supports a given axis.
If the joystick is not connected, this function returns false.
joystick | Index of the joystick |
axis | Axis to check |
|
static |
Check if a joystick button is pressed.
If the joystick is not connected, this function returns false.
joystick | Index of the joystick |
button | Button to check |
|
static |
Check if a joystick is connected.
joystick | Index of the joystick to check |
|
static |
Update the states of all joysticks.
This function is used internally by SFML, so you normally don't have to call it explicitly. However, you may need to call it if you have no window yet (or no window at all): in this case the joystick states are not updated automatically.