home *** CD-ROM | disk | FTP | other *** search
- { MSKEYBRD.INC
- MS 4.0
- Copyright (c) 1985, 87 by Borland International, Inc. }
-
- type
- CircularBuffer = array[0..DefTypeahead] of Char;
-
- var
- Circbuf : CircularBuffer; {Our keyboard buffer}
- Circin : Integer; {Pointer to put data into CircBuf}
- Circout : Integer; {Pointer to take data out of CircBuf}
- AskforInsertflag : Boolean; {Insert mode state in prompt boxes}
-
- function EdGetInput : Char;
- {-Read next character from typeahead buffer}
-
- begin {EdGetinput}
- if EditUsercommandInput > 0 then
- Dec(EditUsercommandInput);
- EdGetInput := Circbuf[Circout];
- Circout := Succ(Circout) mod DefTypeahead;
- end; {EdGetinput}
-
- function EdKeyPressed : Boolean;
- {-Determine if input is available}
- var
- Counter : Integer;
- Ch : Char;
-
- procedure EdAbort;
- {-Abort command and delete typeahead buffer's contents}
-
- begin {EdAbort}
- if not(Aborting) then begin
- Aborting := True;
- Abortcmd := False;
- EdErrormsg(37);
- Abortcmd := True;
- Aborting := False;
- end;
- end; {EdAbort}
-
- begin {EdKeypressed}
-
- {Transfer keystrokes from BIOS to our keyboard buffer}
- Counter := 0;
- while (Counter < 6) and (Succ(Circin) mod DefTypeahead <> Circout) and KeyPressed do begin
- Inc(Counter);
- Ch := ReadKey;
- if (Ch = AbortChar) and (AbortEnable or (EditUsercommandInput <> 0)) then
- EdAbort
- else begin
- Circbuf[Circin] := Ch;
- Circin := Succ(Circin) mod DefTypeahead;
- if Recording then
- {Macro recording on - add to scrap macro}
- if Length(Macrokeys[0]) < (MaxMacroLength-2) then
- Macrokeys[0] := Macrokeys[0]+Ch
- else begin
- {Scrap macro string full, turn off recording}
- Recording := False;
- Macrokeys[0] := Macrokeys[0]+TogglePrime;
- end;
- end;
- end;
-
- EdKeyPressed := (Circin <> Circout);
- end; {EdKeypressed}
-
- function EdKeyInterrupt : Boolean;
- {-Determine whether to interrupt background process}
-
- begin {EdKeyInterrupt}
- if (Intrflag <> Interr) then
- EdKeyInterrupt := False
- else if (Circin <> Circout) then
- EdKeyInterrupt := True
- else
- EdKeyInterrupt := EdKeyPressed;
- end; {EdKeyInterrupt}
-
- procedure EdBreathe;
- {-Enable keyboard buffering without returning a character}
- var
- B : Boolean;
-
- begin {EdBreathe}
- B := EdKeyPressed;
- end; {EdBreathe}
-
- procedure EdUserPush(S : String255);
- {-Push string onto typeahead buffer}
- var
- I : Integer;
-
- procedure EdPushTypeahead(Ch : Char);
- {-Push character onto front of typeahead buffer}
-
- begin {EdPushTypeahead}
- if Succ(Circin) mod DefTypeahead = Circout then
- EdErrormsg(21)
- else begin
- Circout := Pred(Circout+DefTypeahead) mod DefTypeahead;
- Circbuf[Circout] := Ch;
- end
- end; {EdPushTypeahead}
-
- begin {EdUserpush}
- for I := Length(S) downto 1 do
- EdPushTypeahead(S[I]);
- EditUsercommandInput := EditUsercommandInput+Length(S);
- end; {EdUserpush}
-
- procedure EdClearBuffer;
- {-Clear keyboard buffer}
-
- begin {EdClearBuffer}
- Circin := Circout;
- EditUsercommandInput := 0;
- end; {EdClearBuffer}
-
- procedure EdWaitforKey;
- {-Tight loop waiting for keystroke}
-
- begin {EdWaitforKey}
- repeat
- if Printing then
- EdPrintNext(PrintChars);
- until Abortcmd or EdKeyPressed;
- end; {EdWaitforKey}
-
- function EdGetAnyChar : Char;
- {-Wait for and return a character from internal keyboard buffer}
-
- begin {EdGetAnyChar}
- EdWaitforKey;
- if not(Abortcmd) then
- EdGetAnyChar := EdGetInput;
- {Be sure to check Abortcmd before relying on the results of this function}
- end; {EdGetAnyChar}
-
- function EdGetCursorCommand(CmdSet : Charset) : Char;
- {-Return a legal cursor command, WordStar style}
- const
- WScommands : string[12] = ^@^B^C^R^T^D^E^N^S^X^Y^J;
- EXcommands : string[11] = 'OQIGMHRKPS;';
- var
- Ch : Char;
-
- begin {EdGetCursorCommand}
- repeat
- Ch := Upcase(EdGetAnyChar);
- if Abortcmd then
- Exit;
- if not(Abortcmd) and (Ch = Null) then
- {Get extended character}
- {Convert IBM keypad to equivalent control char}
- Ch := WScommands[Succ(Pos(EdGetAnyChar, EXcommands))];
- until Abortcmd or (Ch in CmdSet);
- EdGetCursorCommand := Ch;
- end; {EdGetCursorCommand}
-