home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / c / rkrm / keymap / maprawkey.c < prev   
C/C++ Source or Header  |  1992-09-03  |  5KB  |  158 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. */
  6.  
  7. /*
  8. Copyright (c) 1992 Commodore-Amiga, Inc.
  9.  
  10. This example is provided in electronic form by Commodore-Amiga, Inc. for
  11. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  12. published by Addison-Wesley (ISBN 0-201-56774-1).
  13.  
  14. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  15. information on the correct usage of the techniques and operating system
  16. functions presented in these examples.  The source and executable code
  17. of these examples may only be distributed in free electronic form, via
  18. bulletin board or as part of a fully non-commercial and freely
  19. redistributable diskette.  Both the source and executable code (including
  20. comments) must be included, without modification, in any copy.  This
  21. example may not be published in printed form or distributed with any
  22. commercial product.  However, the programming techniques and support
  23. routines set forth in these examples may be used in the development
  24. of original executable software products for Commodore Amiga computers.
  25.  
  26. All other rights reserved.
  27.  
  28. This example is provided "as-is" and is subject to change; no
  29. warranties are made.  All use is at your own risk. No liability or
  30. responsibility is assumed.
  31. */
  32.  
  33. /*
  34. * maprawkey.c - Map Intuition RAWKEY events to ANSI with MapRawKey();
  35. */
  36. #include <exec/types.h>
  37. #include <exec/memory.h>
  38. #include <dos/dos.h>
  39. #include <intuition/intuition.h>
  40. #include <devices/inputevent.h>
  41.  
  42. #include <clib/exec_protos.h>
  43. #include <clib/dos_protos.h>
  44. #include <clib/keymap_protos.h>
  45. #include <clib/intuition_protos.h>
  46.  
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49.  
  50. #ifdef LATTICE
  51. int CXBRK(void)  { return(0); }  /* Disable Lattice CTRL/C handling */
  52. void chkabort(void) { return; }  /* really */
  53. #endif
  54.  
  55. /* our function prototypes */
  56. void openall(void);
  57. void closeall(void);
  58. void closeout(UBYTE *errstring, LONG rc);
  59.  
  60. struct Library    *IntuitionBase = NULL;
  61. struct Library    *KeymapBase    = NULL;
  62. struct Window     *window        = NULL;
  63.  
  64. void main(int argc, char **argv)
  65. {
  66.     struct IntuiMessage *imsg;
  67.     APTR                *eventptr;
  68.     struct InputEvent   inputevent = {0};
  69.     LONG                windowsignal;
  70.     UBYTE               buffer[8];
  71.     COUNT               i;
  72.     BOOL                Done = FALSE;
  73.  
  74.     openall();
  75.  
  76.     window = OpenWindowTags(NULL,
  77.                             WA_Width,  500,
  78.                             WA_Height, 60,
  79.                             WA_Title, "MapRawKey - Press Keys",
  80.                             WA_Flags, WFLG_CLOSEGADGET | WFLG_ACTIVATE,
  81.                             WA_IDCMP, IDCMP_RAWKEY | IDCMP_CLOSEWINDOW,
  82.                             TAG_DONE);
  83.     if(window == NULL)   closeout("Can't open window",RETURN_FAIL);
  84.  
  85.     windowsignal = 1L << window->UserPort->mp_SigBit;
  86.  
  87.     /* Initialize InputEvent structure (already cleared to 0) */
  88.     inputevent.ie_Class = IECLASS_RAWKEY;
  89.  
  90.     while(!Done)
  91.        {
  92.        Wait(windowsignal);
  93.  
  94.        while (imsg = (struct IntuiMessage *)GetMsg(window->UserPort))
  95.            {
  96.            switch(imsg->Class)
  97.                {
  98.                 case IDCMP_CLOSEWINDOW:
  99.                     Done = TRUE;
  100.                     break;
  101.  
  102.                 case IDCMP_RAWKEY:
  103.                     inputevent.ie_Code = imsg->Code;
  104.                     inputevent.ie_Qualifier = imsg->Qualifier;
  105.  
  106.                     printf("RAWKEY: Code=$%04x  Qualifier=$%04lx\n",
  107.                              imsg->Code, imsg->Qualifier);
  108.  
  109.                     /* Make sure deadkeys and qualifiers are taken
  110.                      * into account.
  111.                      */
  112.                     eventptr = imsg->IAddress;
  113.                     inputevent.ie_EventAddress = *eventptr;
  114.  
  115.                     /* Map RAWKEY to ANSI */
  116.                     i = MapRawKey(&inputevent, buffer, 8, NULL);
  117.  
  118.                     if (i == -1) Write(Output(),"*Overflow*",10);
  119.                     else if (i)
  120.                         {
  121.                         /* This key or key combination mapped to something */
  122.                         printf("MAPS TO: ");
  123.                         Write(Output(),buffer,i);
  124.                         printf("\n");
  125.                         }
  126.                     break;
  127.                 }
  128.             ReplyMsg((struct Message *)imsg);
  129.             }
  130.         }
  131.     CloseWindow(window);
  132.     closeall();
  133.     exit(RETURN_OK);
  134. }
  135.  
  136. void openall(void)
  137. {
  138.  
  139.     KeymapBase = OpenLibrary("keymap.library", 37);
  140.     if (KeymapBase == NULL)    closeout("Kickstart 2.0 required",RETURN_FAIL);
  141.  
  142.     IntuitionBase = OpenLibrary("intuition.library", 37);
  143.     if (IntuitionBase == NULL) closeout("Can't open intuition",RETURN_FAIL);
  144. }
  145.  
  146. void closeall(void)
  147. {
  148.     if (IntuitionBase)  CloseLibrary(IntuitionBase);
  149.     if (KeymapBase)     CloseLibrary(KeymapBase);
  150. }
  151.  
  152. void closeout(UBYTE *errstring, LONG rc)
  153. {
  154.     if (*errstring)  printf("%s\n",errstring);
  155.     closeall();
  156.     exit(rc);
  157. }
  158.