Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have my Caps Lock key remapped to Esc, so now I have a LED on my keyboard that is never on. I'd like to use it for something useful, like HDD or LAN activity.

Especially that I'm using a computer with a custom box & heatsinks (built into my drawer so I don't have to listen to the HDD and it doesn't take up much space), and the LEDs are not visible otherwise.

If there's a library for controlling the keyboard LEDs, I could do some coding myself, if there isn't a solution for this already.

I'm on Gentoo ~amd64.

EDIT: Ok, forget about the HDD LED. It was just an example.

I want the Caps Lock LED to light up when it's my birthday. Or when I have email. Or when I say "Caps Lock LED, please light up!".

I absolutely do not want to use an extra wire. In fact, it would be nice if this would work on wireless keyboards as well.

share|improve this question
3  
I like this idea! Hopefully someone can answer for Windows also? –  Iszi Nov 29 '11 at 18:30
1  
You can edit the HDD LED requirement back to your question. The solutions might not blink as fast as normal hdd led, but it works quite nicely on my keyboard. And it's quite useful, because I can't see my hdd leds. –  Manwe Jan 20 '12 at 15:57
add comment

6 Answers 6

up vote 10 down vote accepted
+100

Well to change the led indicator on VT console you can use setleds. So if you're in a VT you can just type

setleds

and you'll get your current led status. If you don't want to enable numlock, just light it up you can type:

setleds -L +num 

It comes trickier in X and this is the "simplest" way to try it. Please note that X is usually ran as root so you'll either have to check permissions on X-windows tty or run it with root privileges. Usually X is tty7. /dev/console should work being the system console and by that all VTs should be affected.

sudo su -c 'setleds -L +num < /dev/tty7'

I think this will also work:

sudo su -c 'setleds -L +num < /dev/console'

here's list of light options

 [{+|-}num] [{+|-}caps] [{+|-}scroll]

If you don't have setleds in you system, my guess is that you can get it from this emerge package sys-apps/kbd.

If you are more of person who likes to code stuff here's a link to en example code to change leds in X. I did not test this, but just by looking the code looked ok.

And here's a shell script to do what you originally wanted. To have caps or other leds as HDD indicators.

#!/bin/bash

# Check interval seconds
CHECKINTERVAL=0.1

# console
CONSOLE=/dev/console

#indicator to use [caps, num, scroll]
INDICATOR=caps

getVmstat() {
  cat /proc/vmstat|egrep "pgpgin|pgpgout"  
}
#turn led on
function led_on()
{
    setleds -L +${INDICATOR} < ${CONSOLE}
}
#turn led off
function led_off()
{
    setleds -L -${INDICATOR} < ${CONSOLE}
}
# initialise variables
NEW=$(getVmstat)
OLD=$(getVmstat)
## 
while [ 1 ] ; do
  sleep $CHECKINTERVAL # slowdown a bit
  # get status 
  NEW=$(getVmstat)
  #compare state
  if [ "$NEW" = "$OLD" ]; then  
    led_off ## no change, led off
  else
    led_on  ## change, led on
  fi
  OLD=$NEW  
done
share|improve this answer
1  
Thank you for this nice answer, this solution works perfectly for me, and is a good example that I can easily change to whatever I need. A already have sys-apps/kbd installed, so it worked out of the box. You deserve all the bounty I could give :) –  Attila O. Jan 20 '12 at 17:54
add comment
#turn on
xset led named "Scroll Lock"

#turn off
xset -led named "Scroll Lock

also works with Caps Lock, etc.

share|improve this answer
add comment

check Gmail - blinks LEDs when e-mails received and says the number of emails

#!/bin/bash
echo "Checking for new email";
mails="$(wget --secure-protocol=TLSv1 --timeout=3 -t 1 -q -O - \
   https://name1:password1@mail.google.com/mail/feed/atom \
   --no-check-certificate | grep 'fullcount' \
   | sed -e 's/.*<fullcount>//;s/<\/fullcount>.*//' 2>/dev/null)"

echo $mails;

#blink LEDs
if [ "$mails" -gt "0" ];
then
    blink -s -r 5;
fi

#speak announcements

if [ "$mails" -gt "0" ];
then
    espeak "$mails new emails in main account.";
fi

sleep 4;
blink;

exit
share|improve this answer
1  
Where can you find blink? –  Manwe Jan 20 '12 at 20:17
1  
blinkd - looks like Debian guys removed it from repos, sad - bugs.debian.org/cgi-bin/bugreport.cgi?bug=461433 –  jet Jan 21 '12 at 0:19
add comment

You can do that using AutoHotkey. Check this thread if you want to learn about the codes you need to use.

After reading that thread and the documentation on AutoHotkey you can do those things.

Also it works with USB and Wireless keyboards too.

You can use it with Wine on Gentoo.

share|improve this answer
1  
While I was able to run AutoHotkey with Wine, for some reason it did not light up my LEDs (though no error messages were logged). Also, even if it would work, having to pipe through wine every couple of milliseconds, or having a wine process running all the time is not very optimal, especially compared to the other solution that uses setleds. Still, this might be a solution for windoze users, so thanks for posting. –  Attila O. Jan 20 '12 at 17:57
add comment

This is not a software problem to solve with a library.

The keyboard LEDs are controlled by software — in particular by the keyboard device driver generating commands to be sent to the keyboard microprocessor that turn the LEDs on and off, in response to I/O Control requests.

The hard disc activity lights on your front panel are controlled by hardware. They are connected to the mainboard, and — to cut a long story short — wired up to an output of the PCI-to-ATA bridge chip. (For the ICH10, for example, this output is the SATALED# output.) Hardware turns this output on and off as commands are sent across the SATA/PATA bus. Those who remember life with SCSI will remember that SCSI hard disc activity didn't affect the "hard disc" LED, since it is driven by the ATA bridge hardware.

It's not really practical — and would require a considerable amount of extra software and hardware — for output on the SATALED# signal to cause hardware interrupts that are received by software, which then triggers commands by the keyboard device driver. It's a fairly knuckleheaded design. But the converse approach, of having all disc I/O commands generated by the disc device driver make a side trip through the keyboard device driver is almost as bad, albeit that it doesn't require a whole new type of hardware device that receives "The front panel LED is on!" interrupts. It requires two distinct hardware subsystems — disc and keyboard — to be linked, and a fair amount of systems programming. It would also effectively limit all disc I/O to the speed of the keyboard.

This is a hardware problem to solve, very simply, with a longer piece of wire.

If your front panel is hidden away in a drawer or under a table, and you want to see the front panel LEDs, then simply make a detachable front panel of your own and connect it to the mainboard with longer wires. A quick check on eBay reveals that there exist computer component vendors that will sell to you such front panel cables (with the LEDs and switches attached) of varying lengths, up to at least 1 metre.

share|improve this answer
1  
The HDD LED was just an example. The main idea is that I have at unused LED on my keyboard that I'd like to control. Please look at my edits. –  Attila O. Nov 29 '11 at 20:05
add comment

You could remove an HDD led from an old case, extend the wires and tie-wrap the wires to the keyboard wire, branch at the case, and plug direct into the HDD led jumper on the mainboard. Open the keyboard and hot-glue the HDD LED next to the capslock LED.

Software free and ugly? Check.

share|improve this answer
    
Not a bad idea altogether, but 1. I could just use the keyboard led, I don't think I need another led from an old case, and 2. I want there to be only one USB cable connecting my keyboard. Or better yet - think wireless keyboard. –  Attila O. Nov 29 '11 at 20:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.