home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / comm.swg / 0003_Chat.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-05-28  |  5.3 KB  |  184 lines

  1. {
  2. > Otherwise, how could I tell the difference between the local users input
  3. > and the remote users input??? If I knew that I guess I could Write my
  4. > own chat Procedure.
  5.  
  6. Well, I definately agree With you there.. Here's some ugly code
  7. I put into my doors, it's a chat Procedure, not With all the features I'd like,
  8. but it works, anyway..  (BTW, I'm working on a split screen version now, but
  9. that'll take some time as I'm very busy these days..)  This is a dump from part
  10. of my SYSKEY.INC include File..
  11. }
  12.  
  13. {$F+}
  14.  
  15. (* This include File is where you will take actions you define when trapped
  16.    keys such as ALT-keys, Function-keys, etc., are pressed.
  17.  
  18.    You will need to setup your Procedures here which in turn may call other
  19.    Procedures within your code or you may do all you need to do right here.
  20.  
  21.    For example, if you wanted to trap For ALT-C being pressed on the local
  22.    keyboard and then call the Procedure CHAT:
  23.  
  24.    Your main block of code might look like this:
  25.  
  26.    begin  {main}
  27.       ASSIGN(Output,'') ;
  28.       REWrite(Output) ;
  29.       SysopKey[1] := #0 + #46 ;   {define ALT-C as one of twenty keys }
  30.                                   {to trap                            }
  31.       SysopProc[1] := ALT_C ;     {define Procedure as defined here   }
  32.       SysopKey ;                  {setup For Far call to this File    }
  33.    end ;
  34.  
  35.    Now, whenever ALT-C is pressed, the following Procedure will be called:
  36.  
  37.    Procedure ALT_C ;
  38.    begin
  39.       CHAT ;                      {call Procedure CHAT which is located }
  40.    end ;                          {within your Program's code           }
  41.  
  42.    *)
  43.  
  44. (*
  45.    The following Procedures are called when up/down arrows are pressed
  46.    provided they are defined using SysopKey[] and SysopProc[] within
  47.    the main Program code
  48. *)
  49.  
  50. Procedure end_Chat;
  51.  
  52. begin
  53.   Chatended := True;
  54.   { Do some other stuff here if you'd like }
  55. end;
  56.  
  57. Procedure Chat;
  58.  
  59. Const
  60.   FKeyCode          = #0;
  61.   Space             = ' ';
  62.   Hyphen            = '-';
  63.   BackSpace         = ^H;
  64.   CarriageReturn    = ^M;
  65.   MaxWordLineLength = 80;
  66.  
  67. Var
  68.   WordLine  : String[MaxWordLineLength];
  69.   Index1    : Byte;
  70.   Index2    : Byte;
  71.   InputChar : Char;
  72.   F         : Text;
  73.  
  74. Label Get_Char;
  75.  
  76. begin {WordWrap}
  77.   If LocalKey Then
  78.     SetColor(0,14,0)
  79.   Else
  80.     SetColor(0,3,0);
  81.   UserKeysOn := False;
  82.   WordLine  := '';
  83.   Index1    := 0;
  84.   Index2    := 0;
  85.   InputChar := Space;
  86.   ClearScreen;
  87.   Display(0,3,0,'');
  88.   Display(0,12,0,'Sysop Entering Chat Mode: ');
  89.   InputChar := GetChar;
  90.   If LocalKey Then
  91.     SetColor(0,14,0)
  92.   Else
  93.     SetColor(0,3,0);
  94.   InactiveVal := 0;
  95.  
  96.   While  (NOT Chatended)
  97.   do begin
  98.     If LocalKey Then
  99.       SetColor(0,14,0)
  100.     Else
  101.       SetColor(0,3,0);
  102.     Case InputChar OF
  103.       BackSpace: {Write destructive backspace & remove Char from WordLine}
  104.         begin
  105.           If LocalKey Then
  106.             SetColor(0,14,0)
  107.           Else
  108.             SetColor(0,3,0);
  109.           sDisplay(0,7,0,BackSpace+Space+BackSpace);
  110.           DELETE(WordLine,(LENGTH(WordLine) - 1),1)
  111.         end
  112.       else {InputChar contains a valid Char, so deal With it}
  113.       begin
  114.         If ( InPutChar = Chr(13) ) Then
  115.         begin
  116.           If LocalKey Then
  117.             Display(0,14,0,InputChar)
  118.           Else
  119.             Display(0,3,0,InputChar);
  120.         end
  121.         Else
  122.         begin
  123.           If LocalKey Then
  124.             sDisplay(0,14,0,InputChar)
  125.           Else
  126.             sDisplay(0,3,0,InputChar);
  127.         end;
  128.         If InputChar <> Chr(13) Then
  129.           WordLine := (WordLine + InputChar)
  130.         Else
  131.           WordLine := '';
  132.         if (LENGTH(WordLine) >= (MaxWordLineLength - 1)) then {we have to do a Word-wrap}
  133.         begin
  134.           Index1 := (MaxWordLineLength - 1);
  135.           While ((WordLine[Index1] <> Space) and (WordLine[Index1] <> Hyphen) and (Index1 <> 0)) DO
  136.             Index1 := (Index1 - 1);
  137.           if (Index1 = 0) {whoah, no space was found to split line!} then
  138.             Index1 := (MaxWordLineLength - 1); {forces split}
  139.           DELETE(WordLine, 1, Index1);
  140.           For Index2 := 1 to LENGTH(WordLine) DO
  141.             sDisplay(0, 7, 0, BackSpace + Space + BackSpace);
  142.           Display(0,3,0,'');
  143.           If InPutChar = Chr(13) then
  144.           begin
  145.             If LocalKey Then
  146.               Display(0,14,0,WordLine)
  147.             Else
  148.               Display(0,3,0,WordLine);
  149.           end
  150.           Else
  151.           begin
  152.             If LocalKey Then
  153.               sDisplay(0,14,0,WordLine)
  154.             Else
  155.               sDisplay(0,3,0,WordLine);
  156.           end;
  157.         end
  158.       end
  159.     end; {CASE InputChar}
  160.     {Get next key from user.}
  161.     Get_Char:
  162.     begin
  163.      InputChar := GetChar;
  164.      If ( WordLine = '' ) and ( InputChar = Chr(13) ) Then
  165.       begin
  166.        Display(0,3,0,'');
  167.        Goto Get_Char;
  168.       end;
  169.     end;
  170.   end; {WHILE ( not (Chatended) )}
  171.   Display(0, 12, 0, 'Sysop Left Chat Mode.');
  172.   If (NOT Registered) Then
  173.   DisplayLoc(0, 7, 0, '■ If you find this Program of value, please register.');
  174.   Delay(2500);
  175.   Display(0, 15, 0, 'Press ( '+#17+'──┘ ) to Continue . . .');
  176.   ClearScreen;
  177.   Chatended := False;
  178.   InactiveVal := 30;
  179.   UserKeysOn := True;
  180. end;
  181. {
  182. There.. let me know if you need any clarification..  (BTW, you need global
  183. Variables Chatended and Registered as Booleans in the main program..
  184. }