PDA

View Full Version : [kubuntu] Turning numlock on / off when plugging in external keyboard



Chip88
November 7th, 2016, 01:11 PM
Hi there,

after upgarding last weekend from 14.04 LTS to 16.04, I'm trying now to get the numlock turning on automatically when I plug in an external keyboard.
Of course, I found many instructions how to do this.

I did exactly the following:

lsusb to find out idVendor and idProduct:

Bus 001 Device 007: ID 04fc:05d8 Sunplus Technology Co., Ltd Wireless keyboard/mouse

Then I installed numlockx and created a file 25-usbkeyboard.rules in /etc/udev/rules.d/:

ACTION=="add", SUBSYSTEM=="input", ATTRS{idProduct}=="05d8", ATTRS{idVendor}=="04fc", RUN+="/usr/local/bin/numlock on", ENV{REMOVE_CMD}="/usr/local/bin/numlock off"

ENV{ID_VENDOR_ID}=="04fc", ENV{ID_MODEL_ID}=="05d8", ACTION=="remove", RUN+="/usr/local/bin/numlock off'"

I also created another file numlock in /usr/local/bin/:

#!/bin/shexport XAUTHORITY=/home/mark/.Xauthority #falls Session-Daten benötigt werden


case "$1" in
on)
export DISPLAY=':0.0'; /usr/bin/numlockx on
;;
off)
export DISPLAY=':0.0'; /usr/bin/numlockx off
;;
esac
exit 0


Restarted the notebook and got the login screen: Numlock is turned off (LED is off).
Put in the password, logged in and numlock turned on automatically (LED is also on).

→ But: When I unplug the USB receiver, nothing happens (LED keeps on).
Now, when I am plugging in the USB receiver, the LED turns off for a second and then automatically turns on again.
So it seems to me that the ​ACTION=="add" works fine.

But why is the the ​ACTION=="remove" not working correctly?

Thank you in advance about any advices & hints!

Regards,
Chipy

bra|10n
November 8th, 2016, 01:14 PM
Is there any particular reason you don't always want numlock on ?

Chip88
November 8th, 2016, 07:15 PM
Is there any particular reason you don't always want numlock on ?

Hey bar|10n,

thank you for your reply.

Yes, there's a simple reason:
At home, I work with an external keyboard, which has a separate numlock. If I would activate it permanently, I am causing the problem that numlock will always be on - also an my internal notebook keyboard. So if I am not working at home and without an external keyboard, the internal numlock will be turned on anyway.

Acutally, I just wanted to avoid this...

CantankRus
November 8th, 2016, 07:52 PM
I don't know how all this works but the last part of your 25-usbkeyboard.rules file seems to have an extra single quote...

RUN+="/usr/local/bin/numlock off'"