comp.lang.ada
 help / color / mirror / Atom feed
* Getting a single key stroke
@ 1996-05-04  0:00 James Eder
  1996-05-05  0:00 ` John Herro
  0 siblings, 1 reply; 4+ messages in thread
From: James Eder @ 1996-05-04  0:00 UTC (permalink / raw)





Simple question with an expected complex answer.

  How do you, in ada, get a single keystroke such as an arrow key from the
user?  Oh, and it must be a somewhat portable method.  I'm writing the program
for an open VMS system with an Ada 83 compiler.  I'd like to do this with just
Ada, but I'm also open to the possibility of importing a proc/funct from C or
something.  Keep in mind in your response that this program is being written
for use over a terminal with vt300 emulation so forget about anything too
sneaky.

Tanks (h intentionally left blank)

- James
        ////
       (o o)     <----- Me!
---oOO--(_)--OOo----------------------------------------------------------------
                   I think therfore I am - Decartes
   .oooO  Oooo.    The computer IS therefore IT THINKS - James Eder
---(   )--(   )-----------------------------------------------------------------
    \ (    ) /                                    GJE9947@MSU.OSCS.MONTANA.EDU
     \_)  (_/                                    ICSAD110@MSU.OSCS.MONTANA.EDU




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Getting a single key stroke
  1996-05-04  0:00 Getting a single key stroke James Eder
@ 1996-05-05  0:00 ` John Herro
  1996-05-05  0:00   ` Robert Dewar
  0 siblings, 1 reply; 4+ messages in thread
From: John Herro @ 1996-05-05  0:00 UTC (permalink / raw)



gje9947@msu.oscs.montana.edu (James Eder) writes:
> How do you, in Ada, get a single keystroke
> such as an arrow key from the user?  Oh,
> and it must be a somewhat portable method.
> I'm writing the program for an open VMS
> system with an Ada 83 compiler.
     I don't think it's possible to get a single keystroke in a "somewhat
portable" manner in Ada 83.  Even in Ada 95, which has a "portable"
routine to do that, there are no guarantees that the routine will work on
all systems!
     Here's how I did it in VAX Ada [83] for VMS in my Ada Tutor program. 
Unfortunately, this isn't portable.  Sorry, it's as close as I can come to
what you want:

package Custom_IO is
   ...
   procedure Get(Char : out Character);
   ...
end Custom_IO;

with Starlet, System; use Starlet, System;
package body Custom_IO is
   Chan : Starlet.Channel_Type;
   IOSB : System.Unsigned_Quadword;
   Stat : System.Unsigned_Longword;
   procedure QIOW(
        Stat   :    out Unsigned_Longword;
        EFN    : in     Integer;
        Chan   : in     Channel_Type;
        Func   : in     Short_Integer;
        IOSB   :    out Unsigned_Quadword;
        ASTadr : in     Integer;
        ASTPRM : in     Integer;
        P1     : in out String;
        P2, P3 : in     Integer;
        P4     : in     Unsigned_Quadword;
        P5, P6 : in     Integer);
   pragma Interface(System_Library, QIOW);
   pragma Import_Valued_Procedure(
        Internal        => QIOW,
        External        => "SYS$QIOW",
        Parameter_Types => (
             Unsigned_Longword,
             Integer,
             Channel_Type,
             Short_Integer,
             Unsigned_Quadword,
             Integer,
             Integer,
             String,
             Integer,
             Integer,
             Unsigned_Quadword,
             Integer,
             Integer),
        Mechanism       => (
             Value,
             Value,
             Value,
             Value,
             Reference,
             Value,
             Reference,
             Reference,
             Value,
             Reference,
             Reference,
             Reference,
             Reference));

   procedure Get(Char : out Character) is
      S : String(1 .. 1);
   begin
      QIOW(Stat, 0, Chan, 16#7A#, IOSB,
           0, 0, S, 1, 0, (0,0), 0, 0);
      Char := S(1);
   end Get;
   ...
end Custom_IO;

     It appears that, for the portion of the package that I posted, the
"use Starlet, System;" clause may be unnecessary.  However, I no longer
have access to VMS to test this.
     I hope that this helps, or at least that it's better than nothing.
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Getting a single key stroke
  1996-05-05  0:00 ` John Herro
@ 1996-05-05  0:00   ` Robert Dewar
  1996-05-06  0:00     ` David Emery
  0 siblings, 1 reply; 4+ messages in thread
From: Robert Dewar @ 1996-05-05  0:00 UTC (permalink / raw)




Joh Herro said

"     I don't think it's possible to get a single keystroke in a "somewhat
portable" manner in Ada 83.  Even in Ada 95, which has a "portable"
routine to do that, there are no guarantees that the routine will work on
all systems!"

Well there are no guarantees because there are sysmtes on which getting
a single keystroke is impossible or is a meaningless concept, but you
can assume that all Ada 95 compilers will support this in appropriate
environments. During its development, some versions of GNAT did not
support this (indeed some versions of GNAT did not, and some still do
not) support tasking, but as the technology develops, and implementations
mature, I think you will be able to count on Get_Immediate as solidly
as you can count on any other feature of the language.






^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Getting a single key stroke
  1996-05-05  0:00   ` Robert Dewar
@ 1996-05-06  0:00     ` David Emery
  0 siblings, 0 replies; 4+ messages in thread
From: David Emery @ 1996-05-06  0:00 UTC (permalink / raw)



In article <dewar.831339829@schonberg>, dewar@cs.nyu.edu (Robert Dewar) wrote:

> Joh Herro said
> 
> "     I don't think it's possible to get a single keystroke in a "somewhat
> portable" manner in Ada 83.  Even in Ada 95, which has a "portable"
> routine to do that, there are no guarantees that the routine will work on
> all systems!"
> 
> Well there are no guarantees because there are sysmtes on which getting
> a single keystroke is impossible or is a meaningless concept, but you
> can assume that all Ada 95 compilers will support this in appropriate
> environments. During its development, some versions of GNAT did not
> support this (indeed some versions of GNAT did not, and some still do
> not) support tasking, but as the technology develops, and implementations
> mature, I think you will be able to count on Get_Immediate as solidly
> as you can count on any other feature of the language.

There's a 'portable' solution for (Ada83) POSIX-compliant systems in the FAQ
on the HBAPP web site.

            dave




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1996-05-06  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-04  0:00 Getting a single key stroke James Eder
1996-05-05  0:00 ` John Herro
1996-05-05  0:00   ` Robert Dewar
1996-05-06  0:00     ` David Emery

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox