Use Caps Lock LED as HDD LED (or custom) indicator

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.


Solution 1:

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

Solution 2:

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:[email protected]/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

Solution 3:

#turn on
xset led named "Scroll Lock"

#turn off
xset -led named "Scroll Lock

also works with Caps Lock, etc.

Solution 4:

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.