home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
NCS.ZIP
/
NCS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-05-15
|
3KB
|
96 lines
/*-----------------------------------------------------------------------------
NCS.EXE A program to turn the Num/Caps/Scroll Lock keyboard flags
on or off.
This is a bound program which works in an OS/2 full screen
session, an OS/2 DOS session or under ordinary MSDOS.
A public-domain program by Jon Saxton, May 1991
-----------------------------------------------------------------------------*/
#define INCL_BASE
#include <os2.h>
#include <stdio.h>
#include <string.h>
/* Some versions of BSESUB.H don't #define all the fsState field values */
#ifndef KEYBOARD_MODIFY_STATE
#define KEYBOARD_MODIFY_STATE 0x0010
#endif
USHORT
fsStateMask[] = {NUMLOCK_ON, CAPSLOCK_ON, SCROLLLOCK_ON};
VOID usage(void)
{
static CHAR
msg[] =
"\n"
"NCS stands for 'Num Lock Caps Lock Scroll Lock' and is used to set or clear\n"
"those keyboard flags. NCS takes one parameter exactly three characters long\n"
"comprising any combination of '+', '-' and/or '='. A plus sets a keyboard\n"
"flag, a minus clears it and an equal sign leaves it in its current condition.\n"
"The first character in the parameter affects the Num Lock flag, the second\n"
"affects the Caps Lock flag and the third affects the Scroll Lock flag. The\n"
"name of the program, NCS, serves as a convenient mnemonic for the ordering of\n"
"the flags in the parameter.\n\n"
"Example: ncs +-=\n"
"\t\tsets Num Lock,\n"
"\t\tclears Caps Lock and\n"
"\t\tleaves Scroll Lock unchanged\n"
"\nA public domain program by Jon Saxton, May 1991\n";
puts(msg);
}
VOID main(SHORT argc, CHAR *argv[])
{
USHORT
usIndex;
KBDINFO
KbdInfo;
static CHAR
on[] = "on",
off[] = "off";
CHAR
*n, *c, *s;
if (argc < 2 || strspn(argv[1],"-+=") != 3)
usage();
else
{
KbdGetStatus(&KbdInfo, 0);
for (usIndex=0; usIndex < 3; ++usIndex)
switch (argv[1][usIndex])
{
case '-':
KbdInfo.fsState &= ~fsStateMask[usIndex];
break;
case '+':
KbdInfo.fsState |= fsStateMask[usIndex];
break;
}
KbdInfo.fsMask |= KEYBOARD_MODIFY_STATE;
if (usIndex = KbdSetStatus(&KbdInfo, 0))
printf("\nKbdSetStatus() error %u\n", usIndex);
KbdGetStatus(&KbdInfo, 0);
n = KbdInfo.fsState & NUMLOCK_ON ? on : off;
c = KbdInfo.fsState & CAPSLOCK_ON ? on : off;
s = KbdInfo.fsState & SCROLLLOCK_ON ? on : off;
printf("\nKeyboard status:\n"
"\tNum Lock:\t%s\n"
"\t\Caps Lock:\t%s\n"
"\tScroll Lock:\t%s\n",
n, c, s);
}
}