0

I know it is possible to loop until the user presses the enter key:

while (system.in.available() == 0) {
  // ...
}

But I don't know how to loop until the user presses any key:

while (any_key_is_not_pressed) {
  // ...
}

I know that there is a way to do it in a GUI by tracking keyboard events. Can I do it in a console app?

Thanks!

cmutex
  • 1,478
  • 11
  • 24
  • I don't think so. Getting into the details of drivers for consoles is a big, big headache. Java seems to have obviated this problem by only allowing line input, not individual characters. (If you need to input a password, there's a `Console.readPassword()` method that echoes stars instead of the character a user types.) – markspace Feb 23 '19 at 20:34
  • Interestingly enough, the correct answer is the **second** on the duplicated answer: you can't do what you want! The console does not report back individual chars, only after enter is pressed you get to see it! – GhostCat Feb 23 '19 at 20:34

0 Answers0