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 UAA15108; Thu, 2 May 2002 20:03:19 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 UAA15102 for ; Thu, 2 May 2002 20:03:18 +0200 (MET DST) Received: from moutng0.schlund.de (moutng0.kundenserver.de [212.227.126.170]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g42I3HD08573 for ; Thu, 2 May 2002 20:03:18 +0200 (MET DST) Received: from [212.227.126.160] (helo=mrelayng0.kundenserver.de) by moutng0.schlund.de with esmtp (Exim 3.22 #2) id 173KvA-00021C-00; Thu, 02 May 2002 20:03:12 +0200 Received: from [80.129.98.108] (helo=gate.gerd-stolpmann.de) by mrelayng0.kundenserver.de with asmtp (Exim 3.22 #2) id 173Kv9-0002WZ-00; Thu, 02 May 2002 20:03:12 +0200 Received: from ice.gerd-stolpmann.de (ice.gerd-stolpmann.de [192.168.0.13]) by gate.gerd-stolpmann.de (Postfix) with ESMTP id 41146CCCF; Thu, 2 May 2002 20:02:55 +0200 (CEST) Received: from ice (localhost [127.0.0.1]) by ice.gerd-stolpmann.de (Postfix) with ESMTP id 4C27B1AD70; Thu, 2 May 2002 20:02:50 +0200 (MEST) Date: Thu, 2 May 2002 20:02:49 +0200 From: Gerd Stolpmann To: Vincent Barichard Cc: CAML-LIST Subject: Re: [Caml-list] catch keypressed Message-ID: <20020502200249.C569@ice.gerd-stolpmann.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit In-Reply-To: ; from barichar@info.univ-angers.fr on Thu, May 02, 2002 at 12:23:57 +0200 X-Mailer: Balsa 1.2.4 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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() = let m = tcgetattr stdin in tcsetattr stdin TCSAFLUSH { m with c_icanon = false }; let s = 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=false). 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 function 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.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