如何用JLine编写一个等效的KeyListener? [英] How to write an equivalent of KeyListener with JLine?
问题描述
我在使用Java编写的控制台应用程序。我要做的是处理用户键盘输入。当在终端中使用我们的程序启动长时间进程时,用户必须随时按'q'
停止进程(这是在单独运行
- 运行在另一个不同的线程读取用户输入并向进程的线程中抛出
InterruptedException
- 使用JLine及其
ConsoleReader
- 使用JLine并添加链接到键盘键的
TriggeredAction
但每次我面对同样的问题:用户必须按 ENTER $ c $
感谢您的帮助,如果您有任何想法或我的问题的实际解决方案。
PS:请,如果你认为这是不可能的,不要回答。
也许你可以使用这些库之一,
http://sourceforge.net/projects/jxgrabkey/ for linux
https://code.google.com/p/jintellitype / for windows
与您的问题无关,但我认为可以帮助您,
http://sourceforge.net/projects/javacurses/
所有这一切的问题是,你将失去平台的独立性。
I am working on a console application written in Java. What I have to do is handle user keyboard input. When a long process in launched with our program in a terminal, the user must have the possibility to press 'q'
at anytime to stop the process (which is running on a separate thread).
I've tried several things :
- Running in another different thread something that read user input and throws an
InterruptedException
to the process' thread - Using JLine and its
ConsoleReader
- Using JLine and add a
TriggeredAction
linked to a keyboard key
But each time, I face the same problem : the user has to press ENTER
key, and I don't want that.
Thanks for help if you have any ideas, or the actual solution of my problem.
PS : Please, if you think this is impossible, don't answer. I know it's possible.
Perhaps you could use one of these libraries,
http://sourceforge.net/projects/jxgrabkey/ for linux
https://code.google.com/p/jintellitype/ for windows
Less related with your question, but I think can help you,
http://sourceforge.net/projects/javacurses/
The problem, with all of this, is that you will lost the platform independence.
这篇关于如何用JLine编写一个等效的KeyListener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!