Question

I'm writing a program that uses caps-lock as a toggle switch. It would be nice to set the LED of the key to show that my program is on or off, like the capslock key does naturally.

I know that I could just SendInput('Capslock'); or whatever to actually turn caps-lock on and off. But my app is a typing program, and I don't want to have to deal with translating the all-caps keys that turning it on would give me into their lower/upper cases. I might go that route eventually, but not for this version.

I would however be interested in just turning on the LED light WITHOUT actually turning on caps-lock. Is there any way to do that?

Thank you.

Was it helpful?

Solution

You can find code for changing indicators on the keyboard from C# at Faking num lock, caps lock and scroll lock leds

OTHER TIPS

I'm pretty sure you can't toggle the LED without toggling the actual Caps lock, unless you were writing a keyboard driver. (I'm not recommending that!)

There are plugin for Miranda IM named "Keyboard Notify Ext." which contains in its source code C implementation of controlling leds. See file keyboard.c in source. Probably you can port it to C#.

Here are most interesting highlights from source code:

mir_snprintf(aux1, sizeof(aux1), "Kbd%d", i);
mir_snprintf(aux2, sizeof(aux2), "\\Device\\KeyboardClass%d", i);
DefineDosDevice(DDD_RAW_TARGET_PATH, aux1, aux2);

mir_snprintf(aux1, sizeof(aux1), "\\\\.\\Kbd%d", i);
hKbdDev[i] = CreateFile(aux1, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

...

result |= DeviceIoControl(hKbdDev[i], IOCTL_KEYBOARD_SET_INDICATORS, &InputBuffer, DataLength, NULL, 0, &ReturnedLength, NULL);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top