import org.json.JSONObject;
import java.io.IOException;
public class App {
public static void main(String[] args) {
System.out.println("Press ESC to exit.");
JSONObject key;
while (true) {
key = getKey();
System.out.println(key);
}
}
private static JSONObject getKey() {
try {
ProcessBuilder builder = new ProcessBuilder("powershell",
"$Host.UI.RawUI.FlushInputBuffer(); ConvertTo-Json($Host.UI.RawUI.ReadKey('IncludeKeyDown,NoEcho'))").inheritIO();
builder.redirectOutput(ProcessBuilder.Redirect.PIPE);
Process process = builder.start();
process.waitFor();
return new JSONObject(new String(process.getInputStream().readAllBytes()));
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
return null;
}
}