Hi, it's the first time i'm trying event handling but the event KeyReleased is not working properly.
The code in question looks like this:
int main() {
sf::RenderWindow win(sf::VideoMode(800, 800), "Window");
bool button = false;
while (win.isOpen()) {
sf::Event event;
while (win.pollEvent(event))
{
switch (event.type) {
case sf::Event::Closed:
win.close();
break;
case sf::Event::KeyPressed:
switch (event.key.code) {
case 0:
button = true;
break;
}
case sf::Event::KeyReleased:
switch (event.key.code) {
case 0:
button = false;
break;
}
}
}
if (button) {
std::cout << "Key pressed" << std::endl;
}
else {
std::cout << "Key not pressed" << std::endl;
}
}
}
I'm trying to manage key imputs as explaned in the event tutorial but as key released keeps repeting the boolean continuously returns false.
Does anyone knows how to fix it?