Okay, got a solution using udev (note that this applies to the debian configuration for file locations):
1) Create/edit a ~/.xsession file. Add the line (this will let the udev script running as root to modify the numlock in X):
2) Create the udev rules script file (/etc/udev/usbkeyboard.rules):
Code:
SUBSYSTEM=="input", ENV{PHYSDEVDRIVER}=="usbhid", RUN+="/usr/local/bin/usbkeyboard-addremove"
3) Link the rules script so that it executes:
Code:
cd /etc/udev/rules.d; ln -snf ../usbkeyboard.rules 025_usbkeyboard.rules
4) Create the script that it calls, that does the work (/usr/local/bin/usbkeyboard-addremove):
Code:
#!/bin/sh
NL=/usr/bin/numlockx
if [ "${ID_CLASS}" == "kbd" ] ; then
if [ "${DISPLAY}" == "" ] ; then
export DISPLAY=":0.0"
fi
if [ "${ACTION}" = "add" ] ; then
INITTY=/dev/tty[1-8]
for tty in $INITTY; do
setleds -D +num < $tty
done
${NL} on
else
INITTY=/dev/tty[1-8]
for tty in $INITTY; do
setleds -D -num < $tty
done
${NL} off
fi
fi
Summary:
I had an issue for some reason to get the "add" event to match ENV{ID_CLASS}=="kbd", so that is why it is in the script and not in the rule. This script will not only change the numlock in X but also set the tty's numlock status.
Requirements:
Debian packages: kbd numlockx udev