Skip to content

A simple light-weight input manager for the SFML 2.5 API.

Notifications You must be signed in to change notification settings

WerenskjoldH/SFML-Input-Manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Light-weight Header-only Input Manager for SFML-based Projects

License: MIT Repository Size



Purpose

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.


How To Implement:

  1. Clone this repository
  2. Add the files to your program, ensure you have linked the proper library and include directories.
  3. Add #include "InputManager.h" to the top of your file so the pre-compiler can add it to the project.

Updating The Instance:

To keep the keyboard running in line with the rest of the program:

Setup:

  1. Firstly, add the following line of code to the end of your event loop.
    InputManager::Instance()->KRUpdate(event);
  2. 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!


Defining Binds:

To add a bind you just have to call the InputManager's singleton instance and call the KBind function:

Template:

InputManager::Instance()->KBind(int key, Keyboard::<Key Name>)

Example:

InputManager::Instance()->KBind(0, Keyboard::Space);

Checking Input:

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;

Dependencies

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.


Support

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>

Q&A

Q: What if I don't want to use an integer to reference keys?

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!

About

A simple light-weight input manager for the SFML 2.5 API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages