keyboard hits in a console app

M

Marcin Rodzik

Is there any way to track down keys pressed by the user in a console
app? It means reading what he/she is typing immediately. You can read
the standard input stream, but the stream is empty until the user
presses ENTER. I know it's a stuff related to the operating system
which always passes data to the stdin after ENTER is hit, but I'm
looking for some workaround. And it needs to work on both Windows and
Unix/Linux. Any ideas?

MR
 
A

Arne Vajhøj

Is there any way to track down keys pressed by the user in a console
app? It means reading what he/she is typing immediately. You can read
the standard input stream, but the stream is empty until the user
presses ENTER. I know it's a stuff related to the operating system
which always passes data to the stdin after ENTER is hit, but I'm
looking for some workaround. And it needs to work on both Windows and
Unix/Linux. Any ideas?

JNI and a .dll for Windows and a .so for Linux.

Arne
 
M

Martin Gregorie

JNI and a .dll for Windows and a .so for Linux.
I've done the same with a small C program using sockets to pass each
keystroke to the Java app. as a separate packet. It works well and has a
possible advantage because its portable between OSes with no changed to
JNI etc. The C program requires a bit of conditional compilation to cater
for the different ways that different OSes use to set keyboard input to
unbuffered raw reads, but thats about it.
 
A

Arne Vajhøj

I've done the same with a small C program using sockets to pass each
keystroke to the Java app. as a separate packet. It works well and has a
possible advantage because its portable between OSes with no changed to
JNI etc. The C program requires a bit of conditional compilation to cater
for the different ways that different OSes use to set keyboard input to
unbuffered raw reads, but thats about it.

Why is a Java program with 1 C source and N executables more
portable than a Java program with 1 C source and N libraries ?

Arne
 
M

Martin Gregorie

Why is a Java program with 1 C source and N executables more portable
than a Java program with 1 C source and N libraries ?
I was taking the comment that a JNI would use a .DLL for Windows and
a .so for *nixen to mean a change to the JNI code as well. Am I mistaken?
 
A

Arne Vajhøj

I was taking the comment that a JNI would use a .DLL for Windows and
a .so for *nixen to mean a change to the JNI code as well. Am I mistaken?

If the C code compiled to executable can be ifdef'ed to do both
Linux and Windows, then the C code compiled to libraries for the
same two platforms can be ifdef'ed.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top