1
General / KeyReleased is repeating
« on: December 28, 2020, 06:07:55 pm »
From what I read I should use KeyReleased when I want to trigger an action exacly once. And for some reason when I use KeyReleased there is a repeat and I don't really know how I can fix it.
void example() {
if (event->type == sf::Event::KeyReleased) {
if (event->key.code == sf::Keyboard::Up) {
std::cout << "UP!" << std::endl;
}
else if (event->key.code == sf::Keyboard::Down) {
std::cout << "DOWN!" << std::endl;
}
}
}
When I am releasing a key then I get multiple UP! or DOWN! when I only wanted one action per released key and the number of actions it returns is completly random sometimes I get 20, sometimes 50, sometimes maybe 3 and on really rare occasions it works as it should and I get 1. Do somebody know what is going on?
void example() {
if (event->type == sf::Event::KeyReleased) {
if (event->key.code == sf::Keyboard::Up) {
std::cout << "UP!" << std::endl;
}
else if (event->key.code == sf::Keyboard::Down) {
std::cout << "DOWN!" << std::endl;
}
}
}
When I am releasing a key then I get multiple UP! or DOWN! when I only wanted one action per released key and the number of actions it returns is completly random sometimes I get 20, sometimes 50, sometimes maybe 3 and on really rare occasions it works as it should and I get 1. Do somebody know what is going on?