I have a console program written in Java that should respond to single key presses, but the user does not press enter.
I'm making pong.. so need the up and down keys to move the bat thing.
Alternative approaches welcome! (apart from making a GUI instead)
-- Edit:
I'm only going to run my program on UNIX systems (OSX and Linux), so I think I can put the terminal into "raw" mode with this: stty raw
When I type that into the console before running the program it works! But I need Java to do it automatically, so I tried this:
Runtime.getRuntime().exec("stty raw");
and it does nothing... probably because the JVM is just running it as a separate process and not as a process within this terminal.
I think you can't without native code and JNI. Take a look at Java Curses library: http://sourceforge.net/projects/javacurses/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With