home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 029.lha / Mouse.c < prev    next >
C/C++ Source or Header  |  1987-04-02  |  4KB  |  112 lines

  1. /***************************************************************************
  2.  
  3.    'Mouse' was written to move the mouse pointer via keyboard commands.
  4.    It was derived from various display hacks found on CompuServe.
  5.  
  6.    Usage:   Mouse                : Displays current pointer coordinates
  7.             Mouse X Y            : Move pointer to X Y
  8.  
  9.  
  10.    'Mouse' is Public Domain.  Please feel free to pass it anywhere
  11.    you want.
  12.  
  13.    Comments should be sent to:   Denny Jenkins
  14.                                  5226 Greensedge Way
  15.                                  Columbus, Ohio  43220
  16.  
  17.                                  CompuServe ID: 70003,2374
  18.  
  19.  
  20. ****************************************************************************/
  21.  
  22. #include <exec/types.h>
  23. #include <intuition/intuition.h>
  24. #include <lattice/stdio.h>
  25. #include <devices/input.h>
  26.  
  27. #define  Coordinates  "Mouse: Coordinates are %d, %d\n"
  28. #define  NoIntuition  "Error: Loading Intuition\n"
  29. #define  NoWindow     "Error: Opening window\n"
  30. #define  NoPort       "Error: Opening port\n"
  31. #define  NoRequest    "Error: Creating I/O request\n"
  32. #define  NoInput      "Error: Opening input.device\n"
  33. #define  InvalidX     "Error: XCoordinate cannot be greater than 640\n"
  34. #define  InvalidY     "Error: YCoordinate cannot be greater than 400\n"
  35. #define  Usage        "Usage: Mouse XCoordinate YCoordinate\n"
  36.  
  37. struct Window *w=NULL, *OpenWindow();
  38. struct Screen *s;
  39.  
  40. struct NewWindow nw = {
  41.    0,0,3,10,
  42.    -1,-1,
  43.    NULL,
  44.    NULL,
  45.    NULL, NULL,
  46.    NULL,
  47.    NULL, NULL,
  48.    0,0,0,0,
  49.    WBENCHSCREEN
  50. };
  51.  
  52. ULONG    IntuitionBase, OpenLibrary();
  53. struct   MsgPort      *ioPort, *CreatePort();
  54. struct   IOStdReq     *ioReq,  *CreateStdIO();
  55. struct   InputEvent   Mouse;
  56. void     OpenStuff(), CloseStuff();
  57.  
  58. main(ac, av)
  59. int ac;
  60. char *av[];
  61. {
  62.    OpenStuff();
  63.    if (ac == 1) {
  64.       printf (Coordinates,s->MouseX,s->MouseY*2);
  65.       CloseStuff(NULL);
  66.    }
  67.    if (!(ac == 3))                                 CloseStuff (Usage);
  68.    if (atoi(av[1]) > 640)                          CloseStuff (InvalidX);
  69.    if (atoi(av[2]) > 400)                          CloseStuff (InvalidY);
  70.    Mouse.ie_X = atoi (av[1]) - (s->MouseX);
  71.    Mouse.ie_Y = atoi (av[2]) - (s->MouseY)*2;
  72.    DoIO(ioReq);
  73.    CloseStuff(NULL);
  74. }
  75.  
  76. void OpenStuff()
  77. {
  78.    if (!(IntuitionBase = OpenLibrary("intuition.library",0L)))
  79.                                                    CloseStuff (NoIntuition);
  80.    if (!(ioPort = CreatePort("Mouse",NULL)))       CloseStuff (NoPort);
  81.    if (!(ioReq = CreateStdIO(ioPort)))             CloseStuff (NoRequest);
  82.    if (OpenDevice("input.device",0,ioReq,0))       CloseStuff (NoInput);
  83.    if (!(w = OpenWindow(&nw)))                     CloseStuff (NoWindow);
  84.    s = w->WScreen;
  85.  
  86.    ioReq->io_Command           = IND_WRITEEVENT;
  87.    ioReq->io_Flags             = 0;
  88.    ioReq->io_Length            = sizeof(struct InputEvent);
  89.    ioReq->io_Data              = (APTR) &Mouse;
  90.    Mouse.ie_NextEvent          = NULL;
  91.    Mouse.ie_Class              = IECLASS_RAWMOUSE;
  92.    Mouse.ie_TimeStamp.tv_secs  = 0;
  93.    Mouse.ie_TimeStamp.tv_micro = 0;
  94.    Mouse.ie_Code               = IECODE_NOBUTTON;
  95.    Mouse.ie_Qualifier          = IEQUALIFIER_RELATIVEMOUSE;
  96. }
  97.  
  98. void CloseStuff(Message)
  99. char *Message;
  100. {
  101.    if (ioReq)
  102.                         if (ioReq->io_Device)
  103.                         CloseDevice(ioReq);
  104.                             DeleteStdIO(ioReq);
  105.    if (ioPort)
  106.                         DeletePort(ioPort);
  107.    if (w)               CloseWindow(w);
  108.    if (IntuitionBase)   CloseLibrary(IntuitionBase);
  109.    if (Message)         fprintf (stderr, Message);
  110.    _exit(!!Message);
  111. }
  112.