Unfortunately, this is not possible in portable mode:
http://forums.sun.com/thread.jspa?threadID=5351637&messageID=10526512
On Windows, reading from System.in will be blocked until you press enter , even if you are not using BufferedReader . Arrows will cycle through the history of teams. Try it yourself:
import java.io.*; public class KeyTest { public static void main(String[] argv) { try { InputStreamReader unbuffered = new InputStreamReader(System.in); for (int i = 0; i < 10; ++i) { int x = unbuffered.read(); System.out.println(String.format("%08x", x)); } } catch (Exception e) { System.err.println(e); } } }
The same problem with using the Console class (the input is buffered under Windows, the arrow keys set by Windows):
import java.io.*; public class KeyTest2 { public static void main(String[] argv) { try { Console cons = System.console(); if (cons != null) { Reader unbuffered = cons.reader(); for (int i = 0; i < 10; ++i ) { int x = unbuffered.read(); System.out.println(String.format("%08x", x)); } } } catch (Exception e) { System.err.println(e); } } }
vladr Feb 21 '09 at 2:57 2009-02-21 02:57
source share