I'm using a number of objects I iterate over (array of base class pointers to be specific) when I receive an input event. Each one has an "Update()" method that is called when receiving an input event, e.g. for keyboard inputs I've got this:
void KeyInput::Update(const sf::Event &event)
{
if ((event.Type == sf::Event::KeyPressed || event.Type == sf::Event::KeyReleased) && key == event.Key.Code)
{
Tapped = event.Type == sf::Event::KeyPressed && !Down;
Down = event.Type == sf::Event::KeyPressed;
}
}
For comparison, this is for gamepad/joystick buttons:
void JoyButtonInput::Update(const sf::Event &event)
{
if ((event.Type == sf::Event::JoystickButtonPressed || event.Type == sf::Event::JoystickButtonReleased) && controller == event.JoystickButton.JoystickId && button == event.JoystickButton.Button)
{
Tapped = event.Type == sf::Event::JoystickButtonPressed && !Down;
Down = event.Type == sf::Event::JoystickButtonPressed;
}
}
After this handling is done, I'm able to use the members "Tapped" and "Down" to determine whether some key has been pressed (still down) or tapped (one frame only). Once updating is done, I reset the "Tapped" member of all input objects to false, so it's no longer set while holding down the key/button.
It's probably not the most effective way to handle this, but it's very convenient to handle and sufficient for my use for now.