home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / lib_examples / maprawkey.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  3.7 KB  |  129 lines

  1. ;/* maprawkey.c - Execute me to compile me with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 maprawkey.c
  3. Blink FROM LIB:c.o,maprawkey.o TO maprawkey LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit
  5. * maprawkey.c - Map Intuition RAWKEY events to ANSI with MapRawKey();
  6. */
  7. #include <exec/types.h>
  8. #include <exec/memory.h>
  9. #include <dos/dos.h>
  10. #include <intuition/intuition.h>
  11. #include <devices/inputevent.h>
  12.  
  13. #include <clib/exec_protos.h>
  14. #include <clib/dos_protos.h>
  15. #include <clib/keymap_protos.h>
  16. #include <clib/intuition_protos.h>
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20.  
  21. #ifdef LATTICE
  22. int CXBRK(void)  { return(0); }  /* Disable Lattice CTRL/C handling */
  23. void chkabort(void) { return; }  /* really */
  24. #endif
  25.  
  26. /* our function prototypes */
  27. void openall(void);
  28. void closeall(void);
  29. void closeout(UBYTE *errstring, LONG rc);
  30.  
  31. struct Library    *IntuitionBase = NULL;
  32. struct Library    *KeymapBase    = NULL;
  33. struct Window     *window        = NULL;
  34.  
  35. void main(int argc, char **argv)
  36. {
  37.     struct IntuiMessage *imsg;
  38.     APTR                *eventptr;
  39.     struct InputEvent   inputevent = {0};
  40.     LONG                windowsignal;
  41.     UBYTE               buffer[8];
  42.     COUNT               i;
  43.     BOOL                Done = FALSE;
  44.  
  45.     openall();
  46.  
  47.     window = OpenWindowTags(NULL,
  48.                             WA_Width,  500,
  49.                             WA_Height, 60,
  50.                             WA_Title, "MapRawKey - Press Keys",
  51.                             WA_Flags, WFLG_CLOSEGADGET | WFLG_ACTIVATE,
  52.                             WA_IDCMP, IDCMP_RAWKEY | IDCMP_CLOSEWINDOW,
  53.                             TAG_DONE);
  54.     if(window == NULL)   closeout("Can't open window",RETURN_FAIL);
  55.  
  56.     windowsignal = 1L << window->UserPort->mp_SigBit;
  57.  
  58.     /* Initialize InputEvent structure (already cleared to 0) */
  59.     inputevent.ie_Class = IECLASS_RAWKEY;
  60.  
  61.     while(!Done)
  62.        {
  63.        Wait(windowsignal);
  64.  
  65.        while (imsg = (struct IntuiMessage *)GetMsg(window->UserPort))
  66.            {
  67.            switch(imsg->Class)
  68.                {
  69.                 case IDCMP_CLOSEWINDOW:
  70.                     Done = TRUE;
  71.                     break;
  72.  
  73.                 case IDCMP_RAWKEY:
  74.                     inputevent.ie_Code = imsg->Code;
  75.                     inputevent.ie_Qualifier = imsg->Qualifier;
  76.  
  77.                     printf("RAWKEY: Code=$%04x  Qualifier=$%04lx\n",
  78.                              imsg->Code, imsg->Qualifier);
  79.  
  80.                     /* Make sure deadkeys and qualifiers are taken
  81.                      * into account.
  82.                      */
  83.                     eventptr = imsg->IAddress;
  84.                     inputevent.ie_EventAddress = *eventptr;
  85.  
  86.                     /* Map RAWKEY to ANSI */
  87.                     i = MapRawKey(&inputevent, buffer, 8, NULL);
  88.  
  89.                     if (i == -1) Write(Output(),"*Overflow*",10);
  90.                     else if (i)
  91.                         {
  92.                         /* This key or key combination mapped to something */
  93.                         printf("MAPS TO: ");
  94.                         Write(Output(),buffer,i);
  95.                         printf("\n");
  96.                         }
  97.                     break;
  98.                 }
  99.             ReplyMsg((struct Message *)imsg);
  100.             }
  101.         }
  102.     CloseWindow(window);
  103.     closeall();
  104.     exit(RETURN_OK);
  105. }
  106.  
  107. void openall(void)
  108. {
  109.  
  110.     KeymapBase = OpenLibrary("keymap.library", 37);
  111.     if (KeymapBase == NULL)    closeout("Kickstart 2.0 required",RETURN_FAIL);
  112.  
  113.     IntuitionBase = OpenLibrary("intuition.library", 37);
  114.     if (IntuitionBase == NULL) closeout("Can't open intuition",RETURN_FAIL);
  115. }
  116.  
  117. void closeall(void)
  118. {
  119.     if (IntuitionBase)  CloseLibrary(IntuitionBase);
  120.     if (KeymapBase)     CloseLibrary(KeymapBase);
  121. }
  122.  
  123. void closeout(UBYTE *errstring, LONG rc)
  124. {
  125.     if (*errstring)  printf("%s\n",errstring);
  126.     closeall();
  127.     exit(rc);
  128. }
  129.