home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_PAS / XLIB_TP5.ZIP / UNITS / X_KEYS.PAS < prev    next >
Pascal/Delphi Source File  |  1993-11-22  |  3KB  |  125 lines

  1. unit X_Keys;
  2.  
  3. (*
  4.     Procedures to manipulate keybuffer (emulation)
  5.  
  6.     ****** XLIB - Mode X graphics library                ****************
  7.     ******                                               ****************
  8.     ****** Written By Christian Harms in TP              ****************
  9.  
  10.     Harms   : harms@minnie.informatik.uni-stuttgart.de
  11.  
  12.     documentation in german and english
  13. *)
  14.  
  15. interface
  16.  
  17. uses crt;
  18.  
  19. const NULL      = #0 ;
  20.       BackSpace = #8 ;
  21.       Back      = #8 ;
  22.       TAB       = #9 ;
  23.       Enter     = #13;
  24.       Return    = #13;
  25.       ESC       = #27;
  26.       Space     = #32;
  27. (* vor alle nächsten Codes kommt immer ein "NULL"-Zeichen ( #0 ) !        *)
  28. (* The next key-Codes are first a chr(0), following the code !            *)
  29.       Shift_TAB = #15;
  30.       F1        = ';';
  31.       F2        = '<';
  32.       F3        = '=';
  33.       F4        = '>';
  34.       F5        = '?';
  35.       F6        = '@';
  36.       F7        = 'A';
  37.       F8        = 'B';
  38.       F9        = 'C';
  39.       F10       = 'D';
  40.       links     = 'K';       left   = links;
  41.       rechts    = 'M';       right  = rechts;
  42.       runter    = 'P';       down   = runter;
  43.       hoch      = 'H';       up     = hoch;
  44.       Ende      = 'O';
  45.       Home      = 'G';
  46.       PgUp      = 'I';
  47.       PgDown    = 'Q';
  48.       Ins       = 'R';
  49.       Del       = 'S';
  50.  
  51.  
  52. (* Liest Tasten ein und übergibt diese.                                     *)
  53. (* Get a character, if pressed or in Buffer.                                *)
  54. function ReadKeys:Char;
  55.  
  56. (* Gibt true zurück, wenn Readkeys einen Wert bereit hält.                  *)
  57. (* true, if key pressed or key from Set_Key_Makro in Buffer (see keypressed)*)
  58. function keysPressed:Boolean;
  59.  
  60. (* Wartet so lange, bis die entsprechende Taste gedückt wurde .             *)
  61. (* Wait, until key a is pressed.                                            *)
  62. procedure Wait_Key(A:Char);
  63.  
  64. (* Simuliert Tastenbetätigung (in der Reihenfolge des Strings)              *)
  65. (* Emutaled key-pressing                                                    *)
  66. procedure Set_Key_Makro(S:String);
  67.  
  68. (* Clear the Set_Key_Makro-Buffer .                                         *)
  69. procedure Clear_Buffer;
  70.  
  71.  
  72.  
  73. implementation
  74.  
  75. var
  76.     TastenBuffer : Array[1..256] of Char;
  77.     Keys_Pointer : Byte;
  78.  
  79. function ReadKeys:Char;
  80. var a:Char;
  81. begin;
  82.   if Keys_Pointer>0 then begin;
  83.                            a:=TastenBuffer[Keys_Pointer];
  84.                            Dec(Keys_Pointer);
  85.                          end
  86.                     else begin;
  87.                            a:=ReadKey;
  88.                          end;
  89.   ReadKeys:=a;
  90. end;
  91.  
  92. function KeysPressed:Boolean;
  93. begin;
  94.   KeysPressed:=KeyPressed or (Keys_Pointer>0);
  95. end;
  96.  
  97. procedure Wait_Key(A:Char);
  98. begin;
  99.   repeat;
  100.   until ReadKeys=a;
  101. end;
  102.  
  103. procedure Set_Key_Makro(S:String);
  104. var i:Byte;
  105. begin;
  106.   if  ord(s[0])+Keys_Pointer>255 then s[0]:=chr(255-Keys_Pointer);
  107.  
  108.   for i:=ord(s[0]) downto 1 do TastenBuffer[i+Keys_Pointer]:=s[ord(s[0])-i+1];
  109.  
  110.   Keys_Pointer:=Keys_Pointer+ord(s[0]);
  111. end;
  112.  
  113. procedure Clear_Buffer;
  114. var a:Char;
  115. begin;
  116.   while keyspressed do a:=ReadKeys;
  117. end;
  118.  
  119. begin;
  120.   Keys_Pointer:=0;
  121. end.
  122.  
  123.  
  124.  
  125.