comp.lang.ada
 help / color / mirror / Atom feed
* *Direct* input from keyboard
@ 1996-04-29  0:00 S Kuiper (NSWCDD)
  1996-04-30  0:00 ` Richard A. O'Keefe
  1996-05-01  0:00 ` GAFFNEY.BRIAN
  0 siblings, 2 replies; 3+ messages in thread
From: S Kuiper (NSWCDD) @ 1996-04-29  0:00 UTC (permalink / raw)



Hopefully someone has already done this successfully.  I'm trying to take input
directly from the keyboard as a control device.  It won't help me to do a 'Get'
and wait for a <CR>.  I would like to be able to "sense" when arrow keys or certain
letters are depressed and take action accordingly.

I assume I will have to open the keyboard as a device (ie /dev/kbd) and then
do a "Get".  But does anyone know what the return value of the arrow keys on a 
keyboard are?  there is no reference to them in the Standard Package.

Thanx in advance for any help

-- 
Steve Kuiper         
skuiper@nswc.navy.mil





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

* Re: *Direct* input from keyboard
  1996-04-29  0:00 *Direct* input from keyboard S Kuiper (NSWCDD)
@ 1996-04-30  0:00 ` Richard A. O'Keefe
  1996-05-01  0:00 ` GAFFNEY.BRIAN
  1 sibling, 0 replies; 3+ messages in thread
From: Richard A. O'Keefe @ 1996-04-30  0:00 UTC (permalink / raw)



skuiper@nswc.navy.mil (S Kuiper (NSWCDD)) writes:
...
>I'm trying to take input
>directly from the keyboard as a control device.
...
>I would like to be able to "sense" when arrow keys or certain
>letters are depressed and take action accordingly.

>I assume I will have to open the keyboard as a device (ie /dev/kbd) and then
>do a "Get".  But does anyone know what the return value of the arrow keys on a 
>keyboard are?  there is no reference to them in the Standard Package.

There is no fixed set of function keys for keyboards.
My Atari ST, Mac, Sun-3/50 and an IBM PC all have different sets.
There isn't anything in the Fortran, Pascal, C, Modula-2 (is that finished
yet?), C++ (is _that_ finished yet?), PL/I, Ada 83, or Ada 95 standards
that requires or assumes the _existence_ of a keyboard.

Since you mention /dev/kbd, I presume you are using a UNIX system.
In that case, your best bet by a long way is simply to

	- use the UNIX "curses" library (comes standard with UNIX)
	- write a small amount of "glue" code in C
	- use Ada.Interfaces.C to call it from your Ada code.

Given an Ada 95 compiler the code should be pretty portable between current
UNIX systems.  The curses library will take care of mapping terminal-specific
codes to
	KEY_DOWN, KEY_UP, KEY_LEFT, KEY_RIGHT,
or lots of others.

It would be rather nice to have an Ada "thick binding" to Curses.  Now that
we have Ada.Interfaces.C, it should be quite portable between Ada 95
compilers.

-- 
Fifty years of programming language research, and we end up with C++ ???
Richard A. O'Keefe; http://www.cs.rmit.edu.au/~ok; RMIT Comp.Sci.




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

* Re: *Direct* input from keyboard
  1996-04-29  0:00 *Direct* input from keyboard S Kuiper (NSWCDD)
  1996-04-30  0:00 ` Richard A. O'Keefe
@ 1996-05-01  0:00 ` GAFFNEY.BRIAN
  1 sibling, 0 replies; 3+ messages in thread
From: GAFFNEY.BRIAN @ 1996-05-01  0:00 UTC (permalink / raw)



In article <1996Apr29.174806.14478@relay.nswc.navy.mil>, 
skuiper@nswc.navy.mil writes...
>Hopefully someone has already done this successfully.  I'm trying to take input
>directly from the keyboard as a control device.  It won't help me to do a 'Get'
>and wait for a <CR>.  I would like to be able to "sense" when arrow keys or certain
>letters are depressed and take action accordingly.
> 
>I assume I will have to open the keyboard as a device (ie /dev/kbd) and then
>do a "Get".  But does anyone know what the return value of the arrow keys on a 
>keyboard are?  there is no reference to them in the Standard Package.
> 
>Thanx in advance for any help
> 
>-- 
>Steve Kuiper         
>skuiper@nswc.navy.mil
> 

Assuming you're using a PC...
 and further assuming you're using GNAT..
  and further assuming you're using DOS/DJGPP (your reference to /dev/kbd 
  makes me a little suspicious :-)...
   (Since I just needed to do this same thing, I thought I'd post my solution
    even though it may not help you directly).

The easiest way I found to do this is to import the equivalent C function.
This it seems is what GNAT does, but it uses "getc" which at least on DOS 
is buffered.  I used the function "getxkey" (or getkey which treats both sets 
of arrows the same) which returns key codes rather than key values. 
All of the key codes are listed in "include\keys.h".  

package Keyboard is
  type Key_Type is (Up_Arrow,    Down_Arrow,    Right_Arrow,    Left_Arrow, 
                    Up_Arrow_Kp, Down_Arrow_Kp, Right_Arrow_Kp, Left_Arrow_Kp, 
                    Enter,       Space);
  procedure Input_Single_Key(Value : out Key_Type);
end Keyboard;


with Interfaces.C;
package body Keyboard is
  package C renames Interfaces.C;
  procedure Input_Single_Key(Value : out Key_Type) is
    KeyCode : C.int := 0;
    function GetKey return C.int;
    pragma Import(C,GetKey,"getxkey");
  begin
    KeyCode := GetKey;
    case KeyCode is
      when 328    => Value := Up_Arrow;
      when 336    => Value := Down_Arrow;
      when 333    => Value := Right_Arrow;
      when 331    => Value := Left_Arrow;
      when 584    => Value := Up_Arrow_Kp;
      when 592    => Value := Down_Arrow_Kp;
      when 587    => Value := Right_Arrow_Kp;
      when 589    => Value := Left_Arrow_Kp;
      when  13    => Value := Enter;
      when others => Value := Space;
    end case;
  end Input_Single_Key;
end Keyboard;
					--Bg




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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-04-29  0:00 *Direct* input from keyboard S Kuiper (NSWCDD)
1996-04-30  0:00 ` Richard A. O'Keefe
1996-05-01  0:00 ` GAFFNEY.BRIAN

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