home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / utility / misc / rawinfo.lha / handler.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-09  |  1.8 KB  |  63 lines

  1. void RawInsert(long code,long qualifier);
  2. void RemoveHandler(void);
  3. void InstallHandler(void);
  4.  
  5. extern void myhandler(void);
  6. extern APTR data;
  7.  
  8. struct IOStdReq *inputRequestBlock;
  9. struct Interrupt handlerStuff;
  10. struct MsgPort *inputDevPort;
  11.  
  12. void RemoveHandler(void)
  13. {
  14.     if (inputRequestBlock) {
  15.         if (inputRequestBlock->io_Device) {
  16.             inputRequestBlock->io_Command = IND_REMHANDLER;  /* Remove handler */
  17.             inputRequestBlock->io_Data    = (APTR)&handlerStuff;
  18.             DoIO((struct IORequest *)inputRequestBlock);
  19.             CloseDevice((struct IORequest *)inputRequestBlock);
  20.         }
  21.         DeleteStdIO(inputRequestBlock);
  22.     }
  23.     if (inputDevPort) {
  24.         DeletePort(inputDevPort);
  25.     }
  26.     return;
  27. }
  28.  
  29. void InstallHandler(void)
  30. {
  31.     inputRequestBlock = NULL;
  32.     if (!(inputDevPort = CreatePort(0L, 0L))) {
  33.         RemoveHandler();
  34.     }
  35.     if (!(inputRequestBlock = CreateStdIO(inputDevPort))) {
  36.         RemoveHandler();
  37.     }
  38.     if (OpenDevice("input.device", 0L,(struct IORequest *)inputRequestBlock, 0L)) {
  39.         RemoveHandler();
  40.     }
  41.     handlerStuff.is_Node.ln_Name = "MACRO Handler";
  42.     handlerStuff.is_Data = (APTR)&data;         /* Set up for installation of */
  43.     handlerStuff.is_Code = myhandler;          /* myhandler.                 */
  44.     handlerStuff.is_Node.ln_Pri = 51;         /* Ahead of intuition         */
  45.     inputRequestBlock->io_Command = IND_ADDHANDLER;
  46.     inputRequestBlock->io_Data    = (APTR)&handlerStuff;
  47.     DoIO((struct IORequest *)inputRequestBlock);   /* Add me. */
  48.     return;
  49. }
  50.  
  51. void RawInsert(long code,long qualifier) {
  52.     /* Set up an input request */
  53.     struct InputEvent MyNewEvent;
  54.     inputRequestBlock->io_Command = IND_WRITEEVENT;
  55.     inputRequestBlock->io_Flags   = 0L;
  56.     inputRequestBlock->io_Length  = (long)sizeof(struct InputEvent);
  57.     inputRequestBlock->io_Data    = (APTR)&MyNewEvent;
  58.     MyNewEvent.ie_Class = IECLASS_RAWKEY; 
  59.     MyNewEvent.ie_Code = code;
  60.     MyNewEvent.ie_Qualifier = qualifier;
  61.     DoIO((struct IORequest *)inputRequestBlock);
  62. }
  63.