SFML community forums

Help => General => Topic started by: ytivarg on November 14, 2017, 03:49:21 pm

Title: sf::Joystick only reads xbox controllers and no other types
Post by: ytivarg on November 14, 2017, 03:49:21 pm
I wanted to try to get everything controller-related working with SFML before trying my luck with xinput, but the title says the problem.  I have an xbox one controller, a steel series controller, and 2 logitec gamepads.  The only one that SFML can read for me is the xbox one controller. 

while (window.isOpen())
        {
                //get player pressing escape to close the game
                if (Keyboard::isKeyPressed(Keyboard::Escape) || sf::Joystick::isButtonPressed(0, 2))
                {
                        window.close();
                }
                window.clear();//clears the window to draw the next frame
                sf::Joystick::update();
                window.display();
        }

Just trying to see if "x" is pressed on the controller to close the window (still learning everything).  No problems with the xbox controller and nothing happens with the other ones. 
Title: Re: sf::Joystick only reads xbox controllers and no other types
Post by: eXpl0it3r on November 14, 2017, 05:07:12 pm
Maybe first check if you get a controller connected. The button layout isn't the same for all controllers, so your hard-coded value might not be the x button.

With xinput don't you get support for only xbox controllers?
Title: Re: sf::Joystick only reads xbox controllers and no other types
Post by: ytivarg on November 14, 2017, 05:44:51 pm
Thanks for the response.  In my experience, all standard controllers have had the same numbering system for the buttons, except for a generic 5$ one i got from china.  Used to do it on pygame no problem never had an issue with that.  I did end up finding a really well built xinput class and have gotten it to work with every controller I have.   It was daunting at first because that was my first c++ experience with classes and it took a lot of trial and error getting it to work, but it all works perfectly now.  Still curious as to what might fix the issue with SFML, but now that I got it working with xinput i'm finally moving on with the game coding udemy class I'm taking. 

This link is where I found the class I'm using.  Took a bit to fully figure it out but it works perfectly. 
https://www.codeproject.com/Articles/26949/Xbox-Controller-Input-in-C-with-XInput
Title: Re: sf::Joystick only reads xbox controllers and no other types
Post by: ytivarg on November 14, 2017, 06:10:45 pm
Also I did press every button on the controllers before to test them.