On my laptop the Alt and Windows keys are in the opposite positions that I'd prefer them in. Swapping them is fairly easy. However, my external (USB) keyboard has the Alt and Windows keys in the order I prefer, meaning when I switch over to the external keyboard I have the unpreferable keyboard arrangement.

Is there some manner of Linux-y voodoo I can invoke to detect whether input is coming from an external keyboard or not, and have it swap the two keys accordingly? If that's pushing it, I'd settle for a way to detect when an external keyboard is plugged in. Or are there any other reasonable solutions that I haven't considered?


You can have entirely different layout settings for every keyboard you connect; the Unreliable Guide to xkb configuration might be helpful. In your case, you might get by with "Doing it the easy way" therein.

Be advised, though, that the guide was written at a time when the X server had a config file that was honoured. Since then, configuration of the keyboard has moved at least into HAL and back out again, so heaven knows where you have to put your extra Options "XkbOptions" "..." when it's a new moon now.

If all else fails and your X is sufficiently recent, yes, get the device number from xinput list and call setxkbmap -device ... ..., call it in your X startup file and maybe also look at udev to be notified when that keyboard is plugged in.

  • In that guide, I can't find anything about how to match different keyboards in the config. – Turion Feb 14 '15 at 15:09

You can use xinput list to check for an external keyboard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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