Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!usenet.ukfsn.org!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Date: Tue, 13 Mar 2012 02:33:51 +0000 (UTC) Organization: UK Free Software Network Lines: 33 Message-ID: References: <4f5d18ef$0$291$14726298@news.sunsite.dk> <4f5d239d$0$293$14726298@news.sunsite.dk> <4f5e8d1f$0$290$14726298@news.sunsite.dk> NNTP-Posting-Host: 84.45.235.129 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: localhost.localdomain 1331606031 13273 84.45.235.129 (13 Mar 2012 02:33:51 GMT) X-Complaints-To: usenet@localhost.localdomain NNTP-Posting-Date: Tue, 13 Mar 2012 02:33:51 +0000 (UTC) User-Agent: Pan/0.135 (Tomorrow I'll Wake Up and Scald Myself with Tea; GIT 30dc37b master) Xref: csiph.com comp.lang.java.programmer:12944 On Tue, 13 Mar 2012 01:05:21 +0100, Jan Burse wrote: > So if somebody has already worked on such a class I would be interested. > Not necessarily a class, but I know two ways of getting single-keystroke input into Java: - use a KeyAdapter to get the key value from each key press event. This certainly works well inside a Swing application: I've used it to accept keystrokes for a terminal emulator. I initially thought this would not work in a headless environment and/or a console environment because its java.awt.event package: which is why I implemented my second suggestion. Now I'm not so sure that's right but I haven't tried using it in a headless/console environment. If you try it, I'll be most interested to hear if it works in a headless environment. - When I found that I needed single keystroke input for another project that must be capable of operating in a console/headless environment and that System.in won't release keystrokes to the program until newline has been typed, I wrote that Java program to read characters from a Socket and a small C program to send keystrokes to it via the socket. This also works well and does what I wanted with the other advantage that I *know* it will work in both headless and console environments since there are no Swing or AWT classes or packages involved. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |