import java.io.IOException; public final class DemoNonCooked { public static void main(String[] args) throws IOException, InterruptedException { System.out.println("Press any keys; to exit press 'q'"); for (; true;) { if (System.in.available() > 0) { final int c = System.in.read(); System.out.println(String.format("key was pressed, code: %d", c)); if (c == 'q') { break; } } else { Thread.sleep(100); } } } }