home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / NCS.ZIP / NCS.C < prev    next >
C/C++ Source or Header  |  1991-05-15  |  3KB  |  96 lines

  1. /*-----------------------------------------------------------------------------
  2.  
  3.     NCS.EXE        A program to turn the Num/Caps/Scroll Lock keyboard flags
  4.                 on or off.
  5.  
  6.                 This is a bound program which works in an OS/2 full screen
  7.                 session, an OS/2 DOS session or under ordinary MSDOS.
  8.  
  9.     A public-domain program by Jon Saxton, May 1991
  10.  
  11. -----------------------------------------------------------------------------*/
  12.  
  13.  
  14.  
  15. #define INCL_BASE
  16. #include <os2.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19.  
  20. /* Some versions of BSESUB.H don't #define all the fsState field values */
  21. #ifndef KEYBOARD_MODIFY_STATE
  22. #define KEYBOARD_MODIFY_STATE 0x0010
  23. #endif
  24.  
  25. USHORT
  26.     fsStateMask[] = {NUMLOCK_ON, CAPSLOCK_ON, SCROLLLOCK_ON};
  27.  
  28. VOID usage(void)
  29. {
  30.     static CHAR
  31.         msg[] =
  32. "\n"
  33. "NCS stands for 'Num Lock  Caps Lock  Scroll Lock' and is used to set or clear\n"
  34. "those keyboard flags.  NCS takes one parameter exactly three characters long\n"
  35. "comprising any combination of '+', '-' and/or '='.  A plus sets a keyboard\n"
  36. "flag, a minus clears it and an equal sign leaves it in its current condition.\n"
  37. "The first character in the parameter affects the Num Lock flag, the second\n"
  38. "affects the Caps Lock flag and the third affects the Scroll Lock flag.  The\n"
  39. "name of the program, NCS, serves as a convenient mnemonic for the ordering of\n"
  40. "the flags in the parameter.\n\n"
  41. "Example:    ncs +-=\n"
  42. "\t\tsets Num Lock,\n"
  43. "\t\tclears Caps Lock and\n"
  44. "\t\tleaves Scroll Lock unchanged\n"
  45. "\nA public domain program by Jon Saxton, May 1991\n";
  46.  
  47.     puts(msg);
  48. }
  49.  
  50. VOID main(SHORT argc, CHAR *argv[])
  51. {
  52.     USHORT
  53.         usIndex;
  54.     KBDINFO
  55.         KbdInfo;
  56.     static CHAR
  57.         on[] = "on",
  58.         off[] = "off";
  59.     CHAR
  60.         *n, *c, *s;
  61.  
  62.     if (argc < 2 || strspn(argv[1],"-+=") != 3)
  63.         usage();
  64.     else
  65.     {
  66.         KbdGetStatus(&KbdInfo, 0);
  67.  
  68.         for (usIndex=0; usIndex < 3; ++usIndex)
  69.             switch (argv[1][usIndex])
  70.             {
  71.     case '-':
  72.                 KbdInfo.fsState &= ~fsStateMask[usIndex];
  73.                 break;
  74.     case '+':
  75.                 KbdInfo.fsState |=  fsStateMask[usIndex];
  76.                 break;
  77.             }
  78.  
  79.         KbdInfo.fsMask |= KEYBOARD_MODIFY_STATE;
  80.         if (usIndex = KbdSetStatus(&KbdInfo, 0))
  81.             printf("\nKbdSetStatus() error %u\n", usIndex);
  82.  
  83.         KbdGetStatus(&KbdInfo, 0);
  84.  
  85.         n = KbdInfo.fsState & NUMLOCK_ON ? on : off;
  86.         c = KbdInfo.fsState & CAPSLOCK_ON ? on : off;
  87.         s = KbdInfo.fsState & SCROLLLOCK_ON ? on : off;
  88.  
  89.         printf("\nKeyboard status:\n"
  90.                        "\tNum Lock:\t%s\n"
  91.                        "\t\Caps Lock:\t%s\n"
  92.                        "\tScroll Lock:\t%s\n",
  93.                     n, c, s);
  94.     }
  95. }
  96.