home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_USR08B.LHA / gerlib / examples / test / InsertEvent / InsertEvent.cc next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  22.2 KB  |  1,080 lines

  1.     /*
  2.      * C-Includes, C-Definitionen
  3.      *
  4.      */
  5.  
  6. #define class _class
  7. #define template _template
  8.  
  9. extern "C" {
  10. #include <exec/types.h>
  11. #include <exec/ports.h>
  12. #include <exec/memory.h>
  13. #include <exec/execbase.h>
  14.  
  15. #include <dos/dos.h>
  16. #include <dos/dosextens.h>
  17. #include <dos/exall.h>
  18. #include <dos/rdargs.h>
  19.  
  20. #include <clib/alib_protos.h>
  21. #include <clib/alib_stdio_protos.h>
  22.  
  23. #include <devices/input.h>
  24. #include <devices/keymap.h>
  25. #include <devices/inputevent.h>
  26. #include <intuition/intuitionbase.h>
  27. #include <intuition/classusr.h>
  28.  
  29. #include <workbench/workbench.h>
  30. #include <workbench/startup.h>
  31. #include <workbench/icon.h>
  32. #include <graphics/gfxbase.h>
  33. #include <inline/stubs.h>
  34.  
  35. #ifdef __OPTIMIZE__
  36. #include <inline/exec.h>
  37. #include <inline/dos.h>
  38. #include <inline/intuition.h>
  39. #include <inline/utility.h>
  40. #include <inline/keymap.h>
  41. #include <inline/icon.h>
  42. #else
  43. #include <clib/exec_protos.h>
  44. #include <clib/dos_protos.h>
  45. #include <clib/intuition_protos.h>
  46. #include <clib/utility_protos.h>
  47. #include <clib/keymap_protos.h>
  48. #include <clib/icon_protos.h>
  49. #endif
  50.  
  51. int     atexit(void (*)(void));
  52. }
  53.  
  54. #undef template
  55. #undef class
  56.  
  57.  
  58. extern "C" {
  59.  
  60. /* dont mangle our global symbols */
  61.  
  62. IntuitionBase    *IntuitionBase;
  63. GfxBase            *GfxBase;
  64. Library            *GadToolsBase;
  65. Library            *UtilityBase;
  66. Library            *WorkbenchBase;
  67. Library            *IconBase;
  68. Library            *CxBase;
  69. Library            *IFFParseBase;
  70. Library            *AslBase;
  71. Device            *KeymapBase;
  72.  
  73. extern ExecBase    *SysBase;
  74.  
  75. extern BPTR stdin;
  76. extern BPTR stdout;
  77. }
  78.  
  79.  
  80.     /*
  81.      * C++-Includes, C++-Definitionen
  82.      *
  83.      */
  84.  
  85. #include "../../add/baserel/add.h"            // prototypes for all new C-functions
  86. #include "../../add/baserel/couta.h"        // defines cout
  87. #include "../../add/baserel/OwnError.h"    // defines err
  88.  
  89.  
  90.     /*
  91.      * our function-prototypes
  92.      *
  93.      */
  94.  
  95. void    MyExit();
  96. BOOL    MyInit(int alen, char *aptr);
  97. int        main(int alen, char *aptr);
  98. void    OutputError(void);
  99. void    Mouse_SetPosition(UBYTE *x, UBYTE *y, BOOL relative=FALSE);
  100. void    Chars_InsertRawKey(LONG ch);
  101. void    Chars_InsertVanilla(UBYTE *chs);
  102. void    File_Handle(UBYTE *filename);
  103. void    Line_Handle(UBYTE *line);
  104. void    Mouse_Click(UWORD Code);
  105. int        myatoi(char *str);
  106. void    Window_Move_to_Front_and_activate(char *wintitle);
  107. void    Mouse_Move_to_LeftUpperActWindow(void);
  108. void    Screen_to_Front_and_activate(char *screentitle);
  109. void    PubScreen_to_Front_and_activate(UBYTE *pubscreentitle);
  110. void    Icon_Handle(UBYTE *filename);
  111.  
  112.  
  113.     /* Version-String */
  114.  
  115. char *version = "\0$VER: InsertEvent 1.0 (26.10.93)";
  116.  
  117.  
  118. #define TEMPLATE "MX=MOUSEX/K,MY=MOUSEY/K," \
  119. "RX=RELMOUSEX/K,RY=RELMOUSEY/K," \
  120. "LM=LEFT_MOUSE/S,LMU=LEFT_MOUSE_UP/S,LMD=LEFT_MOUSE_DOWN," \
  121. "RM=RIGHT_MOUSE/S,RMU=RIGHT_MOUSE_UP/S,RMD=RIGHT_MOUSE_DOWN/S," \
  122. "D=DOUBLECLICK/S," \
  123. "AW=ACTIVATEWINDOW/K,AS=ACTIVATESCREEN/K,APS=ACTIVATEPUBSCREEN/K," \
  124. "PUL=POINTERUPPERLEFT/S," \
  125. "RAWKEY/N,CHARS/K," \
  126. "FN=FILENAME/K"
  127.  
  128. #define TEMPLATE_HELP "InsertEvent V1.0 (c) by Gerhard Müller in 1993\n" \
  129. "[MOUSEX=<mouse x position in pixel>]\n" \
  130. "[MOUSEY=<mouse y position in pixel>]\n" \
  131. "[RELMOUSEX=<mouse x change in pixel>]\n" \
  132. "[RELMOUSEY=<mouse y change in pixel>]\n" \
  133. "[LEFT_MOUSE (simulates click with left mouse button)]\n" \
  134. "[LEFT_MOUSE_UP (simulates release of left mouse button)]\n" \
  135. "[LEFT_MOUSE_DOWN (simulates press of left mouse button)]\n" \
  136. "[RIGHT_MOUSE (simulates click with right mouse button)]\n" \
  137. "[RIGHT_MOUSE_UP (simulates release of right mouse button)]\n" \
  138. "[RIGHT_MOUSE_DOWN (simulates press of right mouse button)]\n" \
  139. "[DOUBLECLICK (simulates double-click with left mouse button)]\n" \
  140. "[ACTIVATEWINDOW=<windowtitle of window to activate, with *,?,etc.>]\n" \
  141. "[ACTIVATESCREEN=<screen name of screen to activate>]\n" \
  142. "[ACTIVATEPUBSCREEN=<public screen name of screen to activate>]\n" \
  143. "[POINTERUPPERLEFT=<set mouse to upper-left in active window>]\n" \
  144. "[RAWKEY=<rawkey-number>]\n" \
  145. "[CHARS=<string to insert>]\n" \
  146. "[FILENAME=<filename to use as input>]\n"
  147.  
  148. typedef struct {
  149.  UBYTE *mouse_x; UBYTE *mouse_y;
  150.  UBYTE *mouse_x_rel; UBYTE *mouse_y_rel;
  151.  ULONG *left_mouse;
  152.  ULONG *left_mouse_up;
  153.  ULONG *left_mouse_down;
  154.  ULONG *right_mouse;
  155.  ULONG *right_mouse_up;
  156.  ULONG *right_mouse_down;
  157.  ULONG *doubleclick;
  158.  char *activatewindow; char *activatescreen; UBYTE *pubactivatescreen;
  159.  ULONG *upperleft;
  160.  LONG *rawkey; UBYTE *chars;
  161.  UBYTE *filename;}
  162. ARGS;
  163.  
  164. #define DEFAULT { NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,NULL }
  165.  
  166. LONG rawkey=0;
  167.  
  168. ARGS            args = DEFAULT;    /* here the arguments are stored */
  169.  
  170. struct RDArgs    *rda = NULL;    /* for CLI-startup */
  171. UBYTE            **ToolTypes;     /* for WB-startup */
  172.  
  173.  
  174.  
  175. struct IOStdReq   *InputIO;           /* I/O request block */
  176. struct MsgPort    *InputMP;           /* Message port */
  177. struct InputEvent *FakeEvent;         /* InputEvent pointer */
  178. struct IEPointerPixel *NeoPix;        /* New mouse position pointer */
  179. struct Screen *PubScreen;             /* Screen pointer */
  180. BOOL    OpenInputDevice = FALSE;        /* To know what to free...*/
  181.  
  182.  
  183. int main(int arglen, char *argptr)
  184. {
  185.     if(MyInit(arglen, argptr))
  186.     {
  187.         if(arglen)
  188.         {
  189.             // We were called from CLI
  190.  
  191.             // Handle Params
  192.  
  193.             UBYTE *mouse_x=NULL;
  194.  
  195.             if(args.activatescreen)
  196.             {
  197.                 Screen_to_Front_and_activate(args.activatescreen);
  198.             }
  199.  
  200.             if(args.pubactivatescreen)
  201.             {
  202.                 PubScreen_to_Front_and_activate(args.pubactivatescreen);
  203.             }
  204.  
  205.             if(args.activatewindow)
  206.             {
  207.                 Window_Move_to_Front_and_activate(args.activatewindow);
  208.             }
  209.  
  210.             if(args.upperleft)
  211.             {
  212.                 Mouse_Move_to_LeftUpperActWindow();
  213.             }
  214.  
  215.             if(args.mouse_y)
  216.             {
  217.                 mouse_x=args.mouse_x;
  218.             }
  219.  
  220.             if(args.mouse_x)
  221.             {
  222.                 Mouse_SetPosition(mouse_x, args.mouse_y);
  223.             }
  224.  
  225.             if(args.mouse_x_rel)
  226.             {
  227.                 Mouse_SetPosition(args.mouse_x_rel, 0, TRUE);
  228.             }
  229.  
  230.             if(args.mouse_x_rel)
  231.             {
  232.                 Mouse_SetPosition(0, args.mouse_y_rel, TRUE);
  233.             }
  234.  
  235.             if(args.left_mouse)
  236.             {
  237.                 Mouse_Click(IECODE_LBUTTON);
  238.                 Mouse_Click(IECODE_LBUTTON|IECODE_UP_PREFIX);
  239.             }
  240.  
  241.             if(args.left_mouse_up)
  242.             {
  243.                 Mouse_Click(IECODE_LBUTTON|IECODE_UP_PREFIX);
  244.             }
  245.  
  246.             if(args.left_mouse_down)
  247.             {
  248.                 Mouse_Click(IECODE_LBUTTON);
  249.             }
  250.  
  251.             if(args.right_mouse)
  252.             {
  253.                 Mouse_Click(IECODE_RBUTTON);
  254.                 Mouse_Click(IECODE_RBUTTON|IECODE_UP_PREFIX);
  255.             }
  256.  
  257.             if(args.right_mouse_up)
  258.             {
  259.                 Mouse_Click(IECODE_RBUTTON|IECODE_UP_PREFIX);
  260.             }
  261.  
  262.             if(args.right_mouse_down)
  263.             {
  264.                 Mouse_Click(IECODE_RBUTTON);
  265.             }
  266.  
  267.             if(args.doubleclick)
  268.             {
  269.                 Mouse_Click(IECODE_LBUTTON);
  270.                 Mouse_Click(IECODE_LBUTTON|IECODE_UP_PREFIX);
  271.                 Mouse_Click(IECODE_LBUTTON);
  272.                 Mouse_Click(IECODE_LBUTTON|IECODE_UP_PREFIX);
  273.             }
  274.  
  275.             if(args.rawkey)
  276.             {
  277.                 Chars_InsertRawKey(*(args.rawkey));
  278.             }
  279.  
  280.             if(args.chars)
  281.             {
  282.                 Chars_InsertVanilla(args.chars);
  283.             }
  284.  
  285.             if(args.filename)
  286.             {
  287.                 File_Handle(args.filename);
  288.             }
  289.  
  290.         }
  291.         else
  292.         {
  293.             // We were called from WB
  294.  
  295.             // Take all arguements from ToolType-Array
  296.  
  297.             if(ToolTypes)
  298.             {
  299.                 int x=0;
  300.  
  301.                 while(ToolTypes[x])
  302.                 {
  303.                     Line_Handle(ToolTypes[x]);
  304.  
  305.                     x++;
  306.                 }
  307.             }
  308.  
  309.             /* Did we get any arguments passed in? */
  310.  
  311.             UBYTE FileName[256];
  312.  
  313.             WBStartup *WBenchMsg=(WBStartup *)argptr;
  314.  
  315.             if(WBenchMsg -> sm_NumArgs > 1)
  316.             {
  317.                 LONG i;
  318.  
  319.                     /* Run down the list of arguments. */
  320.  
  321.                 for(i = 1 ; i < WBenchMsg -> sm_NumArgs ; i++)
  322.                 {
  323.                         /* Does the argument have a filelock attached? */
  324.  
  325.                     if(WBenchMsg -> sm_ArgList[i] . wa_Lock)
  326.                     {
  327.                             /* Turn the filelock into a file name. */
  328.  
  329.                         if(NameFromLock(WBenchMsg -> sm_ArgList[i] . wa_Lock, FileName,256))
  330.                         {
  331.                             AddPart(FileName, (UBYTE *)WBenchMsg ->sm_ArgList[i] . wa_Name, 256);
  332.  
  333.                                 /* We have a filename */
  334.  
  335.                             Icon_Handle(FileName);
  336.                         }
  337.                     }
  338.                 }
  339.             }
  340.  
  341.         }
  342.     }
  343.  
  344.     OutputError();
  345.  
  346.     return RETURN_OK;
  347. }
  348.  
  349.     /*
  350.      * Open some libraries and make the commandline-parsing
  351.      *
  352.      */
  353.  
  354. BOOL MyInit(int alen, char *aptr)
  355. {
  356.     BOOL ok=FALSE;
  357.  
  358.     /* Are we running under control of Kickstart 2.0 or higher? */
  359.  
  360.     if(SysBase -> LibNode . lib_Version < 37)
  361.     {
  362.         err.NotifyError("needs Workbench & Kickstart Version 2.04 and above !\n");
  363.         return FALSE;
  364.     }
  365.  
  366.  
  367.     atexit(MyExit);            // the function MyExit should be called at exit()-time
  368.  
  369.  
  370.     /* open some libraries, not really needed in this programm, just to show how to do */
  371.  
  372.     if(IntuitionBase = (struct IntuitionBase *)OpenLibrary((UBYTE *)"intuition.library",37))
  373.     {
  374.         if(GfxBase = (struct GfxBase *)OpenLibrary((UBYTE *)"graphics.library",37))
  375.         {
  376.             if(GadToolsBase = OpenLibrary((UBYTE *)"gadtools.library",37))
  377.             {
  378.                 if(UtilityBase = OpenLibrary((UBYTE *)"utility.library",37))
  379.                 {
  380.                     if(WorkbenchBase = OpenLibrary((UBYTE *)"workbench.library",37))
  381.                     {
  382.                         if(IconBase = OpenLibrary((UBYTE *)"icon.library",37))
  383.                         {
  384.                             if(CxBase = OpenLibrary((UBYTE *)"commodities.library",37))
  385.                             {
  386.                                 if(IFFParseBase = OpenLibrary((UBYTE *)"iffparse.library",37))
  387.                                 {
  388.                                     if(AslBase = OpenLibrary((UBYTE *)"asl.library",37))
  389.                                     {
  390.                                         if(KeymapBase = (Device *)OpenLibrary((UBYTE *)"keymap.library", 0))
  391.                                         {
  392.                                             // we have all our libraries
  393.                                             ok=TRUE;
  394.                                         }
  395.                                         else err.NotifyError("unable to open keymap.library !");
  396.                                     }
  397.                                     else err.NotifyError("unable to open asl.library !");
  398.                                 }
  399.                                 else err.NotifyError("unable to open iffparse.library !");
  400.                             }
  401.                             else err.NotifyError("unable to open commodities.library !");
  402.                         }
  403.                         else err.NotifyError("unable to open icon.library !");
  404.                     }
  405.                     else err.NotifyError("unable to open workbench.library !");
  406.                 }
  407.                 else err.NotifyError("unable to open utility.library !");
  408.             }
  409.             else err.NotifyError("unable to open gadtools.library !");
  410.         }
  411.         else err.NotifyError("unable to open graphics.library !");
  412.     }
  413.     else err.NotifyError("unable to open intuition.library !");
  414.  
  415.     if(!ok) return FALSE;
  416.  
  417.  
  418.     /* normal startup-code.... */
  419.  
  420.     ok=FALSE;
  421.  
  422.     if(alen)
  423.     {
  424.         /* start from CLI */
  425.         /* parse arguements */
  426.  
  427.         if(rda = (RDArgs *)AllocDosObject( DOS_RDARGS, NULL ))
  428.         {
  429.             rda->RDA_ExtHelp = (UBYTE *)TEMPLATE_HELP;
  430.  
  431.             if(ReadArgs( (UBYTE *)TEMPLATE, (LONG *) &args, rda ) )
  432.             {
  433.                 /* Args erfolgreich gelesen */
  434.  
  435.                 ok=TRUE;
  436.             }
  437.             else
  438.             {
  439.                 err.DosError(IoErr(), "Error parsing commandline");    /* prints the appropriate err message */
  440.             }
  441.         }
  442.         else
  443.             err.NotifyError("Out of memory error !");
  444.     }
  445.     else
  446.     {
  447.         /* Workbench-Start */
  448.  
  449.         ToolTypes = (UBYTE **)ArgArrayInit((LONG)alen,(UBYTE **)aptr);
  450.  
  451.         if(ToolTypes)
  452.         {
  453.             ok=TRUE;
  454.         }
  455.     }
  456.  
  457.  
  458.     if(!ok) return FALSE;
  459.  
  460.  
  461.     /* open things that are necessary for our fake-events, look at
  462.         Set_Mouse.c in rkrm/dev/input */
  463.  
  464.     if (InputMP = CreateMsgPort())
  465.     {
  466.         if (FakeEvent = (InputEvent *)AllocMem(sizeof(struct InputEvent),MEMF_PUBLIC))
  467.         {
  468.             if (NeoPix  = (IEPointerPixel *)AllocMem(sizeof(struct IEPointerPixel),MEMF_PUBLIC))
  469.             {
  470.                 if (InputIO = (IOStdReq *)CreateIORequest(InputMP,sizeof(struct IOStdReq)))
  471.                 {
  472.                     if (!OpenDevice((UBYTE *)"input.device",NULL,
  473.                               (struct IORequest *)InputIO,NULL))
  474.                     {
  475.                         OpenInputDevice=TRUE;
  476.                         ok=TRUE;
  477.                     }
  478.                     else
  479.                         err.NotifyError("Error: Could not open input.device");
  480.                 }
  481.                 else
  482.                     err.NotifyError("Error: Could not create IORequest");
  483.             }
  484.             else
  485.                 err.NotifyError("Error: Could not allocate memory for NeoPix");
  486.         }
  487.         else
  488.             err.NotifyError("Error: Could not allocate memory for FakeEvent");
  489.     }
  490.     else
  491.         err.NotifyError("Error: Could not create message port");
  492.  
  493.  
  494.     return ok;
  495. }
  496.  
  497.  
  498.     /*
  499.      * This function gets called by exit(), look im MyInit() for corresponding atexit() call
  500.      * frees all system-depended things
  501.      */
  502.  
  503.  
  504. void MyExit()
  505. {
  506.  
  507.     if(OpenInputDevice)
  508.         CloseDevice((struct IORequest *)InputIO);
  509.  
  510.     if(InputIO)
  511.         DeleteIORequest(InputIO);
  512.  
  513.     if(NeoPix)
  514.         FreeMem(NeoPix,sizeof(struct IEPointerPixel));
  515.  
  516.     if(FakeEvent)
  517.         FreeMem(FakeEvent,sizeof(struct InputEvent));
  518.  
  519.     if(InputMP)
  520.         DeleteMsgPort(InputMP);
  521.  
  522.  
  523.         /* free WB-arguments */
  524.  
  525.     if( ToolTypes )
  526.     {
  527.         ArgArrayDone();
  528.     }
  529.  
  530.  
  531.         /* Free arguments passed by commandline allocated by ReadArgs() */
  532.  
  533.     if( rda )
  534.     {
  535.         FreeArgs( rda );
  536.         FreeDosObject( DOS_RDARGS, rda );
  537.     }
  538.  
  539.  
  540.         /* close all our libraries */
  541.  
  542.         /* Close keymap.library */
  543.  
  544.     if(KeymapBase)
  545.         CloseLibrary((struct Library *)KeymapBase);
  546.  
  547.         /* Close asl.library. */
  548.  
  549.     if(AslBase)
  550.         CloseLibrary(AslBase);
  551.  
  552.         /* Close iffparse.library. */
  553.  
  554.     if(IFFParseBase)
  555.         CloseLibrary(IFFParseBase);
  556.  
  557.         /* Close commodities.library. */
  558.  
  559.     if(CxBase)
  560.         CloseLibrary(CxBase);
  561.  
  562.         /* Close icon.library. */
  563.  
  564.     if(IconBase)
  565.         CloseLibrary(IconBase);
  566.  
  567.         /* Close workbench.library. */
  568.  
  569.     if(WorkbenchBase)
  570.         CloseLibrary(WorkbenchBase);
  571.  
  572.         /* Close utility.library. */
  573.  
  574.     if(UtilityBase)
  575.         CloseLibrary(UtilityBase);
  576.  
  577.         /* Close gadtools.library. */
  578.  
  579.     if(GadToolsBase)
  580.         CloseLibrary(GadToolsBase);
  581.  
  582.         /* Close graphics.library. */
  583.  
  584.     if(GfxBase)
  585.     {
  586.         struct Library *dummy=(struct Library *)GfxBase;
  587.         CloseLibrary(dummy);
  588.     }
  589.  
  590.         /* Close intuition.library. */
  591.  
  592.     if(IntuitionBase)
  593.     {
  594.         struct Library *dummy=(struct Library *)IntuitionBase;
  595.         CloseLibrary(dummy);
  596.     }
  597.  
  598. }
  599.  
  600.  
  601.     /*
  602.      * Output error-message if we have one
  603.      *
  604.      */
  605.  
  606.  
  607. void OutputError(void)
  608. {
  609.     if(err)
  610.     {
  611.         char *err_mem=0;
  612.         char *es;
  613.         LONG err_nr=err.SetErrorNumber(0);
  614.  
  615.         if(es=err.have_error_string())
  616.         {
  617.             if(stdout)
  618.             {
  619.                 cout <<    es << endl;
  620.             }
  621.             else
  622.                 ShowRequest(NULL, (UBYTE *)"Error:",
  623.                 (UBYTE *)es,
  624.                 (UBYTE *)"OK", err_nr);
  625.  
  626.         }
  627.         else
  628.         {
  629.             if(err_nr)
  630.             {
  631.                 if(stdout)
  632.                     cout <<    "Error-Number: " << err_nr << endl;
  633.                 else
  634.                 {
  635.                     ShowRequest(NULL, (UBYTE *)"Error:",
  636.                     (UBYTE *)"Error-Number %ld\n",
  637.                     (UBYTE *)"OK", err_nr);
  638.                 }
  639.             }
  640.         }
  641.     }
  642.  
  643.     err.Clear();
  644. }
  645.  
  646.  
  647. void Mouse_SetPosition(UBYTE *x, UBYTE *y, BOOL relative=FALSE)
  648. {
  649.    /* Set up IEPointerPixel fields */
  650.  
  651.     ULONG IBaseLock = LockIBase(0);
  652.  
  653.     NeoPix->iepp_Screen = IntuitionBase -> ActiveScreen;
  654.  
  655.     UnlockIBase(IBaseLock);
  656.  
  657.     NeoPix->iepp_Position.X = myatoi((char *)x);  /* put pointer at x = 100 */
  658.  
  659.     NeoPix->iepp_Position.Y = myatoi((char *)y);  /* put pointer at y = 200 */
  660.  
  661.    /* Set up InputEvent fields */
  662.    FakeEvent->ie_EventAddress = (APTR)NeoPix; /* IEPointerPixel */
  663.    FakeEvent->ie_NextEvent = NULL;
  664.    FakeEvent->ie_Class = IECLASS_NEWPOINTERPOS; /* new mouse pos */
  665.    FakeEvent->ie_SubClass = IESUBCLASS_PIXEL;   /* on pixel */
  666.    FakeEvent->ie_Code = IECODE_NOBUTTON;
  667.  
  668.     if(relative)
  669.        FakeEvent->ie_Qualifier = IEQUALIFIER_RELATIVEMOUSE;   /* absolute positioning */
  670.     else
  671.        FakeEvent->ie_Qualifier = NULL;   /* absolute positioning */
  672.  
  673.    InputIO->io_Data = (APTR)FakeEvent;   /* InputEvent */
  674.    InputIO->io_Length = sizeof(struct InputEvent);
  675.    InputIO->io_Command = IND_WRITEEVENT;
  676.    DoIO((struct IORequest *)InputIO);
  677. }
  678.  
  679. void Chars_InsertRawKey(LONG ch)
  680. {
  681.  
  682.     /* Set up InputEvent fields */
  683.     FakeEvent->ie_EventAddress = NULL;
  684.     FakeEvent->ie_NextEvent = NULL;
  685.     FakeEvent->ie_Class = IECLASS_RAWKEY;
  686.     FakeEvent->ie_SubClass = NULL;
  687.     FakeEvent->ie_Code = ch;
  688.     FakeEvent->ie_Qualifier = NULL;   /* absolute positioning */
  689.  
  690.     InputIO->io_Data = (APTR)FakeEvent;   /* InputEvent */
  691.     InputIO->io_Length = sizeof(struct InputEvent);
  692.     InputIO->io_Command = IND_WRITEEVENT;
  693.     DoIO((struct IORequest *)InputIO);
  694.  
  695. }
  696.  
  697. void Chars_InsertVanilla(UBYTE *chs)
  698. {
  699.   /* puts the given string into the input stream */
  700.   int i;
  701.   struct cq_pair {UBYTE code, qual;} raw_char;
  702.  
  703.         /* Set up InputEvent fields */
  704.         FakeEvent->ie_EventAddress = NULL;
  705.         FakeEvent->ie_NextEvent = NULL;
  706.         FakeEvent->ie_Class = IECLASS_RAWKEY;
  707.         FakeEvent->ie_SubClass = NULL;
  708.  
  709.   for(i=0; chs[i]!=0; i++)
  710.    {
  711.         MapANSI(&chs[i],(long int)1,(unsigned char *)&raw_char,1,NULL);
  712.         FakeEvent->ie_Code = raw_char.code;
  713.         FakeEvent->ie_Qualifier = raw_char.qual;
  714.  
  715.         InputIO->io_Data = (APTR)FakeEvent;   /* InputEvent */
  716.         InputIO->io_Length = sizeof(struct InputEvent);
  717.         InputIO->io_Command = IND_WRITEEVENT;
  718.         DoIO((struct IORequest *)InputIO);
  719.    }
  720.  
  721.     for(int x=0; x<strlen((char *)chs); x++)
  722.     {
  723.  
  724.     }
  725. }
  726.  
  727. void File_Handle(UBYTE *filename)
  728. {
  729.     BPTR fh;
  730.  
  731.     if(fh=Open(filename,MODE_OLDFILE))
  732.     {
  733.         UBYTE Buffer[200];
  734.         UBYTE *buf;
  735.  
  736.         while(buf=FGets(fh, Buffer, 200))
  737.         {
  738.             Line_Handle(buf);
  739.         }
  740.  
  741.         Close(fh);
  742.     }
  743.     else
  744.     {
  745.         UBYTE Buffer[250];
  746.         sprintf(Buffer, (UBYTE *)"Unable to open file \"%s\"!", filename);
  747.         err.NotifyError((char *)Buffer);
  748.         OutputError();
  749.     }
  750. }
  751.  
  752. void Line_Handle(UBYTE *line)
  753. {
  754.     static UBYTE *mouse_x=NULL;
  755.  
  756.     /* Search for "=" */
  757.  
  758.     UBYTE *after_equal=NULL;
  759.  
  760.     while((*line) && (( *line==' ') || (*line == '\t'))) line++;
  761.     UBYTE *s=line;
  762.  
  763.     /* Skip comment lines */
  764.  
  765.     if( (*s=='#') || (*s=='|') || (*s==';') || (*s=='\n')) return;
  766.  
  767.     while(*s)
  768.     {
  769.         if(*s=='\n') *s=0;
  770.  
  771.         if( *s== '=')
  772.         {
  773.             *s=0;
  774.             s++;
  775.             after_equal=s;
  776.         }
  777.         else s++;
  778.     }
  779.  
  780.     if(Stricmp((UBYTE *) "MOUSEX", line)==0)
  781.     {
  782.         mouse_x=after_equal;
  783.     }
  784.     else
  785.     if(Stricmp((UBYTE *) "MOUSEY", line)==0)
  786.     {
  787.         Mouse_SetPosition(mouse_x, after_equal);
  788.     }
  789.     else
  790.     if(Stricmp((UBYTE *) "LEFT_MOUSE_UP", line)==0)
  791.     {
  792.         Mouse_Click(IECODE_LBUTTON|IECODE_UP_PREFIX);
  793.     }
  794.     else
  795.     if(Stricmp((UBYTE *) "LEFT_MOUSE_DOWN", line)==0)
  796.     {
  797.         Mouse_Click(IECODE_LBUTTON);
  798.     }
  799.     else
  800.     if(Stricmp((UBYTE *) "LEFT_MOUSE", line)==0)
  801.     {
  802.         Mouse_Click(IECODE_LBUTTON);
  803.         Mouse_Click(IECODE_LBUTTON|IECODE_UP_PREFIX);
  804.     }
  805.     else
  806.     if(Stricmp((UBYTE *) "RIGHT_MOUSE_UP", line)==0)
  807.     {
  808.         Mouse_Click(IECODE_RBUTTON|IECODE_UP_PREFIX);
  809.     }
  810.     else
  811.     if(Stricmp((UBYTE *) "RIGHT_MOUSE_DOWN", line)==0)
  812.     {
  813.         Mouse_Click(IECODE_RBUTTON);
  814.     }
  815.     else
  816.     if(Stricmp((UBYTE *) "RIGHT_MOUSE", line)==0)
  817.     {
  818.         Mouse_Click(IECODE_RBUTTON);
  819.         Mouse_Click(IECODE_RBUTTON|IECODE_UP_PREFIX);
  820.     }
  821.     else
  822.     if(Stricmp((UBYTE *) "DOUBLECLICK", line)==0)
  823.     {
  824.         Mouse_Click(IECODE_LBUTTON);
  825.         Mouse_Click(IECODE_LBUTTON|IECODE_UP_PREFIX);
  826.         Mouse_Click(IECODE_LBUTTON);
  827.         Mouse_Click(IECODE_LBUTTON|IECODE_UP_PREFIX);
  828.     }
  829.     else
  830.     if(Stricmp((UBYTE *) "RAWKEY", line)==0)
  831.     {
  832.         Chars_InsertRawKey(myatoi((char *)after_equal));
  833.     }
  834.     else
  835.     if(Stricmp((UBYTE *) "CHARS", line)==0)
  836.     {
  837.         Chars_InsertVanilla(after_equal);
  838.     }
  839.     else
  840.     if(Stricmp((UBYTE *) "DELAY", line)==0)
  841.     {
  842.         Delay(myatoi((char *)after_equal));
  843.     }
  844.     else
  845.     if(Stricmp((UBYTE *) "FILENAME", line)==0)
  846.     {
  847.         File_Handle(after_equal);
  848.     }
  849.     else
  850.     if(Stricmp((UBYTE *) "RELMOUSEX", line)==0)
  851.     {
  852.         Mouse_SetPosition(after_equal,0,TRUE);
  853.     }
  854.     else
  855.     if(Stricmp((UBYTE *) "RELMOUSEY", line)==0)
  856.     {
  857.         Mouse_SetPosition(0, after_equal,TRUE);
  858.     }
  859.     else
  860.     if(Stricmp((UBYTE *) "ACTIVATEWINDOW", line)==0)
  861.     {
  862.         Window_Move_to_Front_and_activate((char *)after_equal);
  863.     }
  864.     else
  865.     if(Stricmp((UBYTE *) "POINTERUPPERLEFT", line)==0)
  866.     {
  867.         Mouse_Move_to_LeftUpperActWindow();
  868.     }
  869.     else
  870.     if(Stricmp((UBYTE *) "ACTIVATESCREEN", line)==0)
  871.     {
  872.         Screen_to_Front_and_activate((char *)after_equal);
  873.     }
  874.     else
  875.     if(Stricmp((UBYTE *) "ACTIVATEPUBSCREEN", line)==0)
  876.     {
  877.         PubScreen_to_Front_and_activate(after_equal);
  878.     }
  879.     else
  880.     {
  881.         if(stdout)
  882.             cout << "Ignoring unrecognize keyword " << (char *)line <<endl;
  883.         else
  884.             ShowRequest(NULL,(UBYTE *)"Error:",(UBYTE *)"Ignoring unrecognize keyword %s", (UBYTE *) "OK", line);
  885.     }
  886. }
  887.  
  888. void    Mouse_Click(UWORD Code)
  889. {
  890.     /* Set up InputEvent fields */
  891.     FakeEvent->ie_EventAddress = NULL;
  892.     FakeEvent->ie_NextEvent = NULL;
  893.     FakeEvent->ie_Class = IECLASS_RAWMOUSE;
  894.     FakeEvent->ie_SubClass = NULL;
  895.     FakeEvent->ie_Code = Code;
  896.     FakeEvent->ie_Qualifier = NULL;   /* absolute positioning */
  897.  
  898.     InputIO->io_Data = (APTR)FakeEvent;   /* InputEvent */
  899.     InputIO->io_Length = sizeof(struct InputEvent);
  900.     InputIO->io_Command = IND_WRITEEVENT;
  901.     DoIO((struct IORequest *)InputIO);
  902. }
  903.  
  904. int myatoi(char *str)
  905. {
  906.     LONG x;
  907.  
  908.     if(str)
  909.     {
  910.         int len=strlen(str);
  911.  
  912.         if(len==StrToLong((STRPTR)str,&x))
  913.         {
  914.             return x;
  915.         }
  916.         else
  917.         {
  918.             char Buffer[250];
  919.             sprintf((UBYTE *)Buffer, (UBYTE *)"Unable to convert \"%s\" to a number, taking default value 0",str);
  920.             err.NotifyError(Buffer);
  921.             OutputError();
  922.             return 0;
  923.         }
  924.     }
  925.     else
  926.     return 0;
  927. }
  928.  
  929. void Mouse_Move_to_LeftUpperActWindow(void)
  930. {
  931.     ULONG IBaseLock = LockIBase(0);
  932.  
  933.     NeoPix->iepp_Screen = IntuitionBase -> ActiveScreen;
  934.     NeoPix->iepp_Position.X = IntuitionBase ->ActiveWindow->LeftEdge;
  935.     NeoPix->iepp_Position.Y    = IntuitionBase ->ActiveWindow->TopEdge;
  936.  
  937.     UnlockIBase(IBaseLock);
  938.  
  939.    /* Set up InputEvent fields */
  940.    FakeEvent->ie_EventAddress = (APTR)NeoPix; /* IEPointerPixel */
  941.    FakeEvent->ie_NextEvent = NULL;
  942.    FakeEvent->ie_Class = IECLASS_NEWPOINTERPOS; /* new mouse pos */
  943.    FakeEvent->ie_SubClass = IESUBCLASS_PIXEL;   /* on pixel */
  944.    FakeEvent->ie_Code = IECODE_NOBUTTON;
  945.  
  946.    FakeEvent->ie_Qualifier = NULL;   /* absolute positioning */
  947.  
  948.    InputIO->io_Data = (APTR)FakeEvent;   /* InputEvent */
  949.    InputIO->io_Length = sizeof(struct InputEvent);
  950.    InputIO->io_Command = IND_WRITEEVENT;
  951.    DoIO((struct IORequest *)InputIO);
  952. }
  953.  
  954.  
  955. void Window_Move_to_Front_and_activate(char *wintitle)
  956. {
  957.     if(wintitle)
  958.     {
  959.         ULONG IBaseLock = LockIBase(0);
  960.  
  961.         struct Window *act_win = IntuitionBase -> ActiveScreen -> FirstWindow;
  962.  
  963.         UBYTE *Buffer= (UBYTE *)AllocVec(strlen(wintitle)+10,MEMF_CLEAR);
  964.         if(Buffer)
  965.         {
  966.             Window *found=NULL;
  967.  
  968.             ParsePattern((UBYTE *)wintitle, Buffer, strlen(wintitle)+10);
  969.  
  970.             if(act_win)
  971.             {
  972.                 while(!found && act_win)
  973.                 {
  974.                     if(act_win->Title)
  975.                     {
  976.                         if(MatchPattern(Buffer, act_win->Title))
  977.                         {
  978.                             found=act_win;
  979.                         }
  980.                     }
  981.                     act_win=act_win->NextWindow;
  982.                 }
  983.             }
  984.  
  985.             UnlockIBase(IBaseLock);
  986.  
  987.             if(found)
  988.             {
  989.                 ActivateWindow(found);
  990.                 if(!(found->Flags & WFLG_BACKDROP))
  991.                     WindowToFront(found);
  992.                }
  993.  
  994.             FreeVec(Buffer);
  995.         }
  996.     }
  997. }
  998.  
  999. void Screen_to_Front_and_activate(char *screentitle)
  1000. {
  1001.     if(screentitle)
  1002.     {
  1003.         ULONG IBaseLock = LockIBase(0);
  1004.  
  1005.         struct Screen *act_scr = IntuitionBase -> FirstScreen;
  1006.  
  1007.         UBYTE *Buffer= (UBYTE *)AllocVec(strlen(screentitle)+10,MEMF_CLEAR);
  1008.         if(Buffer)
  1009.         {
  1010.             Screen *found=NULL;
  1011.  
  1012.             ParsePattern((UBYTE *)screentitle, Buffer, strlen(screentitle)+10);
  1013.  
  1014.             if(act_scr)
  1015.             {
  1016.                 while(!found && act_scr)
  1017.                 {
  1018.                     if(act_scr->Title)
  1019.                     {
  1020.                         if(MatchPattern(Buffer, act_scr->Title))
  1021.                         {
  1022.                             found=act_scr;
  1023.                         }
  1024.                     }
  1025.                     act_scr=act_scr->NextScreen;
  1026.                 }
  1027.             }
  1028.  
  1029.             UnlockIBase(IBaseLock);
  1030.  
  1031.             if(found)
  1032.             {
  1033.                 ScreenToFront(found);
  1034.                 if(found->FirstWindow)
  1035.                 {
  1036.                     ActivateWindow(found->FirstWindow);
  1037.                 }
  1038.                }
  1039.  
  1040.             FreeVec(Buffer);
  1041.         }
  1042.     }
  1043. }
  1044.  
  1045. void PubScreen_to_Front_and_activate(UBYTE *pubscreentitle)
  1046. {
  1047.     if(pubscreentitle)
  1048.     {
  1049.         Screen *scr;
  1050.         if(scr=LockPubScreen(pubscreentitle))
  1051.         {
  1052.             ScreenToFront(scr);
  1053.             if(scr->FirstWindow)
  1054.             {
  1055.                 ActivateWindow(scr->FirstWindow);
  1056.             }
  1057.  
  1058.             UnlockPubScreen(NULL, scr);
  1059.         }
  1060.     }
  1061. }
  1062.  
  1063. void Icon_Handle(UBYTE *filename)
  1064. {
  1065.     struct DiskObject *Icon;
  1066.  
  1067.     if(Icon = GetDiskObject(filename))
  1068.     {
  1069.         UBYTE **argptr=(UBYTE **)(Icon -> do_ToolTypes);
  1070.  
  1071.         int x=0;
  1072.  
  1073.         while(argptr[x])
  1074.         {
  1075.             Line_Handle(argptr[x]);
  1076.             x++;
  1077.         }
  1078.     }
  1079. }
  1080.