From 760cda8c47ea8acb7d4007fd57aff5ba1c776735 Mon Sep 17 00:00:00 2001 From: Brian Matzon Date: Tue, 3 Sep 2002 18:08:52 +0000 Subject: [PATCH] fix: better keyboard handling --- src/java/org/lwjgl/openal/test/ALTest.java | 33 ++++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/java/org/lwjgl/openal/test/ALTest.java b/src/java/org/lwjgl/openal/test/ALTest.java index ab80d964..1fcb499d 100644 --- a/src/java/org/lwjgl/openal/test/ALTest.java +++ b/src/java/org/lwjgl/openal/test/ALTest.java @@ -552,7 +552,7 @@ public class ALTest extends BasicTest { try { ch = System.in.read(); - System.in.read(); + eatInput(); } catch (IOException ioe) { } @@ -999,31 +999,34 @@ public class ALTest extends BasicTest { if ((ch == 'S') || (ch == 's')) { return 0; } - if (ch == 0) { + if (ch == 10) { return 1; } } } protected int CRToContinue() { - int ch = 0; - int lastchar = 0; - - do { - lastchar = ch; - try { - ch = System.in.read(); - System.in.read(); - } catch (IOException ioe) { + int current = -1; + try { + //read one, and eat the rest + current = System.in.read(); + eatInput(); + } catch (Exception e) { + } + return (current == 13) ? 10 : current; + } + + protected void eatInput() { + try { + while(System.in.available() > 0) { + int eaten = System.in.read(); } - } while (ch != 10); - - return lastchar; + } catch (Exception e) { + } } protected void CRForNextTest() { System.out.print("\nPress Return to continue on to the next test.\n"); - CRToContinue(); }