home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / input / inputmake.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-03  |  3.6 KB  |  92 lines

  1. /* Copyright (c) 1990 Commodore-Amiga, Inc.
  2.  *
  3.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  4.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals.
  5.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  6.  * information on the correct usage of the techniques and operating system
  7.  * functions presented in this example.  The source and executable code of
  8.  * this example may only be distributed in free electronic form, via bulletin
  9.  * board or as part of a fully non-commercial and freely redistributable
  10.  * diskette.  Both the source and executable code (including comments) must
  11.  * be included, without modification, in any copy.  This example may not be
  12.  * published in printed form or distributed with any commercial product.
  13.  * However, the programming techniques and support routines set forth in
  14.  * this example may be used in the development of original executable
  15.  * software products for Commodore Amiga computers.
  16.  * All other rights reserved.
  17.  * This example is provided "as-is" and is subject to change; no warranties
  18.  * are made.  All use is at your own risk.  No liability or responsibility
  19.  * is assumed.
  20.  */
  21.  
  22. /*
  23.  * InputDevice example
  24.  *
  25.  * This example adds a few mouse movements to the input chain...
  26.  */
  27.  
  28. #include <exec/types.h>
  29. #include <exec/memory.h>
  30. #include <devices/input.h>
  31. #include <devices/inputevent.h>
  32.  
  33. #include <proto/all.h>
  34.  
  35. VOID main(VOID)
  36. {
  37. struct IOStdReq   *inputReqBlk;
  38. struct MsgPort    *inputPort;
  39. struct InputEvent *FakeEvent;
  40.        short      loop;
  41.        short      num;
  42.        short      numloop;
  43.  
  44.     if (inputPort=CreatePort(NULL,NULL))
  45.     {
  46.         if (FakeEvent=AllocMem(sizeof(struct InputEvent),MEMF_PUBLIC))
  47.         {
  48.             if (inputReqBlk=(struct IOStdReq *)CreateExtIO(inputPort,
  49.                                                      sizeof(struct IOStdReq)))
  50.             {
  51.                 if (!OpenDevice("input.device",NULL,
  52.                                  (struct IORequest *)inputReqBlk,NULL))
  53.                 {
  54.                     for (numloop=0;numloop<4;numloop++)
  55.                      for (loop=0;loop<8;loop++)
  56.                       for (num=0;num<20;num++)
  57.                     {
  58.                         FakeEvent->ie_NextEvent=NULL;
  59.                         FakeEvent->ie_Class=IECLASS_RAWMOUSE;
  60.                         FakeEvent->ie_Code=IECODE_NOBUTTON;
  61.                         FakeEvent->ie_Qualifier=IEQUALIFIER_RELATIVEMOUSE;
  62.                         FakeEvent->ie_X=0;
  63.                         FakeEvent->ie_Y=0;
  64.  
  65.                         switch (loop)
  66.                         {
  67.                         case 0: FakeEvent->ie_X=1;
  68.                         case 1: FakeEvent->ie_Y=1;  break;
  69.                         case 2: FakeEvent->ie_Y=1;
  70.                         case 3: FakeEvent->ie_X=-1; break;
  71.                         case 4: FakeEvent->ie_X=-1;
  72.                         case 5: FakeEvent->ie_Y=-1; break;
  73.                         case 6: FakeEvent->ie_Y=-1;
  74.                         case 7: FakeEvent->ie_X=1;  break;
  75.                         }
  76.  
  77.                         inputReqBlk->io_Data=(APTR)FakeEvent;
  78.                         inputReqBlk->io_Command=IND_WRITEEVENT;
  79.                         inputReqBlk->io_Flags=0;
  80.                         inputReqBlk->io_Length=sizeof(struct InputEvent);
  81.                         DoIO((struct IORequest *)inputReqBlk);
  82.                     }
  83.                     CloseDevice((struct IORequest *)inputReqBlk);
  84.                 }
  85.                 DeleteExtIO((struct IORequest *)inputReqBlk);
  86.             }
  87.             FreeMem(FakeEvent,sizeof(struct InputEvent));
  88.         }
  89.         DeletePort(inputPort);
  90.     }
  91. }
  92.