home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 1.2 / amidev_cd_12.iso / reference_library / devices / dev_examples / set_mouse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-20  |  4.3 KB  |  119 lines

  1. /*
  2.  * Set_Mouse.c
  3.  *
  4.  * This example sets the mouse at x=100 and y=200
  5.  *
  6.  * Compile with SAS C 5.10: LC -b1 -cfistq -v -y -L
  7.  * Requires Kickstart 36 or greater.
  8.  *
  9.  * Run from CLI only
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <devices/input.h>
  15. #include <devices/inputevent.h>
  16. #include <intuition/screens.h>
  17.  
  18. #include <clib/exec_protos.h>
  19. #include <clib/intuition_protos.h>
  20.  
  21. #include <stdio.h>
  22.  
  23. #ifdef LATTICE
  24. int CXBRK(void) { return(0); }  /* Disable SAS CTRL/C handling */
  25. int chkabort(void) { return(0); }  /* really */
  26. #endif
  27.  
  28. struct IntuitionBase *IntuitionBase;
  29.  
  30. void main(void)
  31. {
  32. struct IOStdReq   *InputIO;           /* I/O request block */
  33. struct MsgPort    *InputMP;           /* Message port */
  34. struct InputEvent *FakeEvent;         /* InputEvent pointer */
  35. struct IEPointerPixel *NeoPix;      /* New mouse position pointer */
  36. struct Screen *PubScreen;             /* Screen pointer */
  37.  
  38. if (InputMP = CreateMsgPort())
  39.     {
  40.     if (FakeEvent = AllocMem(sizeof(struct InputEvent),MEMF_PUBLIC))
  41.         {
  42.         if (NeoPix  = AllocMem(sizeof(struct IEPointerPixel),MEMF_PUBLIC))
  43.             {
  44.             if (InputIO = CreateIORequest(InputMP,sizeof(struct IOStdReq)))
  45.                 {
  46.                 if (!OpenDevice("input.device",NULL,
  47.                                (struct IORequest *)InputIO,NULL))
  48.                     {
  49.                         /* Open Intuition library */
  50.                     if (IntuitionBase=(struct IntuitionBase *)
  51.                                       OpenLibrary("intuition.library",36L))
  52.                         {
  53.                         /* Get pointer to screen and lock screen */
  54.                         if (PubScreen=(struct Screen *)LockPubScreen(NULL))
  55.                             {
  56.                             /* Set up IEPointerPixel fields */
  57.                             /* WB screen */
  58.                             NeoPix->iepp_Screen=(struct Screen *)PubScreen;
  59.                             /* put pointer at x = 100 */
  60.                             NeoPix->iepp_Position.X = 100;
  61.                             /* put pointer at y = 200 */
  62.                             NeoPix->iepp_Position.Y = 200;
  63.  
  64.                             /* Set up InputEvent fields */
  65.                             /* IEPointerPixel */
  66.                             FakeEvent->ie_EventAddress = (APTR)NeoPix;
  67.                             FakeEvent->ie_NextEvent = NULL;
  68.                             /* new mouse pos */
  69.                             FakeEvent->ie_Class = IECLASS_NEWPOINTERPOS;
  70.                             /* on pixel */
  71.                             FakeEvent->ie_SubClass = IESUBCLASS_PIXEL;
  72.                             FakeEvent->ie_Code = IECODE_NOBUTTON;
  73.                             /* absolute positioning */
  74.                             FakeEvent->ie_Qualifier = NULL;
  75.  
  76.                             /* InputEvent */
  77.                             InputIO->io_Data = (APTR)FakeEvent;
  78.                             InputIO->io_Length = sizeof(struct InputEvent);
  79.                             InputIO->io_Command = IND_WRITEEVENT;
  80.                             DoIO((struct IORequest *)InputIO);
  81.                             /* Unlock screen */
  82.                             UnlockPubScreen(NULL,PubScreen);
  83.                             }
  84.                         else
  85.                             printf("Could not get pointer to screen\n");
  86.                         /* Close intuition library */
  87.                         CloseLibrary(IntuitionBase);
  88.                         }
  89.                     else
  90.                         /* Can't open V36 (or higher) intuition.library */
  91.                         printf("Error:Can't open V36 intuition.library\n");
  92.  
  93.                     CloseDevice((struct IORequest *)InputIO);
  94.                     }
  95.                 else
  96.                     printf("Error: Could not open input.device\n");
  97.  
  98.                 DeleteIORequest(InputIO);
  99.                 }
  100.             else
  101.                 printf("Error: Could not create IORequest\n");
  102.  
  103.             FreeMem(NeoPix,sizeof(struct IEPointerPixel));
  104.             }
  105.         else
  106.             printf("Error: Could not allocate memory for NeoPix\n");
  107.  
  108.         FreeMem(FakeEvent,sizeof(struct InputEvent));
  109.         }
  110.     else
  111.         printf("Error: Could not allocate memory for FakeEvent\n");
  112.  
  113.     DeleteMsgPort(InputMP);
  114.     }
  115. else
  116.     printf("Error: Could not create message port\n");
  117. }
  118.  
  119.