5

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?

David
  • 1,296
  • 1
  • 15
  • 25
  • 1
    How will your program know when the output from the speech recognition is complete? – Tom G Jan 27 '11 at 19:07
  • That was a concern, however, I am reasonably sure I can manage that with correct command parsing. – David Jan 27 '11 at 19:32

3 Answers3

1

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

Community
  • 1
  • 1
prolink007
  • 30,784
  • 21
  • 111
  • 173
  • Thank you for the link Sir, I will check into it! However, I thought Android did events and they were not normal for Java. However, I will look! – David Jan 27 '11 at 19:34
1

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.

Community
  • 1
  • 1
Eric Giguere
  • 3,435
  • 13
  • 11
0

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.

Babak Naffas
  • 11,532
  • 3
  • 32
  • 48