Thread: ioctl and keyboard leds

  1. #1
    Registered User
    Join Date
    Apr 2003

    ioctl and keyboard leds

    well....the situation is like this:

    i was playin around with ioctl() f-ion. And found file something like /usr/inlcude/linux/kd.h. i found there lot's of interesting stuff, and constants with keyboard leds. I wrote a program which turns on Numlock led and exits.

    the code is:
    #include <stdio.h>
    #include <linux/kd.h>
    int main(int argc, char *argv[])
      ioctl(1, KDSETLED, NUM_LED);
      return 0;
    the Num Lock led turns on, but when i press numlock key a couple of times, it won't work. The led is still on. I tried various ioctl() usage (with different params), but it didn't work anyway. Anyone know how i can turn it off ?!
    OS: Linux Debian 2.2 R4 (kinda old, but very good for C studies)
    Compiler: gcc 2.smth

    Thank you

  2. #2
    Registered User
    Join Date
    Apr 2003


    Thanx to Hammer for this link.

    Anyways. I think i'll post answer to my own question...

    There are three constants in linux/kd.h file which represents the state of leds.

    0x0 - All leds OFF
    0x1 - Num Lock led ON (others off),
    0x2 - Caps Lock led ON (others off),
    0x4 - Scroll Lock led ON (others off),
    0x3 - Num Lock and Caps Lock leds are ON (Scroll lock off)
    0x5 - Num lock and Scroll Lock leds are ON (Caps lock off)
    0x6 - Caps Lock and Scroll Lock leds are ON (Num lock off)
    0x7 - All leds are ON.

    you get the point. please don't get angry, i don't know if current leds represents current values (i mean caps lock can represent a value of 0x4 ans so on). So all i have to do is to set led with 0x0 parameter if i want all leds to be off cool eh ?!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wont run in X, works fine in alt+F1 terminal
    By zmerlinz in forum Linux Programming
    Replies: 5
    Last Post: 04-28-2004, 11:58 AM