home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol9n04.zip / KEYTEST.C < prev    next >
Text File  |  1990-01-22  |  1KB  |  83 lines

  1.  
  2. /* keytest.c */
  3. #define MSC
  4.  
  5. #include<conio.h>
  6. #include<stdio.h>
  7.  
  8. #if    !defined(TRUE)
  9. #define TRUE 1
  10. #endif
  11.  
  12. #define    SCANCODE(value)        (value | 0x100)
  13. #define IsScan(value)        (value & 0x100)
  14. #define    NoScan(value)        (value & ~0x100)
  15.  
  16. #define CTL(value)          (value-'A'+1)
  17. #define HOME                SCANCODE(71)
  18. #define END                 SCANCODE(79)
  19. #define PGUP                SCANCODE(73)
  20. #define PGDN                SCANCODE(81)
  21.  
  22.  
  23. void main(void);
  24. int inkey(void);
  25.  
  26. void main(void)
  27.     {
  28.  
  29.     int c;
  30.  
  31.     while(TRUE)
  32.         {
  33.         c = inkey();
  34.         if(IsScan(c))
  35.             printf("%d received for scan code %d\n",c,NoScan(c));
  36.         else
  37.             printf("%c = %d\n",c,c);
  38.         if(c == CTL('C'))
  39.             break;
  40.         switch(c)
  41.             {
  42.             case HOME:
  43.                 printf("HOME pressed\n");
  44.                 break;
  45.             case END:
  46.                 printf("END pressed\n");
  47.                 break;
  48.             case PGUP:
  49.                 printf("PGUP pressed\n");
  50.                 break;
  51.             case PGDN:
  52.                 printf("PGDN pressed\n");
  53.                 break;
  54.             }
  55.         }
  56.     }
  57.  
  58.  
  59. int inkey(void)
  60.     {
  61. #if defined(TC)
  62.     _AH = 0;
  63.     asm int 16h
  64.     if(!_AL)
  65.         return SCANCODE(_AH);
  66.     return _AL;
  67. #endif
  68.  
  69. #if defined(MSC)
  70. #include<dos.h>
  71.  
  72.     union REGS r;
  73.  
  74.     r.h.ah = 0;
  75.     int86(0x16,&r,&r);
  76.     if(!r.h.al)
  77.         return SCANCODE(r.h.ah);
  78.     return r.h.al;
  79. #endif
  80.     }
  81.  
  82.  
  83.