home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff291.lzh / Keyboard / RawDemo.c < prev    next >
C/C++ Source or Header  |  1989-12-12  |  5KB  |  150 lines

  1. /* RawDemo.c
  2.  
  3.    by Fabbian G. Dufoe, III
  4.    This is a public domain program.  You may use it any way you want.
  5.  
  6.    This program demonstrates the use of the OpenReadConsole(), ReadKey(),
  7.    and CloseReadConsole() functions in Keyboard.c
  8. */
  9.  
  10. #include "keyboard.h"
  11.  
  12. #define VERSION 34L
  13.  
  14. struct IntuiText IText1 =
  15. {
  16.    1, 0, JAM1, 4, 12,
  17.    NULL,
  18.    "Type some keys.",
  19.    NULL
  20. };
  21.  
  22. struct NewWindow NewWindow =
  23. {
  24.    0, 10,            /* SHORT LeftEdge, TopEdge, */
  25.    550, 190,         /* SHORT Width, Height, */
  26.    0, 1,             /* UBYTE DetailPen, BlockPen, */
  27.    CLOSEWINDOW | RAWKEY | MOUSEBUTTONS,
  28.                      /* ULONG IDCMPFlags, */
  29.    WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | WINDOWSIZING |
  30.    ACTIVATE | SMART_REFRESH,
  31.                      /* ULONG Flags, */
  32.    NULL,             /* struct Gadget *FirstGadget, */
  33.    NULL,             /* struct Image *CheckMark, */
  34.    "RawDemo",
  35.                      /* UBYTE *Title, */
  36.    NULL,             /* struct Screen *Screen, */
  37.    NULL,             /* struct BitMap *BitMap, */
  38.    10, 10,           /* SHORT MinWidth, MinHeight, */
  39.    640, 400,         /* USHORT MaxWidth, MaxHeight, */
  40.    WBENCHSCREEN      /* USHORT Type, */
  41. };
  42.  
  43. void
  44. main()
  45. {
  46.    int error = 30;
  47.    struct IntuiMessage *IMessage;
  48.    ULONG IMessageClass;
  49.    extern struct IntuitionBase *IntuitionBase;
  50.    void PrintKey(struct IntuiMessage *);
  51.    struct Window *Window;
  52.  
  53.  
  54.    IntuitionBase = (struct IntuitionBase *)
  55.                    OpenLibrary("intuition.library", VERSION);
  56.    if (IntuitionBase)
  57.    {
  58.       if (OpenReadConsole() == 0)
  59.       {
  60.          if (Window = (struct Window *)OpenWindow(&NewWindow))
  61.          {
  62.             PrintIText(Window->RPort, &IText1, 0, 0);
  63.             do
  64.             {
  65.                Wait(1<<Window->UserPort->mp_SigBit);
  66.                while ((IMessage = (struct IntuiMessage *)
  67.                                   GetMsg(Window->UserPort)) != NULL)
  68.                {
  69.                   switch (IMessage->Class)
  70.                   {
  71.                   case CLOSEWINDOW:
  72.                      break;
  73.                   case RAWKEY:
  74.                      PrintKey(IMessage);
  75.                      break;
  76.                   case MOUSEBUTTONS:
  77.                      printf("Mouse X: %d\tY: %d\n",
  78.                              IMessage->MouseX,
  79.                              IMessage->MouseY);
  80.                      break;
  81.                   }
  82.                   IMessageClass = IMessage->Class;
  83.                   ReplyMsg(IMessage);
  84.                }
  85.             }
  86.             while (IMessageClass != CLOSEWINDOW);
  87.             CloseWindow(Window);
  88.          }
  89.          else
  90.             printf("OpenWindow() failed.\n");
  91.          CloseReadConsole();
  92.       }
  93.       else
  94.          printf("OpenReadConsole() failed.\n");
  95.       CloseLibrary(IntuitionBase);
  96.    }
  97.    else
  98.       printf("OpenLibrary() failed for intuition.library.\n");
  99.    exit(error);
  100. }
  101.  
  102.  
  103. void
  104. PrintKey(struct IntuiMessage *IMessage)
  105. {
  106.    char Key;
  107.    unsigned short int KeyID;
  108.  
  109.    Key = ReadKey(IMessage, &KeyID, NULL);
  110.    if (Key == -1 || Key == -2)
  111.       return;
  112.    if (Key != 0)
  113.       printf("Key: %c\n", Key);
  114.    else
  115.    {
  116.       switch (KeyID)
  117.       {
  118.       case K_UP:        printf("K_UP\n");       break;
  119.       case K_DOWN:      printf("K_DOWN\n");     break;
  120.       case K_RIGHT:     printf("K_RIGHT\n");    break;
  121.       case K_LEFT:      printf("K_LEFT\n");     break;
  122.       case K_S_UP:      printf("K_S_UP\n");     break;
  123.       case K_S_DOWN:    printf("K_S_DOWN\n");   break;
  124.       case K_S_RIGHT:   printf("K_S_RIGHT\n");  break;
  125.       case K_S_LEFT:    printf("K_S_LEFT\n");   break;
  126.       case K_HELP:      printf("K_HELP\n");     break;
  127.       case K_F1:        printf("K_F1\n");       break;
  128.       case K_F2:        printf("K_F2\n");       break;
  129.       case K_F3:        printf("K_F3\n");       break;
  130.       case K_F4:        printf("K_F4\n");       break;
  131.       case K_F5:        printf("K_F5\n");       break;
  132.       case K_F6:        printf("K_F6\n");       break;
  133.       case K_F7:        printf("K_F7\n");       break;
  134.       case K_F8:        printf("K_F8\n");       break;
  135.       case K_F9:        printf("K_F9\n");       break;
  136.       case K_F10:       printf("K_F10\n");      break;
  137.       case K_S_F1:      printf("K_S_F1\n");     break;
  138.       case K_S_F2:      printf("K_S_F2\n");     break;
  139.       case K_S_F3:      printf("K_S_F3\n");     break;
  140.       case K_S_F4:      printf("K_S_F4\n");     break;
  141.       case K_S_F5:      printf("K_S_F5\n");     break;
  142.       case K_S_F6:      printf("K_S_F6\n");     break;
  143.       case K_S_F7:      printf("K_S_F7\n");     break;
  144.       case K_S_F8:      printf("K_S_F8\n");     break;
  145.       case K_S_F9:      printf("K_S_F9\n");     break;
  146.       case K_S_F10:     printf("K_S_F10\n");    break;
  147.       }
  148.    }
  149. }
  150.