uses dvcrt, dvwin, dvmacro, dvexec, winprocs, wintypes, strings;

var retorno: longint;
    minhaJan, janProg: hWnd;
    s: string;
    c: char;

const
   DIREITA  = #77;
   ESQUERDA = #75;
   BAIXO    = #80;
   CIMA     = #72;

   HOME     = #71;


{-------------------------------------------------------------------------}
procedure sendKey (c: char);          {  procedure que tecla no programa  }
{-------------------------------------------------------------------------}
begin
   playInit (30);
   playKey (c, 1);
   playStart;
   repeat keypressed until not playIsActive;
end;

procedure marca;
var dados: array [0..80] of char;
    seta: char;
    tam,i, pos : integer;

begin
    tam := 0;
    pos := 0;

    setActiveWindow (janProg);
    repeat keypressed until getActiveWindow = janProg;

    PlayInit (300);
    playVirtKey (ord ('E'), false, false, true, 100);
    PlayStart;
    while playIsActive do;
    readkey;

    PlayInit (300);
    playVirtKey (ord ('i'), false, false, false, 100);
    PlayStart;
    while playIsActive do;

    PlayInit (300);
    playVirtKey (ord ('y'), false, false, false, 100);
    PlayStart;
    while playIsActive do;

    PlayInit (300);
    playVirtKey (ord ('i'), false, false, true, 100);
    PlayStart;
    while playIsActive do;

    setActiveWindow (minhajan);
    repeat keypressed until getActiveWindow = minhajan;

    repeat

       seta := SintReadkey;

       if seta  = #$0 then
          seta := Readkey;

       if seta = DIREITA then
          begin
             dados [pos] := seta;
             pos := pos + 1;
             tam := tam + 1;
          end
       else if (seta = ESQUERDA) and (tam > 0) then
          begin
             dados [pos] := seta;
             pos := pos + 1;
             tam := tam - 1;
          end
       else if seta = #27 then
          begin
             setActiveWindow (janProg);
             repeat keypressed until getActiveWindow = janProg;

             PlayInit (300);
             playVirtKey (VK_HOME, false, false, false, 100);
             PlayStart;
             while playIsActive do;

             setActiveWindow (minhaJan);
             repeat keypressed until getActiveWindow = minhaJan;

          end;

   until (seta = #13) or (seta = #27);

   if seta = #13 then
      begin
         i := 0;

         setActiveWindow (janProg);
         repeat keypressed until getActiveWindow = janProg;

         PlayInit (1000);
         playVirtKey (ord ('e'), false, false, true, 100);
         PlayStart;
         while playIsActive do;

         PlayInit (300);
         playVirtKey (ord ('i'), false, false, false, 100);
         PlayStart;
         while playIsActive do;


         PlayInit (300);
         playVirtKey (ord ('r'), false, false, true, 100);
         PlayStart;
         while playIsActive do;

         sendKey (#13);

         while (dados [i] <> #0) or (i <= 30) do
            begin
               if dados [i] = DIREITA then
                  begin

                     PlayInit (300);
                     playVirtKey (VK_RIGHT, false, true, false, 100);
                     PlayStart;
                     while playIsActive do;

                  end
               else if dados [i] = ESQUERDA then
                  begin

                     PlayInit (300);
                     playVirtKey (VK_LEFT, false, true, false, 100);
                     PlayStart;
                     while playIsActive do;

                  end;
            end;

         PlayInit (300);
         playVirtKey (ord ('e'), false, false, true, 100);
         PlayStart;
         while playIsActive do;

         PlayInit (300);
         playVirtKey (ord ('i'), false, false, false, 100);
         PlayStart;
         while playIsActive do;


         PlayInit (300);
         playVirtKey (ord ('e'), false, false, true, 100);
         PlayStart;
         while playIsActive do;

         sendKey (#13);

         setActiveWindow (minhajan);
         repeat keypressed until getActiveWindow = minhajan;

      end;

end;

begin
    sintInic (2, '');
    clrscr;
    minhaJan := getActiveWindow;

    if executaProg ('c:\geraldo\suporte\suporte.ll', '','') < 32 then
        begin
            writeln ('Não executei');
            delay (1000);
            doneWinCrt;
        end;

    repeat keypressed until getActiveWindow <> minhaJan;
    janProg := getActiveWindow;

    repeat
        setActiveWindow (minhaJan);
        repeat keypressed until getActiveWindow = minhaJan;

        c := sintReadkey;
        if c = '=' then
            marca
        else
            begin
                sintCarac (c);

                setActiveWindow (janProg);
                repeat keypressed until getActiveWindow = janProg;

                keyboardClick (c);
            end;
    until c = ESC;
            {
    setActiveWindow (janProg);
    repeat keypressed until getActiveWindow = janProg;

    PlayInit (300);
    playVirtKey (VK_F4, false, false, true, 100);
    PlayStart;
    while playIsActive do;
                }
    sintFim;
    doneWinCrt;
end.

    function PlayInit (nMsg: integer): boolean;  far;
    function PlayStart: boolean; far;
    function PlayIsActive: boolean; far;
    procedure playKey (key: char; delay: longint); far;
    procedure playAltKey (key: char; delay: longint);  far;
    procedure playVirtKey (key: byte; comCtl, comShift, comAlt: boolean; delay: longint); far;
    procedure playString (s: string; delay: longint); far;
    procedure playInsertKeyEvent (command: word; key: word;  delay: longint); far;
    procedure playMouse (command, x, y: word; delay: longint);  far;

    procedure keyboardClick (letra: char);
    procedure keyboardAlt (letra: char);
    procedure mouseClick (x, y: integer);
