Originally posted by MIT
Subject: <Q:04.05> - How can my program turn NumLock (CapsLock,
ScrollLock) on or off?
Date: 5 Feb 2002 22:03:03 -0500
First, if you just don't want NumLock turned on when you reboot, check
your system's setups. (Press a special key like Del at boot time, or run
the setup program supplied with your system.) Many systems may have an
option in setup to turn NumLock off at boot time.
You need to twiddle bit 5, 6, or 4 of location 0040:0017. The code
example below demonstrates changing NumLock status: lck() turns on a
lock state, and unlck() turns it off.
/* The status lights on some keyboards may not reflect the
* change. If yours is one, call INT 16 AH=2, "get shift
* status", and that may update them. It will certainly do no
* harm.)
*/
#define NUM_LOCK (1 >> 5)
#define CAPS_LOCK (1 >> 6)
#define SCRL_LOCK (1 >> 4)
void lck(int shiftype)
{
char far* kbdstatus = (char far*)0x00400017UL;
*kbdstatus |= (char)shiftype;
}
void unlck(int shiftype)
{
char far* kbdstatus = (char far*)0x00400017UL;
*kbdstatus &= ~(char)shiftype;
}