Listing 11. Using EVIOCGLED

memset(led_b, 0, sizeof(led_b));
ioctl(fd, EVIOCGLED(sizeof(led_b)), led_b);

for (yalv = 0; yalv < LED_MAX; yalv++) {
    if (test_bit(yalv, led_b)) {
        /* the bit is set in the LED state */
        printf("  LED 0x%02x ", yalv);
        switch ( yalv)
            {
            case LED_NUML :
                printf(" (Num Lock)\n");
                break;
            case LED_CAPSL :
                printf(" (Caps Lock)\n");
                break;
            /* other LEDs not shown here*/
            default:
                printf(" (Unknown LED: 0x%04hx)\n",
                       yalv);
            }
    }
}