I have an external keyboard that I use with my Ubuntu 17.10 desktop and laptop at home, and the same species of keyboard on my RHEL 6.8 machines at work. But on my Ubuntu 17.10 laptop, I use the built-in keyboard most of the time, but other times I need to connect the previously mentioned external keyboard to it. So, I need the behavior of the capslock and control keys to work the same for both built-in and external keyboards.

This external keyboard has its customized firmware that, among many other things, swaps the left capslock and left control keys.

The behavior I am looking for is this:

  1. When the external keyboard is unplugged, swap the caps lock and control keys, since the built-in keyboard is in use.
  2. When I connect the external keyboard, I want to stop swapping the capslock and control keys because the keyboard does this already.
  3. I want this behavior under all of the following conditions:
    1. When I login using Gnome under Ubuntu 17.10
    2. When I login using Gnome under RHEL 6.8
    3. When I use the non-X terminal (console).
  4. I want to do this all from scripts I can control from my own home directory, and not have to install special packages under the root user as I need for it to work under both RHEL and Ubuntu (the latter I can control, but not the former, in terms of package installation and configuration).

What I have now is mostly working: I have a script run from Startup Applications that detects the keyboard and runs xmodmap. But it is a hack because something in Gnome or Xlib or Xorg or whatever is also fiddling with the keyboard's capslock and control key behavior, such that I have to have a sleep 5 right before the call to xmodmap to give Gnome/whatever time to finish its "fiddling" so that my call to xmodmap "wins". This is also a hack because it doesn't deal with unplugging and plugging in the keyboard. It should just do this based upon which type of keyboard is connected, not based upon logging in or out, locking or unlocking, or only at Linux startup. Also I had to have some setup that detects lock and unlocking of the desktop as well as then Gnome/whatever tries again to reset the keyboard upon unlock.

Is this possible to do?

Your Answer

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

Browse other questions tagged or ask your own question.