home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / nieuûytki / pckeybhack / bonus / simplehandler.c < prev    next >
C/C++ Source or Header  |  1996-06-08  |  4KB  |  166 lines

  1. /* Handler qui intercepte les codes rawkey 75 a 7c */
  2.  
  3. #include <stdlib.h>
  4.  
  5. #include <exec/types.h>
  6. #include <exec/memory.h>
  7. #include <devices/input.h>
  8. #include <intuition/intuition.h>
  9. #include <devices/inputevent.h>
  10. #include <clib/all_protos.h>
  11.  
  12. UBYTE NameString[]="Permutation";
  13.  
  14. struct NewWindow mywin={0,0,124,15,0,1,CLOSEWINDOW,
  15.             WINDOWDRAG|WINDOWCLOSE|SIMPLE_REFRESH|NOCAREREFRESH,
  16.             NULL,NULL,NameString,NULL,NULL,0,0,0,0,WBENCHSCREEN};
  17.  
  18.  
  19.  
  20. extern struct IntuitionBase *IntuitionBase;
  21.  
  22. struct InputEvent *interceptRawKey( __A0 struct InputEvent *, __A1 APTR );
  23.  
  24.  
  25. /*
  26.  * Cette routine ouvre une fenêtre est attend le seul évènement possible
  27.  * (CLOSEWINDOW). C'est simplement pour que l'utilisateur puisse jouer avec
  28.  * les touches, et, quitter le programmme en cliquant...
  29.  */
  30.  
  31. VOID WaitForUser(VOID)
  32. {
  33. struct Window  *win;
  34.  
  35.     if (IntuitionBase=(struct IntuitionBase *)
  36.                     OpenLibrary("intuition.library",0L))
  37.     {
  38.     if (win=OpenWindow(&mywin))
  39.     {
  40.         WaitPort(win->UserPort);
  41.         ReplyMsg(GetMsg(win->UserPort));
  42.  
  43.         CloseWindow(win);
  44.     }
  45.     CloseLibrary((struct Library *)IntuitionBase);
  46.     }
  47. }
  48.  
  49. /*
  50.     Routine handler qui intercepte certains codes Raw pour les changer par d'autres
  51.     Cette routine récupère les paramètres:
  52.     even list dans A0
  53.     is_data   dans A1
  54.     ET NON PAS DANS LA PILE !!!!!!
  55. */
  56.  
  57.  
  58. struct InputEvent *interceptRawKey( inputPasse, data )
  59. __A0 struct InputEvent *inputPasse;
  60. __A1 APTR data;
  61. {
  62.  
  63.     struct InputEvent *inputDonne;
  64.  
  65.     /*
  66.     On peut recevoir une liste input event. Alors on entâme une boucle
  67.     pour scruter cette liste. Cette liste étant unidirectionnelle, le
  68.     chaînage ce fait uniquement a l'aide de ie_NextEvent.
  69.     Le champ is_data n'est ici pas utilisé.
  70.     */
  71.     inputDonne = inputPasse;
  72.     do
  73.     {
  74.  
  75.       /* Permutation subtile voir inputEvent.h ! */
  76.  
  77.     if ( inputDonne->ie_Class == IECLASS_RAWKEY )
  78.     {
  79.         switch(inputDonne->ie_Code)
  80.         {
  81.             /* home devient 5 ... etc */
  82.             case 0x75 : inputDonne->ie_Code = 0x2e;
  83.             break;
  84.             case 0x76 : inputDonne->ie_Code = 0x2f;
  85.             break;
  86.             case 0x77 : inputDonne->ie_Code = 0x3d;
  87.             break;
  88.             case 0x78 : inputDonne->ie_Code = 0x3e;
  89.             break;
  90.             case 0x79 : inputDonne->ie_Code = 0x3f;
  91.             break;
  92.             case 0x7a : inputDonne->ie_Code = 0x10;
  93.             break;
  94.             case 0x7b : inputDonne->ie_Code = 0x35;
  95.             break;
  96.             case 0x7c : inputDonne->ie_Code = 0x33;
  97.  
  98.         }
  99.     }
  100.  
  101.         /* Y-a-t-il un autre input event ? */
  102.  
  103.     if ( inputDonne->ie_NextEvent != NULL )
  104.         inputDonne = inputDonne->ie_NextEvent;
  105.     else
  106.         break;
  107.  
  108.     } while ( 1 ) ;
  109.  
  110.  
  111.     /* Permet de passer l'input event aux autres handler */
  112.     return (inputPasse);
  113. }
  114.  
  115.  
  116. main(void)
  117. {
  118. struct IOStdReq  *inputReqBlk;
  119. struct MsgPort     *inputPort;
  120. struct Interrupt *inputHandler;
  121. APTR donnees;
  122.  
  123.     if (inputPort = CreatePort(NULL,0L))
  124.     {
  125.         if (inputHandler = AllocMem( sizeof(struct Interrupt),
  126.                             MEMF_PUBLIC|MEMF_CLEAR))
  127.         {
  128.             if (inputReqBlk = (struct IOStdReq *)CreateExtIO(inputPort,
  129.                           sizeof(struct IOStdReq)))
  130.             {
  131.                 if (!OpenDevice( "input.device", 0L,
  132.                  (struct IORequest *)inputReqBlk, 0L ))
  133.                 {
  134.                     inputHandler->is_Code      = interceptRawKey;
  135.                     inputHandler->is_Data      = donnees;
  136.                     inputHandler->is_Node.ln_Pri  = 51;
  137.                     inputHandler->is_Node.ln_Name = NameString;
  138.  
  139.                     /* Mise en place du handler */
  140.  
  141.                     inputReqBlk->io_Data    = (APTR)inputHandler;
  142.                     inputReqBlk->io_Command = IND_ADDHANDLER;
  143.  
  144.                     DoIO( (struct IORequest *)inputReqBlk );
  145.  
  146.                     WaitForUser();
  147.  
  148.                        /* Supprime le handler */
  149.  
  150.                     inputReqBlk->io_Data    = (APTR)inputHandler;
  151.                     inputReqBlk->io_Command = IND_REMHANDLER;
  152.  
  153.                     DoIO( (struct IORequest *)inputReqBlk );
  154.  
  155.                     CloseDevice( (struct IORequest *)inputReqBlk );
  156.                 }
  157.                 DeleteExtIO( (struct IORequest *)inputReqBlk );
  158.             }
  159.             FreeMem( inputHandler,sizeof(struct Interrupt) );
  160.         }
  161.         DeletePort( inputPort );
  162.     }
  163.     exit(0);
  164. }
  165.  
  166.