Hello
I have a problem regarding checking if an user pressed a button.
Code:#include <iostream>
using namespace std;
int main() {
bool repeat = true;
while (repeat) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape) {
cout << "Are you sure you want to quit?" <<endl;
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::A) {
cout << "A is pressed, moving forward." <<endl;
}
}
}
What I need to do, is checking if an user pressed a button, if it does it should print a message.
My problems:- If I put it in a while loop to repeat checking if a button is pressed, my window gets spammed with "A is pressed, moving forward". The message should just appear once.
- If I don't put a while loop, my program just terminates without me even having the chance to type.
How do I keep repeating that checking for when a button is pressed without my program terminating and without my window spammed with the couts?
Thanks for reading,
Niely