Hi, I wanted to track the events with a function like this, and then I realized that I keep getting sf::Event::KeyReleased events infinitely until the window receives another type of event. This is the code:
bool GetEvent(sf::RenderWindow &window, sf::Event &event)
{
bool b = window.GetEvent(event);
// Here you will get this event infinitely before you receive another type of event (like moving the mouse)
if(event.Type == sf::Event::KeyReleased) std::cout << "key released" << std::endl;
return b;
}
int main()
{
sf::RenderWindow window;
window.Create(sf::VideoMode(800, 600), "Bug?");
sf::Event event;
while(window.IsOpened())
{
while(GetEvent(window, event))
{
switch(event.Type)
{
// Close the window
case sf::Event::Closed:
window.Close();
break;
// Check for the key released event. Here it works fine!
case sf::Event::KeyReleased:
std::cout << "=========== KEY RELEASED ===========" << std::endl;
break;
}
}
}
}
I haven't tried with sf::Window. It's my fault?
EDIT:
Somehow, it's fixed if you change the function so it resets the event, like this:
bool GetEvent(sf::RenderWindow &window, sf::Event &event)
{
// Add this to "reset" the event
event.Type = sf::Event::Count;
bool b = window.GetEvent(event);
if(event.Type == sf::Event::KeyReleased) std::cout << "key released" << std::endl;
return b;
}