Java 콘솔 키 이벤트 리더

1 개요[ | ]

Java Console Key Reader, Java Console KeyEvent Reader, Java Console Key Reader without Enter Key
Java 콘솔 키 리더, 자바 콘솔 키 리더, Java 콘솔 키 이벤트 리더
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;
    }
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}