简体   繁体   English

运行期间无阻塞输入流

[英]Non-blocking input stream during run

Working on project console program, that needs an infinite loop, stopped by a key while the process is running , such as 'q', or 'Esc' key, and requires an action uses arrow keys such as Up key to do something , and Down key. 在需要无限循环的项目控制台程序上工作,该进程在进程运行时被一个键(例如“ q”或“ Esc”键)停止,并且需要使用向上键之类的箭头键来执行某项操作,以及向下键。 There is in C/C++ a getch() , but I found after search , there's no equivalent in Java. C / C ++中有一个getch() ,但是我在搜索后发现,Java中没有等效的东西。

System.in.read() will read one bye typed, waiting until one appears before returning. System.in.read()将读取一个键入的字符,等到出现一个字符后再返回。 (for more complex input this will not be enough as it doesn't handle multi byte characters, should be fine for you though...) (对于更复杂的输入,这将是不够的,因为它不能处理多字节字符,但是对您来说应该没问题...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM