From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: How to get char without press <enter>
Date: 1999/03/02
Date: 1999-03-02T00:00:00+00:00 [thread overview]
Message-ID: <AwSKnDLZ#GA.252@pet.hiwaay.net> (raw)
In-Reply-To: Pine.OSF.3.95.990302110209.18411C-100000@dec1
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 <termios.h>
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.
next prev parent reply other threads:[~1999-03-02 0:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-11-23 0:00 Ada-Belgium'98 - Concurrency & Real-Time - 98/12/04 Dirk Craeynest
1998-11-26 0:00 ` Exception
1998-11-27 0:00 ` Jerry van Dijk
1999-03-02 0:00 ` How to get char without press <enter> BIARD EMMANUEL PATRICE
1999-03-02 0:00 ` David C. Hoos, Sr. [this message]
1999-03-02 0:00 ` nabbasi
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox