识别Java扫描仪或控制台应用程序中的箭头键 [英] Recognize arrow keys in Java Scanner or Console application

查看:82
本文介绍了识别Java扫描仪或控制台应用程序中的箭头键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写同时使用ScannerConsole来获取用户输入的Java应用程序.我想添加命令历史记录支持,以便用户可以使用箭头键搜索以前的输入(类似于终端).有没有办法做到这一点?现在,当我使用ScannerConsole时,按箭头键时会出现类似^[[A的奇怪符号.

I am writing a Java application that uses both Scanner and Console to get input from the user. I would like to add command history support so that the user can use the ARROW KEYS to search previous inputs (similar to a terminal). Is there a way to do this? Right now, when I use either the Scanner or the Console, I get weird symbols like ^[[A when pressing the arrow keys.

我已经阅读了有关KeyListenerKeyEvent的信息,但是我的应用程序未使用GUI.

I have read about KeyListener and KeyEvent, but my application does not use a GUI.

谢谢!

推荐答案

好问题-+1.在Windows上,我将使用SetConsoleMode更改控制台以获取原始输入,但是在* Nix上,似乎涉及更多的工作.不幸的是,我现在没有任何代码可以显示给您,但是请看一下此链接,看看是否有帮助.

Good question - +1'd. On Windows, I would SetConsoleMode to change the console to take raw input, but on *Nix it looks like there is more work involved. Unfortunately I don't have any code that I can show you right now, but have a look at this link and see if it helps.

http://www.darkcoding.net /software/non-blocking-console-io-is-not-possible/

这篇关于识别Java扫描仪或控制台应用程序中的箭头键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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