This is a singleton approach to creating a light-weight and performant input manager for the SFML 2.5 API. One of the common issues you will find with SFML's input handling is the lack of support for functionality like: press and release. This is a recurring issue for projects I work on, and so I decided to create a light-weight manager I can simply drop into all my SFML projects and expand if necessary.
- Clone this repository
- Add the files to your program, ensure you have linked the proper library and include directories.
- Add #include "InputManager.h" to the top of your file so the pre-compiler can add it to the project.
To keep the keyboard running in line with the rest of the program:
- Firstly, add the following line of code to the end of your event loop.
InputManager::Instance()->KRUpdate(event);
- Secondly, add the following line of code to the end of your game loop.
InputManager::Instance()->Update();
Now you're good to start defining binds!
To add a bind you just have to call the InputManager's singleton instance and call the KBind function:
InputManager::Instance()->KBind(int key, Keyboard::<Key Name>)
InputManager::Instance()->KBind(0, Keyboard::Space);
This is best shown by example, extending from the binding above:
if (InputManager::Instance()->KeyPress(0))
cout << "Space was pressed" << endl;
if (InputManager::Instance()->KeyDown(0))
cout << "Space is held down" << endl;
if (InputManager::Instance()->KeyRelease(0))
cout << "Space was released" << endl;
if (InputManager::Instance()->KeyUp(0))
cout << "Space is up" << endl;
This project was built for the SFML 2.5 API, and as such, you will need to link the library to your project to use this input manager.
If you are looking for support please send a non-spammy looking email to [email protected]. If you are unsure what to write for the title, try something in this format:
[Repository Name] <Question>
A: Don't worry, the adjustment is quite simple! You will just need to modify the mapping from int -> Key
to std::string -> Key
and make adjustments to all references to the map to pass a string instead of int. Huzzah!