Hi, I thought it'd be good to share something I made recently.
https://github.com/dabbertorres/SwiftInputManagerHere's the example of use on github:
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include "KeyboardManager.hpp"
#include "MouseManager.hpp"
int main(int argc, char** argv)
{
sf::Window window(sf::VideoMode(800, 600, 32), "SFML");
swift::KeyboardManager keyboard;
swift::MouseManager mouse;
keyboard.newBinding("exit", sf::Keyboard::Escape, [&window]()
{
window.close();
});
mouse.newBinding("exit", sf::Mouse::Right, [&window]()
{
window.close();
});
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
keyboard(event);
mouse(event);
switch(event.type)
{
case sf::Event::Closed:
window.close();
break;
default:
break;
}
}
window.clear();
window.display();
}
return 0;
}
Multiple uses of the same button are possible too.
An improvement that I'd like to make in the future though are for multiple keypresses, (Ctrl+A, etc).
Nothing too exciting, but in my own bigger projects I figured this would be a nice way of keeping all of the input handling of keypresses and such wrapped up. It works great for me, so I figured I'd share it, and if anyone is willing, share what they think of it. Thoughts on the quality of the code (I'd love feedback, I haven't shared much of my own, and as I'm pretty much self-taught...), etc, would be great!