home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / c / rkrm / input / set_mouse.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  5KB  |  142 lines

  1. /*
  2.  * Copyright (c) 1992 Commodore-Amiga, Inc.
  3.  *
  4.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  5.  * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition,
  6.  * published by Addison-Wesley (ISBN 0-201-56775-X).
  7.  *
  8.  * The "Amiga ROM Kernel Reference Manual: Devices" contains additional
  9.  * information on the correct usage of the techniques and operating system
  10.  * functions presented in these examples.  The source and executable code
  11.  * of these examples may only be distributed in free electronic form, via
  12.  * bulletin board or as part of a fully non-commercial and freely
  13.  * redistributable diskette.  Both the source and executable code (including
  14.  * comments) must be included, without modification, in any copy.  This
  15.  * example may not be published in printed form or distributed with any
  16.  * commercial product.  However, the programming techniques and support
  17.  * routines set forth in these examples may be used in the development
  18.  * of original executable software products for Commodore Amiga computers.
  19.  *
  20.  * All other rights reserved.
  21.  *
  22.  * This example is provided "as-is" and is subject to change; no
  23.  * warranties are made.  All use is at your own risk. No liability or
  24.  * responsibility is assumed.
  25.  *
  26.  ***************************************************************************
  27.  *
  28.  * Set_Mouse.c
  29.  *
  30.  * This example sets the mouse at x=100 and y=200
  31.  *
  32.  * Compile with SAS C 5.10: LC -b1 -cfistq -v -y -L
  33.  * Requires Kickstart 36 or greater.
  34.  *
  35.  * Run from CLI only
  36.  */
  37.  
  38. #include <exec/types.h>
  39. #include <exec/memory.h>
  40. #include <exec/libraries.h>
  41. #include <devices/input.h>
  42. #include <devices/inputevent.h>
  43. #include <intuition/screens.h>
  44.  
  45. #include <clib/exec_protos.h>
  46. #include <clib/intuition_protos.h>
  47.  
  48. #include <stdio.h>
  49.  
  50. #ifdef LATTICE
  51. int CXBRK(void) { return(0); }  /* Disable SAS CTRL/C handling */
  52. int chkabort(void) { return(0); }  /* really */
  53. #endif
  54.  
  55. struct IntuitionBase *IntuitionBase;
  56. extern struct Library *SysBase;
  57.  
  58. void main(void)
  59. {
  60. struct IOStdReq   *InputIO;           /* I/O request block */
  61. struct MsgPort    *InputMP;           /* Message port */
  62. struct InputEvent *FakeEvent;         /* InputEvent pointer */
  63. struct IEPointerPixel *NeoPix;        /* New mouse position pointer */
  64. struct Screen *PubScreen;             /* Screen pointer */
  65.  
  66. if(SysBase->lib_Version>=36)
  67.    {
  68.    if (InputMP = CreateMsgPort())
  69.       {
  70.       if (FakeEvent = AllocMem(sizeof(struct InputEvent),MEMF_PUBLIC))
  71.          {
  72.          if (NeoPix  = AllocMem(sizeof(struct IEPointerPixel),MEMF_PUBLIC))
  73.             {
  74.             if (InputIO = CreateIORequest(InputMP,sizeof(struct IOStdReq)))
  75.                {
  76.                if (!OpenDevice("input.device",NULL,
  77.                               (struct IORequest *)InputIO,NULL))
  78.                   {
  79.                      /* Open Intuition library */
  80.                   if (IntuitionBase = (struct IntuitionBase *)
  81.                         OpenLibrary("intuition.library",36L))
  82.                      {
  83.                      /* Get pointer to screen and lock screen */
  84.                      if (PubScreen = (struct Screen *)LockPubScreen(NULL))
  85.                         {
  86.                         /* Set up IEPointerPixel fields */
  87.                         NeoPix->iepp_Screen =(struct Screen *)PubScreen; /* WB screen */
  88.                         NeoPix->iepp_Position.X = 100;  /* put pointer at x = 100 */
  89.                         NeoPix->iepp_Position.Y = 200;  /* put pointer at y = 200 */
  90.  
  91.                         /* Set up InputEvent fields */
  92.                         FakeEvent->ie_EventAddress = (APTR)NeoPix; /* IEPointerPixel */
  93.                         FakeEvent->ie_NextEvent = NULL;
  94.                         FakeEvent->ie_Class = IECLASS_NEWPOINTERPOS; /* new mouse pos */
  95.                         FakeEvent->ie_SubClass = IESUBCLASS_PIXEL;   /* on pixel */
  96.                         FakeEvent->ie_Code = IECODE_NOBUTTON;
  97.                         FakeEvent->ie_Qualifier = NULL;   /* absolute positioning */
  98.  
  99.                         InputIO->io_Data = (APTR)FakeEvent;   /* InputEvent */
  100.                         InputIO->io_Length = sizeof(struct InputEvent);
  101.                         InputIO->io_Command = IND_WRITEEVENT;
  102.                         DoIO((struct IORequest *)InputIO);
  103.  
  104.                         UnlockPubScreen(NULL,PubScreen);  /* Unlock screen */
  105.                         }
  106.                      else
  107.                         printf("Could not get pointer to screen\n");
  108.  
  109.                      CloseLibrary(IntuitionBase);  /* Close intuition library */
  110.                      }
  111.                   else
  112.                      printf("Error: Could not open V36 or higher intuition.library\n");
  113.  
  114.                   CloseDevice((struct IORequest *)InputIO);
  115.                   }
  116.                else
  117.                   printf("Error: Could not open input.device\n");
  118.  
  119.                DeleteIORequest(InputIO);
  120.                }
  121.             else
  122.                printf("Error: Could not create IORequest\n");
  123.  
  124.             FreeMem(NeoPix,sizeof(struct IEPointerPixel));
  125.             }
  126.          else
  127.             printf("Error: Could not allocate memory for NeoPix\n");
  128.  
  129.          FreeMem(FakeEvent,sizeof(struct InputEvent));
  130.          }
  131.       else
  132.          printf("Error: Could not allocate memory for FakeEvent\n");
  133.  
  134.       DeleteMsgPort(InputMP);
  135.       }
  136.    else
  137.       printf("Error: Could not create message port\n");
  138.    }
  139. else
  140.    printf("Error: Release2 (V36) or a later version of the OS is required\n");
  141. }
  142.