Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] read a key press
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-08-05 (11:06)
From: tim@f...
Subject: Re: [Caml-list] read a key press
>I want to write a small echo program (for self amusement). It's like 
>that everytime I press a character key, there's a hook function got 
>called. Somewhat like a event loop.

The operating system is buffering your line of input so it can process
any rubouts you might do.

There are lots of ways to invoke OCAML in different operating systems,
so there isn't one way to get it to work.  I just had this dialogue
under an xterm in linux that does something resembling what you want:

   lobus:~> stty cbreak; ocaml
           Objective Caml version 3.04

   # 3+4;;
   - : int = 7
   # read_char stdin;;
   Unbound value read_char
   # input_char stdin;;
   x- : char = 'x'

The "stty cbreak" gets rid of line buffering, so backspace becomes a
normal input character instead of rubbing out the previous character.
Tim Freeman
GPG public key fingerprint ECDF 46F8 3B80 BB9E 575D  7180 76DF FE00 34B1 5C78 
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: