From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b86e9e055dc72fc8 X-Google-Attributes: gid103376,public From: gaffney@ewirb-wr (GAFFNEY.BRIAN) Subject: Re: *Direct* input from keyboard Date: 1996/05/01 Message-ID: <1MAY199613515750@ewirb-wr>#1/1 X-Deja-AN: 152482082 distribution: world references: <1996Apr29.174806.14478@relay.nswc.navy.mil> news-software: VAX/VMS VNEWS 1.41 organization: Robins AFB - LNEW newsgroups: comp.lang.ada Date: 1996-05-01T00:00:00+00:00 List-Id: 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 . 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