home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 365.lha / RevBut / RevBut.c < prev    next >
C/C++ Source or Header  |  1990-04-10  |  2KB  |  95 lines

  1. #include <exec/exec.h>
  2. #include <libraries/dos.h>
  3. #include <intuition/intuition.h>
  4. #include <devices/inputevent.h>
  5. #include <devices/input.h>
  6.  
  7. void HandlerInterface();
  8.  
  9. struct MsgPort *inPort;
  10. struct IOStdReq *inReq;
  11.  
  12. struct Interrupt HandlerData =
  13. { { NULL,NULL,0,55,NULL }, NULL, &HandlerInterface };
  14.  
  15. int down = NULL;
  16. BOOL on = TRUE;
  17.  
  18.  
  19. struct InputEvent *myHandler(event, data)
  20.   struct InputEvent *event;
  21.   APTR data;
  22. {    register struct InputEvent *e, *oe = NULL, *ne = NULL;
  23.  
  24.     Forbid();
  25.     for(e=event; e != NULL; e = ne)
  26.     {    ne = e->ie_NextEvent;
  27.         if(on && e->ie_Class == IECLASS_RAWMOUSE &&
  28.           (e->ie_Code & IECODE_COMM_CODE_LAST) == IECODE_RBUTTON)
  29.         {    if(e->ie_Code & IECODE_UP_PREFIX)    /* Loslass-Event: entfernen */
  30.             {    if(oe) oe->ie_NextEvent = ne;
  31.                 else event = ne;
  32.                 e = 0;
  33.             }
  34.             else                                /* sonst: kippen */
  35.             {    e->ie_Code = down | IECODE_RBUTTON;
  36.                 down = IECODE_UP_PREFIX - down;
  37.             }
  38.         }
  39.         else if(e->ie_Class == IECLASS_RAWKEY &&
  40.                 e->ie_Code == 0x42 && e->ie_Qualifier & IEQUALIFIER_LSHIFT)
  41.         {    on = !on;                            /* Lshift-Tab: Ein/Aus */
  42.             if(oe) oe->ie_NextEvent = ne;
  43.             else event = ne;
  44.             e = 0;
  45.         }
  46.  
  47.         if(e) oe = e;
  48.     }
  49.  
  50.     Permit();
  51.     return(event);
  52. }
  53.  
  54. void HandlerInterface()
  55. {
  56. #asm
  57.     movem.l    a4,-(sp)
  58.     jsr        _geta4#
  59.     movem.l    a0/a1,-(sp)
  60.     jsr        _myHandler
  61.     addq.l    #8,sp
  62.     move.l    (sp)+,a4
  63. #endasm
  64. }
  65.  
  66. Init()
  67. {
  68.     inPort = CreatePort(0,0);
  69.     inReq = CreateStdIO(inPort);
  70.     OpenDevice("input.device",0,inReq,0);
  71.     
  72.     inReq->io_Command = IND_ADDHANDLER;
  73.     inReq->io_Data = (APTR)&HandlerData;
  74.     DoIO(inReq);
  75. }
  76.  
  77. Quit()
  78. {
  79.     inReq->io_Command = IND_REMHANDLER;
  80.     inReq->io_Data = (APTR)&HandlerData;
  81.     DoIO(inReq);
  82.  
  83.     CloseDevice(inReq);
  84.     DeleteStdIO(inReq);
  85.     DeletePort(inPort);
  86.     exit(0);
  87. }
  88.  
  89. main()
  90. {
  91.     Init();
  92.     Wait(SIGBREAKF_CTRL_C);
  93.     Quit();
  94. }
  95.