I'm having some trouble with Joystick events. When I plug in my PS3 Dualshock 3 controller, I only get console output telling me that the controller was connected the first time the controller is plugged in. If I unplug the controller and plug it back in I no longer receive console output telling me that the controller was connected. I also never receive console output telling me that the controller was disconnected. However, even though the connected and disconnected events produce no console output, the button pressed event always does when a button is pressed.
Here is the code that handles the events:
#ifndef GAME_H
#define GAME_H
#include <SFML/Graphics.hpp>
#include "renderer.hpp"
class Game
{
public:
Game();
void run();
private:
sf::RenderWindow window;
sf::Event event;
Renderer renderer;
};
#endif
#include <iostream>
#include "game.hpp"
Game::Game() : window(sf::VideoMode(800, 600), "Game"), renderer(window)
{
window.setFramerateLimit(60);
}
void Game::run()
{
while(window.isOpen())
{
while(window.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
{
window.close();
break;
}
case sf::Event::JoystickConnected:
{
std::cout << "Controller connected!\n";
break;
}
case sf::Event::JoystickDisconnected:
{
std::cout << "Controller disconnected!\n";
break;
}
case sf::Event::JoystickButtonPressed:
{
std::cout << "Controller button pressed!\n";
break;
}
}
}
renderer.render();
}
}
Do you know what might be causing this behaviour? Any help would be much appreciated, thanks.