Question

Need to make the Keyboard's LED (Caps lock / Num lock or Scroll lock LED) blink either using C# or VB.net. (With or without using interop is fine)

Was it helpful?

Solution

This Microsoft Support article seems to be what you're looking for. It explains how to toggle the num lock, caps lock, and scroll lock keys in Visual Basic 6.

OTHER TIPS

Here's the C way

#include <windows.h>
#define err if (GetLastError() != 0) return GetLastError();

extern "C" __declspec(dllexport) int __stdcall TurnLed(int state)
{
    DWORD tmp = 4;
    DWORD buf = (2*GetKeyState(VK_NUMLOCK) + 4*GetKeyState(VK_CAPITAL) + state)<<16;
    DefineDosDevice(DDD_RAW_TARGET_PATH, "Kbd", "\\Device\\KeyboardClass1"); err
    HANDLE kbd = CreateFile("\\\\.\\Kbd", GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING,  FILE_ATTRIBUTE_NORMAL,  NULL); err
    DeviceIoControl(kbd, CTL_CODE(FILE_DEVICE_KEYBOARD, 0x0002, METHOD_BUFFERED, FILE_ANY_ACCESS), &buf, sizeof(buf), 0, 0, &tmp, 0); err
    DefineDosDevice(DDD_REMOVE_DEFINITION, "Kbd", 0); err
    CloseHandle(kbd); err
    return 0;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top