From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, WEIRD_QUOTING autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b4046e8267548c91 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: How to get char without press Date: 1999/03/02 Message-ID: #1/1 X-Deja-AN: 450355537 References: <73a774$2ai@neptunus.cs.kuleuven.ac.be> <365d9d8e.10956594@news.xs4all.nl> Newsgroups: comp.lang.ada X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Date: 1999-03-02T00:00:00+00:00 List-Id: BIARD EMMANUEL PATRICE wrote in message ... >Hello everybody, > >I would like to know how to get a char without press enter >I work on Unix plateform (System V) >Language: ADA, C or anyone who can make an object file. Here's a simple Ada program: with Ada.Text_Io; procedure Tgi is Item : Character; begin loop Ada.Text_Io.Get_Immediate (Item => Item); Ada.Text_Io.Put_Line ("""" & Integer'Image (Character'Pos (Item)) & """"); exit when Item = 'Z'; end loop; end Tgi; The above program will echo the characters to the terminal. If you don't want the characters to echo, you can use this program: with Ada.Text_Io; with Interfaces.C; procedure Tgi is pragma Linker_Options ("console_echo.o"); Item : Character; Available : Boolean; procedure Set_Console_Echo (Fd : Interfaces.C.Int; State : Interfaces.C.Int); pragma Import (C, Set_Console_Echo, "set_console_echo"); begin Set_Console_Echo (0,0); loop Ada.Text_Io.Get_Immediate (Item => Item, Available => Available); if Available then Ada.Text_Io.Put_Line ("""" & Integer'Image (Character'Pos (Item)) & """"); exit when Item = 'Z'; end if; end loop; Set_Console_Echo (0,1); end Tgi; Along with this Ada program, you will need to compile the following C file, named console_echo.c: #include struct termios termios_struct; void set_console_echo (int fd, int state) { tcgetattr (fd, & termios_struct); if (state == 0) { termios_struct.c_lflag &= ~ (ECHO); } else { termios_struct.c_lflag |= (ECHO); } tcsetattr (fd, TCSAFLUSH, & termios_struct); } Hope this helps. David C. Hoos, Sr.