Java 流键盘输入
我正在编写一个通过控制台接受命令的程序。
但是,我不想按“输入”来发送该命令。
我希望代码不断监视我输入的内容,并在我完成后执行代码。
这些命令是来自语音识别程序的文本,因此,消除“输入”笔划的需要非常关键。
有人有什么想法吗?
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 need for the "enter" stroke is pretty key.
Any one have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最近开始了解java中的事件,我相信这会对你有所帮助。您只需要将屏幕上的语音识别打印与 java 中的事件关联起来,它就会有一个侦听器来侦听该事件,当它看到该事件时,它将执行您想要的代码。我目前打开了一个线程,我试图在其中获取一些很好的例子,也许这会有所帮助。
Java 事件问题
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
已经在这里回答:
如何在 Java 中从控制台读取单个字符(当用户键入时)?
没有可移植的方法来执行此操作,具体取决于您的平台。
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.
我从大学起就没有使用过 Java,但如果您从命令行读取内容,那么您正在使用 System.in.read() 或类似的东西。由于这些是阻塞方法调用,因此在按下 ENTER 之前,您的应用程序永远不会收到有关新输入的通知。
如果我完全错了,请告诉我。
您可能最好使用一个简单的(甚至可能是隐藏的),它可以获取用户文本和 UI 元素上的事件侦听器,将其读入应用程序的文本处理器。
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.