Keep checking if-statement

Hello

How do you keep an if-statement active?
I already searched the whole internet, but only found results on how to keep your terminal active.

So, this is actually what I mean:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

using namespace std;
int main() {
bool repeat = true;

while (repeat) {
	if (buttonESC == pressed) {
		cout << "Are you sure you want to quit?" <<endl;
	} else if (buttonA == pressed) {
		cout << "A is pressed, moving forward." <<endl;
	}
}
}

It's pseudo of course.

The problem is, with this code; that if I press for example 'A', that the cout keeps repeating and my screens get spammed with "moving forward".

How do I keep checking if button gets pressed, but only cout once?

Thanks for reading,
Niely
Last edited on
assign non-A to the variable that holds the buttonA.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

using namespace std;
int main() {
bool repeat = true;

while (repeat) {
	if (buttonESC == pressed) {
		cout << "Are you sure you want to quit?" <<endl;
	} else if (buttonA == pressed) {
		cout << "A is pressed, moving forward." <<endl;
buttonA = '\0';
	}
}
}
^How would that work if I use the SFML library?
1
2
3
4
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
 cout << "A" <<endl;
 sf::Keyboard::A = '\0';
}
Last edited on
Topic archived. No new replies allowed.