Processing input in full lines is easy. Processing his character at a time is slightly dependent on the system. If you are using a Unix-like system, you can 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
source share