From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA01865; Fri, 3 May 2002 15:59:53 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA01884 for caml-list@pauillac.inria.fr; Fri, 3 May 2002 15:59:53 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA01028 for ; Fri, 3 May 2002 15:33:32 +0200 (MET DST) Received: from mail.info.univ-angers.fr (nes.info.univ-angers.fr [193.49.146.122]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g43DXVX14095 for ; Fri, 3 May 2002 15:33:31 +0200 (MET DST) Received: from orion.info-ua (orion.info-ua [172.20.41.6]) by mail.info.univ-angers.fr (Postfix) with ESMTP id 1E3CD8AC; Fri, 3 May 2002 15:33:26 +0200 (CEST) Received: from helios.info-ua (helios.info-ua [172.20.41.5]) by orion.info-ua (Postfix) with ESMTP id 84E7C175CA; Fri, 3 May 2002 15:33:26 +0200 (MEST) Received: by helios.info-ua (Postfix, from userid 759) id 6DFAD14213; Fri, 3 May 2002 13:33:25 +0000 (MET) Received: from localhost (localhost [127.0.0.1]) by helios.info-ua (Postfix) with ESMTP id 5A1761D8B; Fri, 3 May 2002 15:33:25 +0200 (MEST) Date: Fri, 3 May 2002 15:33:25 +0200 (MEST) From: Vincent Barichard X-X-Sender: barichar@helios.info-ua To: Gerd Stolpmann Cc: CAML-LIST Subject: Re: [Caml-list] catch keypressed In-Reply-To: <20020502200249.C569@ice.gerd-stolpmann.de> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Thanks for your help, I'll use the following function which works very well : open Unix;; let waitkey() =3D let m =3D tcgetattr stdin in tcsetattr stdin TCSANOW { m with c_vmin =3D 0; c_icanon =3D false }; let s =3D String.create 1 in ignore(read stdin s 0 1); tcsetattr stdin TCSAFLUSH m; s.[0] ;; Thanks again. Vincent On Thu, 2 May 2002, Gerd Stolpmann wrote: > > On 2002.05.02 12:23 Vincent Barichard wrote: > > > > Hello, > > > > I would like to catch the hit of a key without being in graphic > > mode. Something like : > > > > while not keypressed() do > > print_string "Hit a key"; > > done; > > > > Is a fonction of this kind exists in CAML ?? > > And if it doesn't exist, is there a way to simulate its effect ?? > > The read_int fonction blocks until user enter a value so it is not > > suitable for my problem. > > > > thanks for your help > > > > Vincent > > Quite simple: Turn the "canonical mode" of stdin off, and keypresses > are reported immediately: > > open Unix;; > let waitkey() =3D > let m =3D tcgetattr stdin in > tcsetattr stdin TCSAFLUSH { m with c_icanon =3D false }; > let s =3D String.create 1 in > ignore(read stdin s 0 1); > tcsetattr stdin TCSAFLUSH m; > s.[0] > ;; > > Maybe you also want to turn off echo mode (c_echo=3Dfalse). Changing the > terminal mode is dangerous, because it is a property of the terminal > emulator, and is not automatically reset if the program stops for any > reason. Because of this, it is a good idea to register an at_exit functio= n > that restores the terminal mode when the program terminates, and to catch > also the various signals that might lead to termination. > > And if the cursor has vanished: type "stty sane" to reset the terminal > modes from the shell. > > Gerd > -- > -------------------------------------------------------------------------= --- > Gerd Stolpmann Telefon: +49 6151 997705 (privat) > Viktoriastr. 45 > 64293 Darmstadt EMail: gerd@gerd-stolpmann.de > Germany > -------------------------------------------------------------------------= --- > ------------------- > To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inr= ia.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 > Vincent Barichard M=E9taheuristiques et Optimisation Combinatoire Facult=E9 des Sciences d'Angers Tel : 02 41 73 52 06 ------------------- 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