Page 1 of 1
Linux: change Xmodmap depending on keyboard plugged in?
Posted: 13 Apr 2013, 16:26
by mSSM
I like to switch between my HHKB and my IBM SSK from time to time (and sometimes I need to use my laptop's keyboard). My problem: I need the Super-key (Windows-key) quite often, and for that I am remapping CTRL to CapsLock on the SSK, and make the left CTRL a Super key.
Of course, these changes are not necessary on the HHKB, and I don't want the HHKBs CTRL to behave like a Super key. Does anyone know if I can have my system detect which keyboard is plugged in and set the Xmodmap dynamically depending on that?
Posted: 13 Apr 2013, 17:54
by matt3o
it seems a job for udev. I don't know your distro I'll try to be generic.
Basically you have to find the device with lsusb or dmesg. You can identify the keyboard in many ways, the easiest is probably by ID. It's in the form of xxxx:yyyy. where xxxx is the vendor and yyyy the device itself.
Then you create a new rule (a text file) in /etc/udev/rules.d/98-user.rules
In that file you place something like this (please verify I didn't check it)
Code: Select all
SUBSYSTEM=="usb_device", SYSFS{idVendor}=="xxxx", SYSFS{idProduct}=="yyyy", ACTION=="add", RUN+="/path/to/your/script.sh"
of course replace xxxx and yyyy with the keyboards ID and /path/to/your/script.sh with the script to execute.
I didn't check it, but should work. Google it, you'll find dozens tutorials.
Posted: 13 Apr 2013, 17:56
by Daniel
Maybe you could write a little script which parses the output of lsusb and calls xmodmap depending on the found device?
Posted: 29 Apr 2013, 02:07
by TacticalCoder
mSSM: if you get it to work (for example following matt3o's infos), could you do a recap here?
I'd like to do the same (with xkbcomp instead of Xmodmap but I take it that's not the "hard" part)
Posted: 29 Apr 2013, 03:31
by Findecanor
You will also need a rule for when you disconnect the SSK.
Posted: 29 Apr 2013, 09:58
by matt3o
Findecanor wrote:You will also need a rule for when you disconnect the SSK.
same as above but with ACTION=="remove"