I have a console program written in Java that should respond with one keystroke, but the user does not press the enter key.
I'm doing pong .. so I need the up and down keys to move the beat game.
Alternative approaches are welcome! (besides creating a graphical interface)
- Change:
I will run my program only on UNIX systems (OSX and Linux), so I think I can put the terminal in raw mode with this: stty raw
When I enter it into the console before starting the program, it works! But I need Java to do this automatically, so I tried this:
Runtime.getRuntime().exec("stty raw");
and it does nothing ... perhaps because the JVM just starts it as a separate process, and not as a process inside this terminal.
java console
Matt
source share