是否有残培()Scala中的等效? [英] Is there an equivalent for getch() in Scala?

查看:132
本文介绍了是否有残培()Scala中的等效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找Scala中的函数具有相似的功能可以参考getch。在使用控制台,我想基于什么字符用户输入(例如,如果我是显示文本​​,击中n是否显示下一个页面,而p的previous)有我的节目显示信息。现在我用的readLine或readChar,但他们需要的用户敲回车每个输入后,有点讨厌。此外,在Eclipse插件的跨preTER,输入的字符显示,虽然我猜这可能是不可避免的。

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.

推荐答案

<一个href=\"http://www.scala-lang.org/api/current/index.html#scala.Console%24\"><$c$c>scala.Console.readChar,别名在斯卡拉的当前化身为<一个href=\"http://www.scala-lang.org/api/current/index.html#scala.$p$pdef%24\"><$c$c>$p$pdef.getChar是最直接的方式。

scala.Console.readChar, aliased in in current incarnations of Scala as Predef.getChar is the most direct way.

scala> readChar
res0: Char = !

更新

这一次没有讨厌的输入

scala> Console.in.read.toChar
res0: Char = !

这篇关于是否有残培()Scala中的等效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆