home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / d / diskeys.zip / DISKEYS.C next >
C/C++ Source or Header  |  1992-01-23  |  4KB  |  126 lines

  1. /*
  2.            Displays key codes when they are pressed.
  3.         Displays key combinations such as <CTL F1>, etc.
  4.      Uses BIOS call for Enhanced or Standard style keyboard.
  5.               ESC key ends the program.
  6.  
  7.      ----------------------------------------------------------------
  8. */
  9.  
  10. #include <conio.h>
  11. #include <string.h>
  12. #include <bios.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15.  
  16.  unsigned returnval;
  17.  char decval[2];
  18.  unsigned hibyte;
  19.  unsigned lobyte;
  20.  char flag;
  21.  char lockstat[40];
  22.  char blanks[40];
  23.  union REGS in,out;
  24.  
  25. /*--------------------------------------------------------------------*/
  26.  
  27. main()
  28.  {
  29.       in.h.ah=0;
  30.       in.h.al=3;
  31.    int86(0x10,&in,&out);                  /*Set video mode 80x25 color*/
  32.       in.h.ah=5;
  33.       in.h.al=0;
  34.    int86(0x10,&in,&out);                  /*Set active video page*/
  35.       in.h.ah=6;
  36.       in.h.al=0;
  37.       in.h.bh=0x08;
  38.       in.h.ch=0;
  39.       in.h.cl=0;
  40.       in.h.dh=24;
  41.       in.h.dl=79;
  42.    int86(0x10,&in,&out);                  /*Blank entire screen*/
  43.       in.h.ah=2;
  44.       in.h.dh=1;
  45.       in.h.dl=3;
  46.       in.h.bh=0;
  47.    int86(0x10,&in,&out);                  /*Set cursor to row-1,col-3 */
  48.       in.h.ah=9;
  49.       in.h.al=205;                        /*double horizontal bar */
  50.       in.h.bh=0;
  51.       in.h.bl=0x0c;                       /*Attrib: bright red */
  52.       in.x.cx=74;
  53.    int86(0x10,&in,&out);                  /*Display chars*/
  54.       in.h.ah=2;
  55.       in.h.dh=5;
  56.       in.h.dl=3;
  57.       in.h.bh=0;
  58.    int86(0x10,&in,&out);                  /*Set cursor to row-5,col-3 */
  59.       in.h.ah=9;
  60.       in.h.al=205;                        /*double horizontal bar */
  61.       in.h.bh=0;
  62.       in.h.bl=0x0c;                       /*Attrib: bright red */
  63.       in.x.cx=74;
  64.    int86(0x10,&in,&out);                  /*Display chars*/
  65.       in.h.ah=2;
  66.       in.h.dh=2;
  67.       in.h.dl=8;
  68.       in.h.bh=0;
  69.    int86(0x10,&in,&out);                  /*Set cursor to row-2,col-8 */
  70.    puts("Displays keyboard scan codes            (C)1991, George Rogozin.");
  71.    puts("        Press a key or key combination - press <ESC> to quit.");
  72.    cputs("        Enhanced or Standard keyboard (E/s)? ");
  73.    flag=getche();
  74.       in.h.ah=2;
  75.       in.h.dh=7;
  76.       in.h.dl=3;
  77.       in.h.bh=0;
  78.    int86(0x10,&in,&out);                  /*Set cursor to row-7,col-3 */
  79.    if(flag!='s' && flag!='S')
  80.       flag='e';                                  /* Set keyboard default */
  81.    do
  82.     {
  83.       strcpy(lockstat,blanks);                   /* Clear lockstat area */
  84.       if(flag=='e')
  85.        returnval=_bios_keybrd(_NKEYBRD_READ); /* enhanced board */
  86.       else returnval=_bios_keybrd(_KEYBRD_READ); /* standard board */
  87.       hibyte=0xff00 & returnval;                 /* Isolate scan code    */
  88.       hibyte=hibyte>>8;
  89.       lobyte=0x00ff & returnval;                 /* Isolate ASCII code   */
  90.       ultoa(lobyte,decval,10);                   /* Convert to string    */
  91.       if(flag=='e')
  92.        returnval=_bios_keybrd(_NKEYBRD_SHIFTSTATUS); /* enhanced board */
  93.       else returnval=_bios_keybrd(_KEYBRD_SHIFTSTATUS);  /* standard board */
  94.     in.h.ah=6;
  95.     in.h.al=0;
  96.     in.h.bh=0x08;
  97.     in.h.ch=7;
  98.     in.h.cl=0;
  99.     in.h.dh=25;
  100.     in.h.dl=79;
  101.       int86(0x10,&in,&out);              /*Scroll up to clear data area */
  102.     in.h.ah=2;
  103.     in.h.dh=7;
  104.     in.h.dl=3;
  105.     in.h.bh=0;
  106.       int86(0x10,&in,&out);              /*Set cursor to row-7,col-3 */
  107.       printf("\n   Shift status value in hex:  %.4X       ",returnval);
  108.       if(0x0010 & returnval) strcat(lockstat,"SCROLL LOCK   ");
  109.       if(0x0020 & returnval) strcat(lockstat,"NUM LOCK   ");
  110.       if(0x0040 & returnval) strcat(lockstat,"CAPS LOCK   ");
  111.       puts(lockstat);
  112.       printf("   Scan code value in hex:  %.2X\n",hibyte);
  113.       printf("   ASCII key value in hex:  %.2X\n",lobyte);
  114.       printf("   ASCII key value in dec:  %s\n",decval);
  115.       printf("   ASCII printable char:  %c\n",lobyte);
  116.     }
  117.    while (lobyte!=0x1B);                         /* Test for <ESC> */
  118.       in.h.ah=2;
  119.       in.h.dh=14;
  120.       in.h.dl=0;
  121.       in.h.bh=0;
  122.    int86(0x10,&in,&out);                      /*Set cursor at row 14 */
  123.  }
  124.  
  125.  
  126.