开发者

Java Stream Keyboard Input

I am writing a program that takes commands via the console.

However, I do not want to press "enter" in order to send that command.

I want the code to constantly monitor what I am entering, and execute the code when I am finished.

The commands are coming as text from a speech recognition program, therefore, eliminating the ne开发者_运维知识库ed for the "enter" stroke is pretty key.

Any one have any ideas?


I have recently come to the knowledge of events in java and i believe this would help you. You would just need to associate the speech recognition printing to the screen with an event in java and it would have a listener to listen for the event and when it sees the event it would execute your desired code. I currently have a thread opened where im trying to get some good examples of this, perhaps that will help.

Java Events Question


Already answered here:

How to read a single char from the console in Java (as the user types it)?

No portable way to do it, depends on your platform.


I haven't worked with Java since college, but if you're reading from the command line, then you are using System.in.read() or something similar. Since these are blocking method calls, your application will never be notified about the new input until ENTER is pressed.

If I'm dead wrong, please let me know.

You're probably better off using a simple (possibly even hidden) that can take the user text and an event listener on the UI element that reads it in to the application's text processor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜