问题
I'm looking for something like input_char stdin but without waiting for a return key. I would not to depend on a big dependency like lambda-term.
回答1:
Handling input in full lines is easy. Handling it a character at a time is a little bit system dependent. If you're on a Unix-like system you should be able to do this using the Unix module:
let get1char () =
let termio = Unix.tcgetattr Unix.stdin in
let () =
Unix.tcsetattr Unix.stdin Unix.TCSADRAIN
{ termio with Unix.c_icanon = false } in
let res = input_char stdin in
Unix.tcsetattr Unix.stdin Unix.TCSADRAIN termio;
res
来源:https://stackoverflow.com/questions/13410159/how-to-read-a-character-in-ocaml-without-a-return-key