Hello. Thanks for the replies.
Which controller are you using? It is an official Xbox one?
You mention that you get no input from the triggers. Although I'm pretty sure this isn't the issue, make sure you don't press them together.
It seems weird that the right analog stick is using Z and R for its axis when there are perfectly good pairs of axes for them (mine doesn't even use the R axis at all!).
Does this mean that you can only get input on left axis pair and Z/R pair (and all the buttons)? That is, none of the other axes are getting input at all?
To answer @Hapax:
- Yes, I'm using an official wireless xbox PC controller
- I've been pressing the two triggers seperately and together, get no input either way
- Yeah, it's wierd that I'm getting R & Z axis inputs mapped to the right analog stick :shrug:
- I'm not sure I understand the question. Currently X & Y are mapped to the left analog stick and R & Z to the right analog stick. In regards to the buttons - A, B, X, Y, right shoulder, left shoulder, left axis press, right axis press, and the left menu button (one below and to the left of the central X box button) all work. But I don't get anything for the Dpad or the other menu button below and to the right of the central X box button don't register any input.
@eXpl0it3r here's some testing code I've written as requested:
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/Window/Joystick.hpp>
#include <iostream>
std::string axisToString(const sf::Joystick::Axis axis) {
switch (axis) {
case sf::Joystick::Axis::PovX:
return "PovX";
case sf::Joystick::Axis::PovY:
return "PovY";
case sf::Joystick::Axis::R:
return "R";
case sf::Joystick::Axis::U:
return "U";
case sf::Joystick::Axis::V:
return "V";
case sf::Joystick::Axis::X:
return "X";
case sf::Joystick::Axis::Y:
return "Y";
case sf::Joystick::Axis::Z:
return "Z";
default:
return "";
}
}
int main() {
sf::RenderWindow window(sf::VideoMode(800, 600), "Test Gamepad");
sf::Joystick::update();
std::vector<sf::Joystick::Axis> connectedAxis;
int numButtons = 0;
int gamePadIdx = -1;
for (int i = 0; i < sf::Joystick::Count; i++) {
if (sf::Joystick::isConnected(i)) {
gamePadIdx = i;
std::cout << "found connected gamepad at idx: " << gamePadIdx
<< std::endl;
numButtons = sf::Joystick::getButtonCount(gamePadIdx);
std::cout << "number of buttons: " << numButtons << std::endl;
connectedAxis.clear();
for (int i = sf::Joystick::Axis::X; i < sf::Joystick::AxisCount; i++) {
sf::Joystick::Axis axis = static_cast<sf::Joystick::Axis>(i);
if (sf::Joystick::hasAxis(gamePadIdx, axis)) {
std::cout << "has axis: " << axisToString(axis) << std::endl;
connectedAxis.push_back(axis);
}
}
break;
}
}
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed: {
std::cout << "shutting down" << std::endl;
window.close();
break;
}
case sf::Event::KeyPressed: {
if (event.key.code == sf::Keyboard::Escape) {
std::cout << "shutting down" << std::endl;
window.close();
}
break;
}
case sf::Event::JoystickConnected: {
// Don't override if there's already a joystick id
if (gamePadIdx == -1) {
gamePadIdx = event.joystickConnect.joystickId;
std::cout << "found connected gamepad at idx: " << gamePadIdx
<< std::endl;
numButtons = sf::Joystick::getButtonCount(gamePadIdx);
std::cout << "number of buttons: " << numButtons << std::endl;
connectedAxis.clear();
for (int i = sf::Joystick::Axis::X; i < sf::Joystick::AxisCount;
i++) {
sf::Joystick::Axis axis = static_cast<sf::Joystick::Axis>(i);
if (sf::Joystick::hasAxis(gamePadIdx, axis)) {
std::cout << "has axis: " << axisToString(axis) << std::endl;
connectedAxis.push_back(axis);
}
}
}
break;
}
case sf::Event::JoystickDisconnected: {
if (event.joystickConnect.joystickId == gamePadIdx) {
std::cout << "gamepad disconnected at idx: " << gamePadIdx
<< std::endl;
gamePadIdx = -1;
}
}
default:
break;
}
}
if (gamePadIdx != -1) {
// Log axis movement
static const float deadZone = 20.f;
for (int i = 0; i < connectedAxis.size(); i++) {
const float axisPos =
sf::Joystick::getAxisPosition(gamePadIdx, connectedAxis);
if (std::abs(axisPos) > deadZone) {
std::cout << "Axis: " << axisToString(connectedAxis)
<< ", Pos: " << axisPos << std::endl;
}
}
// Log button presses
for (int i = 0; i < numButtons; i++) {
if (sf::Joystick::isButtonPressed(gamePadIdx, i)) {
std::cout << "Button: " << i << " is pressed" << std::endl;
}
}
}
}
}
When I run this code locally with a controller already connected (wirelessly or wired) I get the output:
Unexpected usage for element of Page Generic Desktop: 0x1
Unexpected usage for element of Page Generic Desktop: 0x1
Joystick (vendor/product id: 0x45e/0xb20) range is an unexpected one: [1, 8]
found connected gamepad at idx: 0
number of buttons: 15
has axis: X
has axis: Y
has axis: Z
has axis: R
The first three lines seem to indicate something isn't right with how the mac OS platform functions are being called, maybe in
https://github.com/SFML/SFML/blob/2.6.x/src/SFML/Window/OSX/JoystickImpl.cpp (I hadn't seen this log before as I first discovered this issue when writing a game which was outputting a lot to stdout owing to another library).
When testing the axis and buttons I get the corresponding stdout for the results I mentioned earlier:
> I'm not sure I understand the question. Currently X & Y are mapped to the left analog stick and R & Z to the right analog stick. In regards to the buttons - A, B, X, Y, right shoulder, left shoulder, left axis press, right axis press, and the left menu button (one below and to the left of the central X box button) all work. But I don't get anything for the Dpad or the other menu button below and to the right of the central X box button don't register and input.
I should also mention I've been building from the 2.6.x branch and I'm using macOS 12.7.1, maybe I need to downgrade the SFML version I'm using?
Hope that helps, let me know if you need any more information or testing.
Many Thanks,
Haize