SFML - Simple and Fast Multimedia Library

SFML 3.0.2
Loading...
Searching...
No Matches
Joystick.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2025 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
30#include <SFML/Window/Export.hpp>
31
32#include <SFML/System/String.hpp>
33
38 namespace sf::Joystick
39{
44// NOLINTBEGIN(readability-identifier-naming)
45 static constexpr unsigned int Count{8};
46 static constexpr unsigned int ButtonCount{32};
47 static constexpr unsigned int AxisCount{8};
48// NOLINTEND(readability-identifier-naming)
49
54 enum class Axis
55{
56 X,
57 Y,
58 Z,
59 R,
60 U,
61 V,
62 PovX,
63 PovY
64};
65
70 struct SFML_WINDOW_API Identification
71{
72 String name{"No Joystick"};
73 unsigned int vendorId{};
74 unsigned int productId{};
75};
76
85[[nodiscard]] SFML_WINDOW_API bool isConnected(unsigned int joystick);
86
97[[nodiscard]] SFML_WINDOW_API unsigned int getButtonCount(unsigned int joystick);
98
110[[nodiscard]] SFML_WINDOW_API bool hasAxis(unsigned int joystick, Axis axis);
111
123[[nodiscard]] SFML_WINDOW_API bool isButtonPressed(unsigned int joystick, unsigned int button);
124
136[[nodiscard]] SFML_WINDOW_API float getAxisPosition(unsigned int joystick, Axis axis);
137
146[[nodiscard]] SFML_WINDOW_API Identification getIdentification(unsigned int joystick);
147
157 SFML_WINDOW_API void update();
158} // namespace sf::Joystick
159
160
String.hpp
Export.hpp
SFML_WINDOW_API
#define SFML_WINDOW_API
Definition Window/Export.hpp:42
sf::String
Utility string class that automatically handles conversions between types and encodings.
Definition String.hpp:89
sf::Joystick
Give access to the real-time state of the joysticks.
Definition Joystick.hpp:39
sf::Joystick::getIdentification
Identification getIdentification(unsigned int joystick)
Get the joystick information.
sf::Joystick::AxisCount
static constexpr unsigned int AxisCount
Maximum number of supported axes.
Definition Joystick.hpp:47
sf::Joystick::getButtonCount
unsigned int getButtonCount(unsigned int joystick)
Return the number of buttons supported by a joystick.
sf::Joystick::Count
static constexpr unsigned int Count
Constants related to joysticks capabilities.
Definition Joystick.hpp:45
sf::Joystick::Axis
Axis
Axes supported by SFML joysticks.
Definition Joystick.hpp:55
sf::Joystick::Axis::X
@ X
The X axis.
Definition Joystick.hpp:56
sf::Joystick::Axis::Z
@ Z
The Z axis.
Definition Joystick.hpp:58
sf::Joystick::Axis::U
@ U
The U axis.
Definition Joystick.hpp:60
sf::Joystick::Axis::V
@ V
The V axis.
Definition Joystick.hpp:61
sf::Joystick::Axis::Y
@ Y
The Y axis.
Definition Joystick.hpp:57
sf::Joystick::Axis::PovX
@ PovX
The X axis of the point-of-view hat.
Definition Joystick.hpp:62
sf::Joystick::Axis::PovY
@ PovY
The Y axis of the point-of-view hat.
Definition Joystick.hpp:63
sf::Joystick::Axis::R
@ R
The R axis.
Definition Joystick.hpp:59
sf::Joystick::getAxisPosition
float getAxisPosition(unsigned int joystick, Axis axis)
Get the current position of a joystick axis.
sf::Joystick::ButtonCount
static constexpr unsigned int ButtonCount
Maximum number of supported buttons.
Definition Joystick.hpp:46
sf::Joystick::isConnected
bool isConnected(unsigned int joystick)
Check if a joystick is connected.
sf::Joystick::update
void update()
Update the states of all joysticks.
sf::Joystick::isButtonPressed
bool isButtonPressed(unsigned int joystick, unsigned int button)
Check if a joystick button is pressed.
sf::Joystick::hasAxis
bool hasAxis(unsigned int joystick, Axis axis)
Check if a joystick supports a given axis.
sf::Joystick::Identification
Structure holding a joystick's identification.
Definition Joystick.hpp:71
sf::Joystick::Identification::name
String name
Name of the joystick.
Definition Joystick.hpp:72
sf::Joystick::Identification::productId
unsigned int productId
Product identifier.
Definition Joystick.hpp:74
sf::Joystick::Identification::vendorId
unsigned int vendorId
Manufacturer identifier.
Definition Joystick.hpp:73