This Season
 

How to Use the XMODMAP Command in Linux to Swap Keyboard Keys

How to Use the XMODMAP Command in Linux to Swap Keyboard Keysthumbnail
Use the XMODMAP Command in Linux to Swap Keyboard Keys

Linux lets you be very flexible about individual system configurations. For example, the input system. The keyboard configuration is completely accessible in the form of a customizable keymap. The xmodmap utility lets you change your keyboard configuration as needed. Swapping a set of keys to exchange their functions or adding a function for additional keys your keyboard might include. Interestingly, this program also lets you control the buttons on your mouse, enabling customization of a mouse with several buttons.

Related Searches:
    Difficulty:
    Moderate

    Instructions

    Things You'll Need

    • A computer with Linux operating system
    • Knowledge of shell
    • An unknowing victim to play the prank on
      • 1

        Open a new Terminal window. Type the following command:

        xmodmap -pke

        This displays the current keyboard mapping. If all you want to do is exchange two keys, this makes it easier to see the code needed.

      • 2

        Type "xev" and press "Enter" if you need to add functions to keys which aren't currently mapped. For example, the multimedia keys on a keyboard may not be included in your current map. Press a key you want to map in the Terminal screen, xev displays an event that includes the "keycode" for that key. Make a note of the keycode for any key you want to map.

      • 3

        Open or create the .xmodmaprc file in your home directory using your preferred text editor. Chances are the file doesn't exist if you haven't run xmodmap before, so you'll need to create it.

      • 4

        Add one line to the .xmodmaprc file for each key you want to modify. The line should be formatted this way:

        keycode number = key

        Replace "number" with the keycode number you discovered using the "pke" option or xev. Replace "key" with the key you want to insert when the key is pressed. For example, to change keycode 89 to the F4 key, you'd type "keycode 89 = F4" in a line of the file. To change the case of the key or type a different key when shift is pressed, insert a space at the end of the line and type the second key you want the key to represent when shift is pressed.

      • 5

        Open the "XKeysymDB" file normally located in the "/usr/share/X11" folder to see multimedia function names. For example, the file shows that the "XF86AudioMute" function is available. To change a multimedia key with a keycode of 102 to work as the mute button, you'd add the following line to your .xmodmaprc file:

        keycode 102 = XF86AudioMute

      • 6

        Save the .xmodmaprc file once you're finished. Log out and log back in for the changes to take effect.

    Tips & Warnings

    • To reverse what you have changed, simply go back into the user's .bashrc file, change the keycodes back to normal.

    Related Searches

    References

    • Photo Credit Andrea Church

    Read Next:

    Comments

    You May Also Like

    Follow eHow

    Related Ads