From: gaffney@ewirb-wr (GAFFNEY.BRIAN)
Subject: Re: *Direct* input from keyboard
Date: 1996/05/01
Date: 1996-05-01T00:00:00+00:00 [thread overview]
Message-ID: <1MAY199613515750@ewirb-wr> (raw)
In-Reply-To: 1996Apr29.174806.14478@relay.nswc.navy.mil
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
prev parent reply other threads:[~1996-05-01 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox