Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: How can I read individual keystrokes? Date: Sun, 5 Apr 2020 00:17:36 -0000 (UTC) Organization: A noiseless patient Spider Lines: 26 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Sun, 5 Apr 2020 00:17:36 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="1c89068f2c74709a2e576e14a58f5b58"; logging-data="18282"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18vCUOJc9mDsobEeq316FBHvvF8o83la18=" User-Agent: Pan/0.146 (Hic habitat felicitas; 8107378 git@gitlab.gnome.org:GNOME/pan.git) Cancel-Lock: sha1:8Pt2v1Qoj8SaLhmLvfDsEHMPI94= Xref: csiph.com comp.lang.java.programmer:39415 I have a need to read individual key presses as they are made. I'm developing this stuff under Linux with OpenJava 1.8 and would prefer a portable Java solution if that's possible. I have a working solution, but its ugly. A small C program captures the one or more characters emitted as a key is pressed and sends them individually to my Java application over a local network session. I've also tried using the Reader.read() method of the Reader instance returned by calling Console.reader() but that uses line buffering internally. As a result the Java code doesn't get sent anything until I hit RETURN, when all the characters typed since the last RETURN are sent, followed by the LF, so is of no use here. Also, there's a good chance that the C program is using OS-specific features to let it capture individual keystrokes. I have a feeling that I'm missing something obvious and so would appreciate it if any of you can point me in the direction of a pure Java way to capture individual key presses. -- Martin | martin at Gregorie | gregorie dot org