views:

536

answers:

2

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.

+2  A: 

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!)

Scott P
He should build a hardware peripheral that ships with the software. A great big globe in a box, with label "TOGGLE"
alex
If you are booting your own OS and have direct write access to the port the keyboard is plugged in to... but in C#? I doubt it.
Daniel Coffman
+1  A: 

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);
ivanzoid