caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] read a key press
@ 2002-08-05 10:10 zw
  2002-08-05 10:59 ` Tim Freeman
  0 siblings, 1 reply; 2+ messages in thread
From: zw @ 2002-08-05 10:10 UTC (permalink / raw)
  To: caml-list

Hi,

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.

I found Stream can't do this. Stream only begins to parse the input from 
keyboard after I press Ctrl-D. read_char from Pervasive can't do this 
either. It only begins to do stuff after I press the Return key. What I 
want is a read function that read instantly after a charcter key being 
pressed.

Can you give me some recommendations? Thanks in advance.
zw

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] read a key press
  2002-08-05 10:10 [Caml-list] read a key press zw
@ 2002-08-05 10:59 ` Tim Freeman
  0 siblings, 0 replies; 2+ messages in thread
From: Tim Freeman @ 2002-08-05 10:59 UTC (permalink / raw)
  To: zhaoway; +Cc: caml-list

>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       
tim@fungible.com
GPG public key fingerprint ECDF 46F8 3B80 BB9E 575D  7180 76DF FE00 34B1 5C78 
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-08-05 11:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-05 10:10 [Caml-list] read a key press zw
2002-08-05 10:59 ` Tim Freeman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).