In each loop I receive a sf::Event::KeyPressed event , if a key is held down.
Is there a way to receive a single key press?
If I wanted to check if a key is beeing held down, I would use the sf::Input class instead.
sf::Event::KeyReleased events are only received if a key is released, as I would expect it.
Here is a short example of what I mean:
#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Events");
sf::Font Font;
Font.LoadFromFile("ARIAL.TTF", 40);
sf::String Text("", Font, 32);
std::ostringstream oss;
int NbKeysPressed = 0; //counts, how often a key has been pressed
// Start game loop
bool Running = true;
while (Running)
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
switch(Event.Type)
{
case sf::Event::Closed:
{
Running = false;
break;
}
case sf::Event::KeyPressed:
{
++NbKeysPressed;
oss.str("");
oss << NbKeysPressed;
Text.SetText(oss.str());
break;
}
case sf::Event::KeyReleased:
{
--NbKeysPressed;
oss.str("");
oss << NbKeysPressed;
Text.SetText(oss.str());
break;
}
default:
{
break;
}
}
}
App.Draw(Text);
App.Display();
}
return EXIT_SUCCESS;
}
Any ideas?