Linux: Keyboard-Mapping Control


Remapping Keys

Given the variations in physical keyboard layouts across personal computers from different manufacturers, the potential for a configured key to be mapped differently than expected or even to be missing on some keyboards creates the need for System Administrators to be able to remedy this problem by remapping the desired functions to the available key(s) of their choosing.  Luckily, there are a number of powerful tools available for the Linux OS, some of which will be outlined in this note with a few usage examples and scenarios.

  • xev
  • xmodmap
  • showkey
  • loadkeys

How to Map the Super key to Search key

The Samsung Chromebook doesn't have a Super key, or "Windows" key, on its keyboard; as a result, the Super key, which is usually mapped to it by default, is missing from the keyboard and the user is missing a useful function from certain applications.
    In order to provide the user with a convenient shortcut on their keyboard, first we need to find find out some more information on the specific key of choice.  A number of tools are available to achieve this:

∘ xev - Xev  creates  a window and then asks the X server to send it events whenever anything happens to the window (such as it being moved, resized, typed in, clicked in, etc.).  You can also attach it to an existing window.  It is useful for seeing what causes events to occur and to display the information that they contain.  xev is installed as part of the xorg-x11-utils package on a Fedora system.
∘ xmodmap -  The xmodmap program is used to edit and display the keyboard modifier map and keymap table that are used by client applications to convert event keycodes into keysyms.  It is usually run from the user's session startup script to configure the keyboard according to personal tastes. xmodmap is installed as part of the xorg-x11-server-utils package on Fedora systems.
∘ showkey - installed as part of the kbd package, which "contains tools for managing a Linux system's console's behavior, including the keyboard, the screen fonts, the virtual terminals and font files." showkey  prints  to  standard  output  either the scan codes or the keycode or the `ascii' code of each key pressed.

Get the keycode of the "Search" Button

# showkey 
kb mode was ?UNKNOWN?
[ if you are trying this under X, it might not work
since the X server is also reading /dev/console ]

press any key (program terminates 10s after last keypress)...
keycode  28 release
keycode 125 press
keycode 125 release
Typing showkey in the terminal will continually probe the system for keystrokes, showing the keycodes for every key pressed and released, as displayed above.  So, without going into great detail and diverging from the issue at hand, this shows us that the "Search" button's keycode is "125".  Armed with this information, we can specify the chosen key to the computer system in more specific terms than simply "search" button.

Assign keycode to modifier
Running the xmodmap command in the terminal returns some output about key modifiers. 

xmodmap -e "keycode 125 = Super_L"
The above command will assign the search button to the mod4 key modifier, which is necessary to use the awesome window manager painlessly.

Popular posts from this blog

Password Policy in RHEL 7

Centos 7 pulseaudio

Password Aging and Authentication in RHEL7