From: Marcin Rodzik on 11 Feb 2010 15:05 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
From: Arne Vajhøj on 11 Feb 2010 18:52 On 11-02-2010 15:05, Marcin Rodzik wrote: > 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
From: Martin Gregorie on 11 Feb 2010 19:56 On Thu, 11 Feb 2010 18:52:43 -0500, Arne Vajhøj wrote: > On 11-02-2010 15:05, Marcin Rodzik wrote: >> 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. > 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. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
From: Arne Vajhøj on 11 Feb 2010 21:10 On 11-02-2010 19:56, Martin Gregorie wrote: > On Thu, 11 Feb 2010 18:52:43 -0500, Arne Vajhøj wrote: > >> On 11-02-2010 15:05, Marcin Rodzik wrote: >>> 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. >> > 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
From: Martin Gregorie on 12 Feb 2010 06:53
On Thu, 11 Feb 2010 21:10:37 -0500, Arne Vajhøj wrote: > On 11-02-2010 19:56, Martin Gregorie wrote: >> On Thu, 11 Feb 2010 18:52:43 -0500, Arne Vajhøj wrote: >> >>> On 11-02-2010 15:05, Marcin Rodzik wrote: >>>> 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. >>> >> 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 ? > 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? -- martin@ | Martin Gregorie gregorie. | Essex, UK org | |