Java forum for Java programmers

Read DEL and BACK key from stdin

Dec 9, 2011 3:31 pm
Xdevel1999

Is it possible to read DEL and BACKSPACE keys from standard in?

If I use:

System.in.read()

these keys are never returned.

Thanks.

Dec 9, 2011 4:19 pm
Lew
Re: read DEL and BACK key from stdin

xdevel1999 wrote:
> Is it possible to read DEL and BACKSPACE keys from standard in?
>
> If I use:
>
> System.in.read()
>
> these keys are never returned.

It is only possible to read what the OS puts into the input stream. What is
the behavior of stdin from the OS point of view?

On your platform and most that we know, the OS buffers input on that stream
until it receives an end-of-line. That line is passed entire to Java to wrap
as an 'InputStream' input. It follows trivially that the Java stream cannot
see the characters you describe unless you escape them.

Have you escaped them?

"Never" is a very strong word.

<http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#in>
public static final InputStream in

<http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html>

Lew
Dec 9, 2011 6:29 pm
Roedy Green
Re: read DEL and BACK key from stdin

On Fri, 9 Dec 2011 07:31:39 -0800 (PST), xdevel1999
<xdevel1999@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>Is it possible to read DEL and BACKSPACE keys from standard in?

I don't think you see anything until the user hits enter.

If you want to see things in a keystroke by keystroke way you need
some sort of gui TextField or the like where you can intercept the
event for each keystroke.

The other way to do it is to use C.
Roedy Green Canadian Mind Products
http://mindprod.com
For me, the appeal of computer programming is that
even though I am quite a klutz,
I can still produce something, in a sense
perfect, because the computer gives me as many
chances as I please to get it right.


Previous Thread: Silly simply question
Next Thread: (java.lang.Runtime()).exec(new String[]) ...

Related Forum Topics
How to read back the lines printed out to the console?
Hi:

We have an existing Java program, which prints out a lot of message
using System.out.println() method to the console. There are about 500
those calls in the code. We hope to add one more feature: besides
print out to the console as it is doing now, we also want to store
those messages...
Back to .Net? lesser of two evils?
With Oracle on one side suing Google over Android
and on the other cooing about how many phones
run Java; I'm wondering if it might be worth it
to put my ideological views about Microsoft aside
and consider going back to .Net.

--
// This is my opinion.


How can I read from the entire standard input at once?
The following code is a stripped down version of a large project. The
question is why do I have to press ctrl z every time to get the
output? That is, say I type the following at the command line

1 - 3

and then press the enter key on my keyboard. I press ctrl z and I get
'The value is 1'...
Read java Annotation field values from class
How to read java Annotation field values from reflect class.
I am having a java class file Myclass.java. This file having the
annotation

@interface MyAnnotation {
boolean DuplicateValues();
boolean DuplicateVariables();
}
@MyAnnotation(DuplicateValues = true, DuplicateVariables =...
Read java Annotation field values from class
How to read java Annotation field values from reflect class.
I am having a java class file Myclass.java. This file having the
annotation

@interface MyAnnotation {
boolean DuplicateValues();
boolean DuplicateVariables();
}
@MyAnnotation(DuplicateValues = true, DuplicateVariables =...
I need to write Simple JAVA program to read and write from USB serialto use it with Arduino
Hi every one

I’m trying to write simple JAVA program that could send command to Arduino board or read output from Arduino.
I tried java-simple-serial-connector library but I keep getting error.
And in Arduino web site they use gnu.io. classpath witch I have no idea how to use it with java...
Socket problem: read & write to same socket
I want to establish connection to a server(written by myself in Go language), read from socket, and then write into socket.

The connection can be established, and it reads correctly. But after that and when I want to write to socket, it closes the connection. I used wireshark to listen to the...