/* MoveMouse.jl  By Kamran Karimi

   Should be linked with JustLook (© Kamran Karimi) routines.
*/

#include <stdlib.h>
#include <stdio.h>
#include <intuition/intuition.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/intuition_protos.h>

#include "JustLook.h"

struct IntuitionBase *IntuitionBase;

#define Write_err printf("err = %08lx\n",err)

main()
{
 struct Window *win1,*win2;
 ErrorCode err;
 struct ScrMap SM;
 int count;
 
 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
 if(IntuitionBase == 0) exit(100);

 win1 = FindWindow("Workbench",NULL);
 if(win1 > WIN_REPEATED) 
 {
  err = IEDisable(MOUSE|KBD); Write_err;
  printf("Mouse and Keyboard disabled!\n");
  Delay(50);
  InitSM(&SM,win1->WScreen);
  WindowToFront(win1);
  SetDest(&SM,(win1->WScreen)->LeftEdge,(win1->WScreen)->Height / 2);
  MoveMouse(&SM,ABSOLUTE,6);
  Click(&SM,LBUTTON,0,DOWN);
  SetDest(&SM,(win1->WScreen)->Width - 20,(win1->WScreen)->Height - 10);
  MoveMouse(&SM,ABSOLUTE,2);
  Delay(100);
  Click(&SM,LBUTTON,0,UP);
  err = IEEnable(MOUSE|KBD); Write_err;
  printf("Mouse and Keyboard enabled!\n");
 }
 else printf("Trouble finding Workbench window!\n");
 win2 = FindWindow("AmigaShell",NULL);
 if(win2 > WIN_REPEATED)
 {
  WindowToFront(win2);
  Printf("Try to stop me!\n");
  Delay(75);
  InitSM(&SM,win2->WScreen);
  for(count = 1;count < 3; count++)
  {
   SetDest(&SM,0,0);
   MoveMouse(&SM,ABSOLUTE,8);
   SetDest(&SM,(win2->WScreen)->Width - 10,(win2->WScreen)->Height -10);
   MoveMouse(&SM,ABSOLUTE,4);
   SetDest(&SM,(win2->WScreen)->Width - 10,0);
   MoveMouse(&SM,ABSOLUTE,1);
   SetDest(&SM,0,(win2->WScreen)->Height -10);
   MoveMouse(&SM,ABSOLUTE,1);
  }
  printf("That was all!\n");
 }
 else
 {
  if(win2 == WIN_REPEATED) printf("More than 1 AmigaShell window found!\n");
  else printf("AmigaShell window not found!\n");
  printf("Aborted...\n");
 }
 CloseLibrary((struct Library *)IntuitionBase);
 exit(0);
}
