Having NumLock on is convenient when using a full-sized external keyboard (having a keypad) and very inconvenient when using laptop's built-in keyboard (which places digits instead of letters on the keyboard's right sid unless Fn is pressed).
So I have to turn NumLock on every time I attach an external keyboard (or boot with it attached) and off every time I detach an external keyboard (or boot with it detached). And I do this frequently because I prefer using a full-sized external keyboard, but have not enough (only 3) USB ports to plug-in it alongside with a mouse, a 3G modem and an external hard/flash drive.
Can I automate this? Seems a very formaliseable, logically simple task: if there is an USB keyboard attached (some device in /dev present?) - NumLock is on, if not - NumLock is off. My laptop's built-in keyboard is PS/2-attached, external is USB.
Maybe I should code it myself, but where to put it in this case?
I use Ubuntu 10.10.
First off, install numlockx (click here to install numlockx). Basically this allows you to write scripts to set the state of Num Lock - see the numlockx man page for details.
Next we need to start delving into the fun of udev rules. First we need to find out how the keyboard is identified. You can do this by
This should give you some human readable file names (that are soft links to the not particularly readable true name). My keyboard was
So then we need to find out all the info about the keyboard. I did
But insert your own path there of course. You'll get a lot of info, but you want to look at the first block that names the keyboard and has
SUBSYSTEMS=="usb"
. (Rather than the USB controller or whatever). In my case that was:So now we have enough information to write some rules. Use your favourite editor to create
/etc/udev/rules.d/10-local.rules
and put in:Again, put the name of your keyboard in here, and the ATTRS if it is different. Then it should work :)
Note I haven't been able to test this, though I have run all the commands up until creating the rules file. And the sources in case you need to do some more investigation are:
If you are using Gnome3 shell.
Install numlockx
then launch Startup application preferences
gnome-session-properties
Image (new users can't post images :))
Click Add
Write anything into name field and into command field copy this:
numlockx on
Image
I'm not sure what I'm doing differently, because my numlock on this keyboard is defaulting to on (This is a Mac Pro Aluminum keyboard). There are some instructions here that should do the trick.
Hope this helps!
If are you using gnome-shell, then you could install Numlock & Capslock status on the panel "Lock Keys" extension. Please, found it here