Board index » jbuilder » Keyboard Input?

Keyboard Input?


2005-03-16 05:22:12 PM
jbuilder16
Perhaps a bit off the swing topic, but I wonder if it is possible to
obtain direct keyboard character/signal input from the console.
System.in only reads lines of text and echoes all characters. For a
commandline utility I need to perform password input, so to echo only
"*" instead of the text. - Can somebody know a solution or can give me
directions? Thanks!
 
 

Re:Keyboard Input?

Vander wrote:
Quote
Perhaps a bit off the swing topic, but I wonder if it is possible to
obtain direct keyboard character/signal input from the console.
System.in only reads lines of text and echoes all characters. For a
commandline utility I need to perform password input, so to echo only
"*" instead of the text. - Can somebody know a solution or can give me
directions? Thanks!

java.sun.com/features/2002/09/pword_mask.html
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html
 

Re:Keyboard Input?

On 3/16/2005 at 4:22:12 AM, Vander wrote:
Quote
Perhaps a bit off the swing topic, but I wonder if it is possible to
obtain direct keyboard character/signal input from the console.
System.in only reads lines of text and echoes all characters. For a
commandline utility I need to perform password input, so to echo only
"*" instead of the text. - Can somebody know a solution or can give me
directions? Thanks!
There is nothing in Java that allows this level of control over console
input. To do this with console input, you would need to use some sort of
native library. An alternative approach would be to use a GUI console
window, such as the JConsole class that comes with BeanShell:
www.beanshell.org/
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
www.JPMcGrath.net/newsgroups/e-mail.html
 

{smallsort}

Re:Keyboard Input?

Many thanks both of you, very interesting hints!
In particular the BeanShell approach seems promising. Another question
that arises is if somebody tries to mimic an operating system prompt in
a JConsole, could you possibly redirect system console output of other
programs (e.g. service commands) into the Java application that runs the
JConsole?
John McGrath [TeamB] wrote:
Quote
On 3/16/2005 at 4:22:12 AM, Vander wrote:



>Perhaps a bit off the swing topic, but I wonder if it is possible to
>obtain direct keyboard character/signal input from the console.
>System.in only reads lines of text and echoes all characters. For a
>commandline utility I need to perform password input, so to echo only
>"*" instead of the text. - Can somebody know a solution or can give me
>directions? Thanks!
>
>

There is nothing in Java that allows this level of control over console
input. To do this with console input, you would need to use some sort of
native library. An alternative approach would be to use a GUI console
window, such as the JConsole class that comes with BeanShell:

www.beanshell.org/



 

Re:Keyboard Input?

On 3/17/2005 at 3:16:25 AM, Vander wrote:
Quote
Another question that arises is if somebody tries to mimic an operating
system prompt in a JConsole, could you possibly redirect system console
output of other programs (e.g. service commands) into the Java
application that runs the JConsole?
If you run another program using Runtine.exec(), you have a pipe to the
stdin/stdout/stderr of the process. I think you should be able to hook
those into a JConsole.
I know that JConsole provides line editing, and I do not know if you can
turn that off, so there may some issues if you need character-by-character
input in the program you run. It may be that JConsole will only send an
entire line at a time.
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
www.JPMcGrath.net/newsgroups/e-mail.html