I've recently bought a Unicomp keyboard that comes with swapped right-alt and Windows keys. The keyboard identifies like this on lsusb:
Bus 003 Device 002: ID 17f6:0822 Unicomp, Inc
Is there a way to have the kernel (i.e. not xmodmap-based) swap the right-alt and windows keys so every application sees them in the swapped places even if they get raw keyboard input (swapping stuff with xmodmap won't do that)? Is there a way to have that only for this one keyboard?
Best Answer
Yes, it's possible using XKB. Unlike xmodmap, XKB can remap your keys for individual devices.
Note: Make sure you have xkbcomp > 1.2.0
First list your devices with:
xinput list
You'll get something like this:
Identify the string of your device and edit the following shell script, changing the sed line with one that fits your device's name. Then change the keys you need remapped.
Example: Load
xev
and press a key you want to remap. Suppose you find out it's keycode 84. Lookup 84 in https://gist.github.com/zoqaeski/3880640. The key name there is<KP5>
. Then lookup the key you want it replaced by (in the same link, farther below) and copy what's inside the brackets. Repeat the process for all the keys you want.Then source it (you can add it to your .xinitrc). All done! Now pressing the keys should generate the desired output, only for the device you specified.
Edit: Recently, I've noticed that, for some reason, the new configuration isn't applied immediately. You must first press a key on your other keyboard, then test the configured keys on your modified keyboard. I don't know why this happens, maybe some sort of cache.