25

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.

Attila O.
  • 1,447

9 Answers9

19

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
Manwe
  • 888
6

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
jet
  • 2,733
5
#turn on
xset led named "Scroll Lock"

#turn off
xset -led named "Scroll Lock

also works with Caps Lock, etc.

gcb
  • 5,442
  • 13
  • 62
  • 86
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.

horatio
  • 3,719
4

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.

3

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.

JdeBP
  • 27,556
  • 1
  • 77
  • 106
2

Since Linux 4.7:

# echo ide-disk > /sys/class/leds/input17::capslock/trigger

It requires CONFIG_LEDS_TRIGGER_DISK=y in the kernel config.

2

http://members.optusnet.com.au/foonly/whirlpool/code/hddled.c

That will make the HDD LED on Scroll Lock. Modification for CAPS LOCK should be simple.

1

I once wrote a small C program to control the CapsLock LED on my DELL XPS15. It is only tested on one System, therefore I can not guarantee that it will work for you. Maybe you would have to adapt it, but that should be pretty straight forward.

cee
  • 410