home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / MM1 / DRIVERS / windio54.lzh / testkysns.c < prev    next >
C/C++ Source or Header  |  1995-01-31  |  4KB  |  165 lines

  1. /*
  2.  *    sample code to test _gs_kysns (windio #54)
  3.  *    requires kysns.h and cgfx.l
  4.  *
  5.  *    NOTE:  This code eats quite a bit of CPU time.
  6.  */
  7.  
  8. #include <stdio.h>
  9.  
  10. /* macros for _gs_kysns() */
  11. int _gs_kysns();
  12.  
  13. /* keys returned */
  14. #define    KS_SHIFT    (1<<0)    /* Shift key (either) */
  15. #define    KS_CTRL        (1<<1)    /* CTRL key */
  16. #define    KS_ALT        (1<<2)    /* ALT key */
  17. #define    KS_UP        (1<<3)    /* Up Arrow key */
  18. #define    KS_DOWN        (1<<4)    /* Down Arrow key */
  19. #define    KS_LEFT        (1<<5)    /* Left Arrow key */
  20. #define    KS_RIGHT    (1<<6)    /* Right Arrow key */
  21. #define    KS_SPACE    (1<<7)    /* Space key */
  22.  
  23. #define    KS_ARROW    (KS_UP | KS_DOWN | KS_RIGHT | KS_LEFT) /* Any arrow key */
  24.  
  25. #define    KS_LSHIFT    (1<<8)    /* Left Shift */
  26. #define    KS_RSHIFT    (1<<9)    /* Right Shift */
  27. #define    KS_ESC        (1<<10)    /* ESC */
  28. #define    KS_BACKSPACE    (1<<11)    /* Backspace */
  29. #define    KS_TAB        (1<<12)    /* TAB */
  30.  
  31. #define    KS_CAPSLOCK    (1<<16)    /* CAPS Lock */
  32. #define    KS_SCROLL    (1<<17)    /* Scroll Lock */
  33. #define    KS_NUMLOCK    (1<<18)    /* NUM Lock */
  34. #define    KS_KEYPAD    (1<<19)    /* Keypad Key */
  35. #define    KS_ALTKEYPAD (1<<20)    /* Alternate KeyPad Key */
  36.  
  37. #define    KS_INVALID    (1<<31)    /* is invalid for this window */
  38.  
  39. /* key test macros */
  40. #define    IS_SHIFT(x)        (x & KS_SHIFT)
  41. #define    IS_KEYPAD(x)    (x & KS_KEYPAD)
  42. #define    IS_ALTKEYPAD(x)    (x & KS_ALTKEYPAD)
  43. #define    IS_CTRL(x)        (x & KS_CTRL)
  44. #define    IS_ALT(x)        (x & KS_ALT)
  45. #define    IS_UP(x)        (x & KS_UP)
  46. #define    IS_DOWN(x)        (x & KS_DOWN)
  47. #define    IS_LEFT(x)        (x & KS_LEFT)
  48. #define    IS_RIGHT(x)        (x & KS_RIGHT)
  49. #define    IS_ARROW(x)        (x & KS_ARROW)
  50. #define    IS_SPACE(x)        (x & KS_SPACE)
  51. #define    IS_LSHIFT(x)    (x & KS_LSHIFT)
  52. #define    IS_RSHIFT(x)    (x & KS_RSHIFT)
  53. #define    IS_ESC(x)        (x & KS_ESC)
  54. #define    IS_BACKSPACE(x)    (x & KS_BACKSPACE)
  55. #define    IS_TAB(x)        (x & KS_TAB)
  56. #define    IS_CAPSLOCK(x)    (x & KS_CAPSLOCK)
  57. #define    IS_SCROLL(x)    (x & KS_SCROLL)
  58. #define    IS_NUMLOCK(x)    (x & KS_NUMLOCK)
  59. #define    IS_INVALID(x)    (x & KS_INVALID)
  60. #define    IS_VALID(x)        !IS_INVALID(x)
  61. #define    IS_NOKEY(x)        !(x & ~(KS_INVALID))
  62.  
  63.  
  64. main()
  65. {
  66.     int key;
  67.     char c;
  68.  
  69.     for (;;) {
  70.         tsleep(20);        /* sleep a bit */
  71.         if (_gs_kysns(1, &key) == -1) {
  72.             printf("This call requires windio #54 or greater!\n");
  73.             exit(0);
  74.         } else {
  75.             if (IS_INVALID(key)) {    /* invalid */
  76.                 /* go back to sleep */
  77.                 continue;
  78.             }
  79.             if (IS_KEYPAD(key)) {    /* keypad key down? */
  80.                 printf("KeyPAD ");
  81.             }
  82.             if (IS_ALTKEYPAD(key)) {    /* alternate keypad key down? */
  83.                 printf("AltKeyPAD ");
  84.             }
  85.             if (IS_LEFT(key)) {        /* left key down? */
  86.                 printf("Left  ");
  87.             }
  88.             if (IS_RIGHT(key)) {        /* right key down? */
  89.                 printf("Right  ");
  90.             }
  91.             if (IS_UP(key)) {        /* up key down? */
  92.                 printf("Up  ");
  93.             }
  94.             if (IS_DOWN(key)) {        /* down key down? */
  95.                 printf("Down  ");
  96.             }
  97.             if (IS_SPACE(key)) {    /* space key down? */
  98.                 printf("Space  ");
  99.             }
  100.             if (IS_SHIFT(key)) {    /* either shift down? */
  101.                 printf("Shift  ");
  102.             }
  103.             if (IS_LSHIFT(key)) {    /* left shift down? */
  104.                 printf("LShift  ");
  105.             }
  106.             if (IS_RSHIFT(key)) {    /* right shift down? */
  107.                 printf("RShift  ");
  108.             }
  109.             if (IS_CTRL(key)) {        /* ctrl down? */
  110.                 printf("CTRL  ");
  111.             }
  112.             if (IS_ALT(key)) {        /* alt down? */
  113.                 printf("ALT  ");
  114.             }
  115.             if (IS_ESC(key)) {        /* esc down? */
  116.                 printf("ESC  ");
  117.             }
  118.             if (IS_BACKSPACE(key)) {    /* backspace down? */
  119.                 printf("BACKSPACE ");
  120.             }
  121.             if (IS_TAB(key)) {            /* tab key down? */
  122.                 printf("TAB ");
  123.             }
  124.             if (IS_CAPSLOCK(key)) {    /* capslock down? */
  125.                 printf("CAPS Lock  ");
  126.             }
  127.             if (IS_SCROLL(key)) {    /* capslock down? */
  128.                 printf("SCROLL Lock  ");
  129.             }
  130.             if (IS_NUMLOCK(key)) {    /* num lock down? */
  131.                 printf("NUM Lock  ");
  132.             }
  133.             if (!IS_NOKEY(key)) {    /* no key down? */
  134.                 printf("\n");
  135.             }
  136.         }
  137.     }
  138. }
  139.  
  140.  
  141. #include <types.h>
  142. #include <machine/reg.h>
  143. #define    DS_KySns 173
  144. #define I_SetStt 0x8e
  145. #define I_GetStt 0x8d
  146.  
  147.  
  148. _gs_kysns(path, key)
  149. int             path,               /* Path to window */
  150.                 *key;
  151. {
  152.     REGISTERS reg;
  153.  
  154.     reg.d[0] = path;
  155.     reg.d[1] = DS_KySns;
  156.  
  157.     if (_osk(I_GetStt,®) == -1) {
  158.         return(-1);
  159.     }
  160.  
  161.     *key = reg.d[0];
  162.     return(0);
  163. }
  164.  
  165.