[comp.lang.ada] How do I read in a character w/out pressing return ?

Arne.Gehlhaar@arbi.informatik.uni-oldenburg.de (Arne Gehlhaar) (11/19/90)

Hello

I have Question concerning the input of characters.  I wrote a little
program, to scan through a sequential file, and want to be able to
go forward and backward.  So I wrote :
		direction : character;

		get(direction);
		case ...

The thing is though, that I have to press return every time I enter
the "command".  Is there any way I can make the program accept just
a 'touch of a button'?  I tried looking at the text_io file, but it
turned out, that the thing is a little more complicated than I expected.

As far as I know, there is no ADA command that allows me to do that.
Is there a way of getting around that ?

Thanks for any replys!

Greetings
Arne
received data 988 bytes 5.95 secs

defaria@hpclapd.HP.COM (Andy DeFaria) (11/22/90)

Seems we just went through this discussion a little while back.

There is no good way to do it using  pure Ada.  The  best way to accomplish
this, IMHO, is to interface with the OS system call that reads a character.
Encapsulate this  procedures (GET_KEY) into  a  package  (SYSTEM_CALLS)  to
minimize and localize portablity concerns.  The Ada call will 1) insure the
types coming  in  and going  out are  correct  and  pragma INTERFACE to the
correct system call (depending, of course, on the OS in question).

so (hypothetical example, assume reasonable type definitions):

package SYSTEM_CALLS is

   type STATUS_TYPE is new INTEGER;
   type CHAR_PTR    is access CHARACTER;

   OK : constant STATUS_TYPE := 0;

   function GET_KEY (THE_CHARACTER : in CHAR_PTR) return STATUS_TYPE;
   pragma INTERFACE (C, GET_KEY);
   pragma INTERFACE_NAME (GET_KEY, "getchar");
                     
end SYSTEM_CALLS;