I'd like to use a second USB keyboard connected to my box running Ubuntu to generate special keystrokes. I'd like to map those in Vim to very specific actions.

I plug both my main keyboard and the secondary keyboard on two different USB ports.

How can I configura Ubuntu so that the keystrokes of only one of the keyboards are mapped to different keycodes?

For example, when I press the letter A on keyboard 2, I'd like it to appear as if I had pressed XF86XK_Launch0.

Assuming a sufficiently recent Ubuntu, you should be able to add your keyboard to /etc/udev/hwdb.d/. The required format can be cribbed from /lib/udev/hwdb.d/60-keyboard.hwdb.

After adding your new mapping, you need to rebuild the hwdb.bin file: udevadm hwdb --update. The next time udev sees your second keyboard (e.g. unplug and replug), it should load the mapping you wrote.

This is all assuming that your second keyboard has a distinct USB vendor:product pair to your first keyboard. If the two are identical, you might need more involved rules in /etc/udev/rules.d (check /lib/udev/rules.d/60-keyboard.rules for a starting point).

Also, look at /lib/udev/rules.d/64-xorg-xkb.rules if you're running X.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.