I'm looking for a function in Scala that has similar functionality to getch. While using the console, I'd like to have my program display information based on what characters the user inputs (for example, if I was displaying a text, hitting n would show the next page, and p the previous). Right now I'm using readLine or readChar, but they require the user to hit Enter after each input, a bit annoying. Plus, in Eclipse plug-in's interpreter, the input character is shown, although I guess that might be unavoidable.
scala.Console.readChar
, aliased in in current incarnations of Scala as Predef.getChar
is the most direct way.
scala> readChar
res0: Char = !
UPDATE
This time without the pesky Enter
:
scala> Console.in.read.toChar
res0: Char = !
Use StdIn lib:
StdIn.readChar()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With