!!! Help, Cursor Keys 
Author Message
 !!! Help, Cursor Keys

How, can I make  Turbo-Pascal 7.0 (DOS) make read cursor-key-inputs, or any
other keys, that have no ascii-code (Such like F1-F12, Enter, Alt,
Shift...)?
Please answer soon...




Wed, 18 Jun 1902 08:00:00 GMT  
 !!! Help, Cursor Keys
Kinda like this:

Uses Crt;
[...]
  Case ReadKey of
    #0:
      Case ReadKey of
        #72:WriteLn('Up');
        #75:WriteLn('Left');
        #77:WriteLn('Right');
        #80:WriteLn('Down');
      End;
    'a':WriteLn('Alpha');
    #13:WriteLn('Return');
  End;
[...]

As for alt, shift and control, have a look at int 16, func 2, or
mem[$40:$17]:

                         INT 16,2 - Read Keyboard Flags
        AH = 02

        on return:
        AL = BIOS keyboard flags (located in BIOS Data Area 40:17)
                |7|6|5|4|3|2|1|0|  AL or BIOS Data Area 40:17
                 | | | | | | | +---- right shift key depressed
                 | | | | | | +----- left shift key depressed
                 | | | | | +------ CTRL key depressed
                 | | | | +------- ALT key depressed
                 | | | +-------- scroll-lock is active
                 | | +--------- num-lock is active
                 | +---------- caps-lock is active
                 +----------- insert is active

/GreenGhost


Quote:
>How, can I make  Turbo-Pascal 7.0 (DOS) make read cursor-key-inputs, or any
>other keys, that have no ascii-code (Such like F1-F12, Enter, Alt,
>Shift...)?
>Please answer soon...





Wed, 18 Jun 1902 08:00:00 GMT  
 !!! Help, Cursor Keys

Quote:

>How, can I make  Turbo-Pascal 7.0 (DOS) make read cursor-key-inputs, or any
>other keys, that have no ascii-code (Such like F1-F12, Enter, Alt,
>Shift...)?

Enter has ascii code: 13. Alt and shift do not thing on themselves so
you cannot read then (without hooking the int 9 vector). F1-F10 etc.-
can be read by first checking if readkey returns zero and then calling
it again. F11-F12 cannot be read with crt.readkey. Here are replacements
for readkey and keypressed that work with them:

Unit F1112;

interface

var extended_kbd:boolean;  { Set to false if no extended support. }

function readkey:char;
function keypressed:boolean;

{* = extended }

Const F1=#59;    Shift_F1=#84;    Ctrl_F1=#94;    Alt_F1=#104;
      F2=#60;    Shift_F2=#85;    Ctrl_F2=#95;    Alt_F2=#105;
      F3=#61;    Shift_F3=#86;    Ctrl_F3=#96;    Alt_F3=#106;
      F4=#62;    Shift_F4=#87;    Ctrl_F4=#97;    Alt_F4=#107;
      F5=#63;    Shift_F5=#88;    Ctrl_F5=#98;    Alt_F5=#108;
      F6=#64;    Shift_F6=#89;    Ctrl_F6=#99;    Alt_F6=#109;
      F7=#65;    Shift_F7=#90;    Ctrl_F7=#100;   Alt_F7=#110;
      F8=#66;    Shift_F8=#91;    Ctrl_F8=#101;   Alt_F8=#111;
      F9=#67;    Shift_F9=#92;    Ctrl_F9=#102;   Alt_F9=#112;
      F10=#68;   Shift_F10=#93;   Ctrl_F10=#103;  Alt_F10=#113;
      F11=#133;  Shift_F11=#135;  Ctrl_F11=#137;  Alt_F11=#139;  {****}
      F12=#134;  Shift_F12=#136;  Ctrl_F12=#138;  Alt_F12=#140;  {****}

      Alt_1=#120;     Alt_2=#121;     Alt_3=#122;   Alt_4=#123;
      Alt_5=#124;     Alt_6=#125;     Alt_7=#126;   Alt_8=#127;
      Alt_9=#128;     Alt_0=#129;

      Alt_A=#30;      Alt_B=#48;      Alt_C=#46;     Alt_D=#32;
      Alt_E=#18;      Alt_F=#33;      Alt_G=#34;     Alt_H=#35;
      Alt_I=#23;      Alt_J=#36;      Alt_K=#37;     Alt_L=#38;
      Alt_M=#50;      Alt_N=#49;      Alt_O=#24;     Alt_P=#25;
      Alt_Q=#16;      Alt_R=#19;      Alt_S=#31;     Alt_T=#20;
      Alt_U=#22;      Alt_V=#47;      Alt_W=#17;     Alt_X=#45;
      Alt_Y=#21;      Alt_Z=#44;

      Shift_Tab=#15;
      Ctrl_tab=#148;  {*}
      Alt_tab=#165;   {*}

      Alt_Esc=#1;     {*}
      alt_BS=#14;     {*}

      Home=#71;
      Up=#72;
      PgUp=#73;
      Left=#75;
      Right=#77;
      End_=#79;    { Note the underscore as End is a reserved word }
      Down=#80;
      PgDn=#81;
      Ins=#82;
      Del=#83;

      Ctrl_PrtSc=#114;

      Ctrl_Left=#115;
      Ctrl_Right=#116;
      Ctrl_End=#117;
      Ctrl_PgDn=#118;
      Ctrl_Home=#119;
      Ctrl_PgUp=#132;

implementation

{$undef asm}

{$ifdef ver70} {$define asm} {$endif}
{$ifdef ver60} {$define asm} {$endif}

{$ifndef asm}
uses dos;
{$endif}

const scancode:char=#0;

{ This routine replaces crt.keypressed. It uses int 16h, ah=11h.
  if there is a scancode in buffer then it immediately returns true }

{$ifndef asm}
function keypressed:boolean;
var rg:registers;
begin
  if scancode>#0 then keypressed:=true
    else begin
           rg.ah:=ord(extended_kbd)*$10+1;
           intr($16,rg);
           keypressed:=rg.flags and fzero=0;
         End;
End;
{$else}

function keypressed:boolean; assembler;
         asm
         cmp scancode,0

         mov al,1
         ret

         mov cl,4
         shl ah,cl
         inc ah
         int 16h
         mov al,1


{$endif}

{ This routine replaces the crt.readkey. It uses int 16h. ah=10h.
  If there is a scancode in buffer it is immediately returned.

  They grey cursor keys report E0h as ASCII code instead of
  zero, so this has to be changed to zero. However, one must be
  careful as ASCII E0h (224d) can also be alpha as entered from
  keypad }

{$ifndef asm}
function readkey:char;
var rg:registers;
begin
  if scancode>#0 then begin
      readkey:=scancode;
      scancode:=#0;
      exit;
  End;
  rg.ah:=ord(extended_kbd)*$10;
  intr($16,rg);
  if (rg.al=$E0) and (rg.ah>70) then rg.al:=0;  { Grey cursor keys }
  readkey:=chr(rg.al);
  if rg.al=0 then scancode:=chr(rg.ah);
End;

{$else}

function readkey:char; assembler;
         asm
         mov al,scancode
         or al,al

         mov scancode,0
         ret

         mov cl,4
         shl ah,cl
         int 16h
         cmp al,0E0h

         cmp al,70

         xor al,al



{$endif}

var tmp:byte;
    tmp2:word;

function status:word;
         inline(
         $B8/$00/$12/      {MOV AX,1200h}
         $CD/$16           {INT 16h }
         );

{$ifdef msdos}
const seg0040=$40;
{$endif}

begin
  tmp:=mem[Seg0040:$17];
  extended_kbd:=false;
  if lo(status)=tmp then begin
     mem[Seg0040:$17]:=tmp xor 7;
     tmp2:=status;
     extended_kbd:=(tmp2<>$1200) and (lo(tmp2)=tmp xor 7);
     mem[Seg0040:$17]:=tmp;
  End;
end.

Osmo



Wed, 18 Jun 1902 08:00:00 GMT  
 !!! Help, Cursor Keys

Quote:

> How, can I make  Turbo-Pascal 7.0 (DOS) make read cursor-key-inputs, or any
> other keys, that have no ascii-code (Such like F1-F12, Enter, Alt,
> Shift...)?
> Please answer soon...



const  arle =#..                  {-there are a lot of ascii lists outside to
get this values-}
          arup =#..                 {- you can download a from program from me
to get the codes-}
          esc =#27;
{-http://141.39.192.188/~mz/MZHP/MZASC2.ARJ-}
          cr =#13;
          zero =#0;
          tab =#9;
          shifttab =#15;

var     c : char;

repeat   c:=readkey;
             if (c = zero) then begin  {-keys with two codes, 0+.. -}
                c:=readkey;
                case c of
                   shifttab:;
                   arle: ;
                   arup: ;
                   ...
                end;
             end else begin   {- key with one code -}
               case c of
                  esc: ;
                    cr: ;
                  tab: ;
                end;
             end;
until (c=esc);

Hope this help you.
M.Z.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Source Code For Using Function Keys or Cursor Keys - Help :)

2. Source Code For Using Function Keys or Cursor Keys - H

3. read cursor keys

4. Reading function/cursor keys

5. read cursor key

6. How to put cursor-keys in keyboard buffer??

7. How control Cursor-Keys with TPW 1.5 in a WinCRT-Window

8. How control Cursor-Keys with TPW 1.5 in a WinCRT-Window

9. Cursor Keys

10. How to get cursor key events ?

11. key release and key pressed help?

12. Help on Arrow Keys--Handy tool for all keys

 

 
Powered by phpBB® Forum Software