Linux: change Xmodmap depending on keyboard plugged in?

mSSM

13 Apr 2013, 16:26

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?

User avatar
matt3o
-[°_°]-

13 Apr 2013, 17:54

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.
Last edited by matt3o on 13 Apr 2013, 17:56, edited 1 time in total.

User avatar
Daniel

13 Apr 2013, 17:56

Maybe you could write a little script which parses the output of lsusb and calls xmodmap depending on the found device?

TacticalCoder

29 Apr 2013, 02:07

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)

Findecanor

29 Apr 2013, 03:31

You will also need a rule for when you disconnect the SSK.

User avatar
matt3o
-[°_°]-

29 Apr 2013, 09:58

Findecanor wrote:You will also need a rule for when you disconnect the SSK.
same as above but with ACTION=="remove"

Post Reply

Return to “Off-topic”