home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 16 / 16.iso / w / w048 / 2.ddi / MSSRC.ARC / MSKEYBRD.INC < prev    next >
Encoding:
Text File  |  1987-12-21  |  5.0 KB  |  163 lines

  1. {                           MSKEYBRD.INC
  2.                                MS 4.0
  3.                 Copyright (c) 1985, 87 by Borland International, Inc.         }
  4.  
  5. type
  6.   CircularBuffer = array[0..DefTypeahead] of Char;
  7.  
  8. var
  9.   Circbuf : CircularBuffer;  {Our keyboard buffer}
  10.   Circin : Integer;          {Pointer to put data into CircBuf}
  11.   Circout : Integer;         {Pointer to take data out of CircBuf}
  12.   AskforInsertflag : Boolean; {Insert mode state in prompt boxes}
  13.  
  14.   function EdGetInput : Char;
  15.     {-Read next character from typeahead buffer}
  16.  
  17.   begin                      {EdGetinput}
  18.     if EditUsercommandInput > 0 then
  19.       Dec(EditUsercommandInput);
  20.     EdGetInput := Circbuf[Circout];
  21.     Circout := Succ(Circout) mod DefTypeahead;
  22.   end;                       {EdGetinput}
  23.  
  24.   function EdKeyPressed : Boolean;
  25.     {-Determine if input is available}
  26.   var
  27.     Counter : Integer;
  28.     Ch : Char;
  29.  
  30.     procedure EdAbort;
  31.       {-Abort command and delete typeahead buffer's contents}
  32.  
  33.     begin                    {EdAbort}
  34.       if not(Aborting) then begin
  35.         Aborting := True;
  36.         Abortcmd := False;
  37.         EdErrormsg(37);
  38.         Abortcmd := True;
  39.         Aborting := False;
  40.       end;
  41.     end;                     {EdAbort}
  42.  
  43.   begin                      {EdKeypressed}
  44.  
  45.     {Transfer keystrokes from BIOS to our keyboard buffer}
  46.     Counter := 0;
  47.     while (Counter < 6) and (Succ(Circin) mod DefTypeahead <> Circout) and KeyPressed do begin
  48.       Inc(Counter);
  49.       Ch := ReadKey;
  50.       if (Ch = AbortChar) and (AbortEnable or (EditUsercommandInput <> 0)) then
  51.         EdAbort
  52.       else begin
  53.         Circbuf[Circin] := Ch;
  54.         Circin := Succ(Circin) mod DefTypeahead;
  55.         if Recording then
  56.           {Macro recording on - add to scrap macro}
  57.           if Length(Macrokeys[0]) < (MaxMacroLength-2) then
  58.             Macrokeys[0] := Macrokeys[0]+Ch
  59.           else begin
  60.             {Scrap macro string full, turn off recording}
  61.             Recording := False;
  62.             Macrokeys[0] := Macrokeys[0]+TogglePrime;
  63.           end;
  64.       end;
  65.     end;
  66.  
  67.     EdKeyPressed := (Circin <> Circout);
  68.   end;                       {EdKeypressed}
  69.  
  70.   function EdKeyInterrupt : Boolean;
  71.     {-Determine whether to interrupt background process}
  72.  
  73.   begin                      {EdKeyInterrupt}
  74.     if (Intrflag <> Interr) then
  75.       EdKeyInterrupt := False
  76.     else if (Circin <> Circout) then
  77.       EdKeyInterrupt := True
  78.     else
  79.       EdKeyInterrupt := EdKeyPressed;
  80.   end;                       {EdKeyInterrupt}
  81.  
  82.   procedure EdBreathe;
  83.     {-Enable keyboard buffering without returning a character}
  84.   var
  85.     B : Boolean;
  86.  
  87.   begin                      {EdBreathe}
  88.     B := EdKeyPressed;
  89.   end;                       {EdBreathe}
  90.  
  91.   procedure EdUserPush(S : String255);
  92.     {-Push string onto typeahead buffer}
  93.   var
  94.     I : Integer;
  95.  
  96.     procedure EdPushTypeahead(Ch : Char);
  97.       {-Push character onto front of typeahead buffer}
  98.  
  99.     begin                    {EdPushTypeahead}
  100.       if Succ(Circin) mod DefTypeahead = Circout then
  101.         EdErrormsg(21)
  102.       else begin
  103.         Circout := Pred(Circout+DefTypeahead) mod DefTypeahead;
  104.         Circbuf[Circout] := Ch;
  105.       end
  106.     end;                     {EdPushTypeahead}
  107.  
  108.   begin                      {EdUserpush}
  109.     for I := Length(S) downto 1 do
  110.       EdPushTypeahead(S[I]);
  111.     EditUsercommandInput := EditUsercommandInput+Length(S);
  112.   end;                       {EdUserpush}
  113.  
  114.   procedure EdClearBuffer;
  115.     {-Clear keyboard buffer}
  116.  
  117.   begin                      {EdClearBuffer}
  118.     Circin := Circout;
  119.     EditUsercommandInput := 0;
  120.   end;                       {EdClearBuffer}
  121.  
  122.   procedure EdWaitforKey;
  123.     {-Tight loop waiting for keystroke}
  124.  
  125.   begin                      {EdWaitforKey}
  126.     repeat
  127.       if Printing then
  128.         EdPrintNext(PrintChars);
  129.     until Abortcmd or EdKeyPressed;
  130.   end;                       {EdWaitforKey}
  131.  
  132.   function EdGetAnyChar : Char;
  133.     {-Wait for and return a character from internal keyboard buffer}
  134.  
  135.   begin                      {EdGetAnyChar}
  136.     EdWaitforKey;
  137.     if not(Abortcmd) then
  138.       EdGetAnyChar := EdGetInput;
  139.     {Be sure to check Abortcmd before relying on the results of this function}
  140.   end;                       {EdGetAnyChar}
  141.  
  142.   function EdGetCursorCommand(CmdSet : Charset) : Char;
  143.     {-Return a legal cursor command, WordStar style}
  144.   const
  145.     WScommands : string[12] = ^@^B^C^R^T^D^E^N^S^X^Y^J;
  146.     EXcommands : string[11] = 'OQIGMHRKPS;';
  147.   var
  148.     Ch : Char;
  149.  
  150.   begin                      {EdGetCursorCommand}
  151.     repeat
  152.       Ch := Upcase(EdGetAnyChar);
  153.       if Abortcmd then
  154.         Exit;
  155.       if not(Abortcmd) and (Ch = Null) then
  156.         {Get extended character}
  157.         {Convert IBM keypad to equivalent control char}
  158.         Ch := WScommands[Succ(Pos(EdGetAnyChar, EXcommands))];
  159.     until Abortcmd or (Ch in CmdSet);
  160.     EdGetCursorCommand := Ch;
  161.   end;                       {EdGetCursorCommand}
  162.  
  163.