I worked with Pascal and now I'm trying to understand if there is (in java) something similar of the Pascal readkey() command. I've searched it but I haven't found anything good, only answer like this:
try
{
java.io.InputStreamReader in = new java.io.InputStreamReader(System.in);
java.io.BufferedReader THEinput = new java.io.BufferedReader(in);
String s = THEinput.readLine()+"";
System.out.println(s);
}
catch (Exception ex){}
This is not what I'm searching because this command wait for the user press ENTER before go on. I'm searching a command that wait for the first key that the user type (whatever it is: a numer, a char or something other like ESC or TAB or one of the arrows or something other) and immediately go on with the program without waiting any other key from the user.
For example this code:
char n = readkey();
System.out.println((int)n);
if I launch it and press only enter it MUST print
13
That is the ASCII code of ENTER. This java code would be like this other pascal code:
Program PROG;
uses crt;
var x:char;
begin
x := readkey;
writeln(ord(x));
end.
That if you only type ENTER shows 13 and then it closes. Do anyone know how to help me resolve my problem?