home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / kybdctrl.zip / KYBDCTL.C next >
C/C++ Source or Header  |  1993-08-24  |  3KB  |  111 lines

  1. /*-------------------------------------------------------------------
  2.  *  KYBDCTL -- Controls the state of the Numlock, Capslock,
  3.  *             and scroll lock.
  4.  *-------------------------------------------------------------------*/
  5.  
  6. #define INCL_BASE
  7. #include <os2.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11.  
  12. main(int argc, char **argv[])
  13. {
  14.    SHIFTSTATE keyboard;
  15.    HKBD        handle;
  16.    char        option;
  17.    char        modifier;
  18.    int         count;
  19.    USHORT      rc;
  20.    char        temp[80];
  21.    BYTE        machinemode;
  22.    char far    *farbyte;
  23.  
  24.    if (argc < 2)
  25.    {
  26.       printf("KYBDCTL  -- This program is designed to change the status\n");
  27.       printf("            of the numlock, scroll lock, and capslock keys.\n");
  28.       printf("            It should run under DOS or OS/2 1.3 or above.\n");
  29.       printf(" Format:\n");
  30.       printf("   KYBDCTL {Num[+/-] Caps[+/-] Scroll[+/-]\n");
  31.       printf("   Each parameter is optional and only the first letter is required\n\n");
  32.       printf("   Example:  KYBDCTL N+ Scroll-\n");
  33.       printf("             Would turn on the Numlock, turn off the Scroll lock,\n");
  34.       printf("             and leave the Capslock alone\n");
  35.       return(1);
  36.    }
  37.  
  38.    DosGetMachineMode(&machinemode);
  39.    if (machinemode  == MODE_PROTECTED)
  40.    {
  41.       if ((rc =KbdOpen(&handle)) != 0)
  42.       {
  43.          printf("Unable to open the Keyboard\nProgram Aborts\nRC = %d\n",rc);
  44.          return(2);
  45.       }
  46.  
  47.       if ((rc = DosDevIOCtl(&keyboard, 0L, 0x0073, 0x0004, handle)) != 0)
  48.       {
  49.          printf("rc = %d\n",rc);
  50.          printf("Unable to get keyboard status\nProgram Aborts\n");;;
  51.          return(4);
  52.       }
  53.    }
  54.    else
  55.    {
  56.       farbyte = 0x400017;
  57.       keyboard.fsState = *farbyte;
  58.    }
  59.  
  60.    for (count = 1; count <argc; count ++)
  61.    {
  62.       strcpy(temp, (char *)argv[count]);
  63.       option = (char) toupper(temp[0]);
  64.       modifier = temp[strlen(temp) - 1];
  65.       if ((modifier != '+') && (modifier != '-'))
  66.       {
  67.          printf("Option must end in either + or -.\nProgram Aborting\n");
  68.          return(5);
  69.       }
  70.       switch(option)
  71.       {
  72.          case 'N':
  73.             if (modifier == '+')
  74.                keyboard.fsState = keyboard.fsState | NUMLOCK_ON;
  75.             else
  76.                keyboard.fsState = keyboard.fsState &~ NUMLOCK_ON;
  77.             break;
  78.          case 'C':
  79.             if (modifier == '+')
  80.                keyboard.fsState = keyboard.fsState | CAPSLOCK_ON;
  81.             else
  82.                keyboard.fsState = keyboard.fsState &~ CAPSLOCK_ON;
  83.             break;
  84.          case 'S':
  85.             if (modifier == '+')
  86.                keyboard.fsState = keyboard.fsState | SCROLLLOCK_ON;
  87.             else
  88.                keyboard.fsState = keyboard.fsState &~ SCROLLLOCK_ON;
  89.             break;
  90.          default:
  91.             printf("Option Must be Num, Caps, or Scroll\nProgram Aborts\n");
  92.             return(6);
  93.       }
  94.    }
  95.  
  96.  
  97.    if (machinemode  == MODE_PROTECTED)
  98.    {
  99.       if ((rc = DosDevIOCtl(0L, &keyboard, 0x0053, 0x0004, handle)) != 0)
  100.       {
  101.          printf("Unable to set status bytes\nProgram Aborts\nRc = %d\n",rc);
  102.          return(7);
  103.       }
  104.    }
  105.    else
  106.    {
  107.       memmove(farbyte, &keyboard.fsState, 1);
  108.    }
  109.    return(0);
  110. }
  111.