keyPressed, keyPressed(), keyTyped, etc. Does not work in while loop condition statement.
in
Programming Questions
•
1 year ago
Hi,
I'm new to Processing, so maybe there is something obvious that I'm missing.
I'm writing a sketch where I need it to wait for serial data or single-key input from the keyboard.
I'm using a while loop to wait for those events, but keyboard entries don't seem to register when the sketch is in the while loop.
Here's an example (ignoring the serial aspect, which seems to work fine). When I run it, it never gets out of the while loop, so it never prints "key was pressed". And, usually, the sketch locks up and I have to end java manually in task manager.
void setup() { }
void draw() {
while (keyPressed == false) {
println ("waiting for key press");
}
println ("key was pressed");
}
Thanks for any help.
1