Xmodmap

From LinuxReviews
Jump to navigationJump to search
Keyboard-icon.svg

xmodmap is a small program for modifying keyboard keymaps and mouse pointer button mapping under the X display server. It can be used to permanently or temporarily swap ctrl with ⇪ Caps Lock, replace the . on the number pad with , and similar. It can also be used to change what physical mouse button should be read what what button in X.

System Configuration[edit]

Most GNU/Linux distributions come with a file in /etc/X11/xinit/xinitrc-common that runs xmodmap and reads any users $HOME/.Xmodmap file if it exists. No system-specific configuration should be required to make X read a $HOME/.Xmodmap file regardless of what desktop environment or window manager you happen to be using.

If your particular distribution does not read and activate $HOME/.Xmodmap regardless of window manager and desktop environment for some odd reason then it is possible to start it xmodmap in .xinitrc along with your favorite window manager:

/usr/bin/xmodmap $HOME/.Xmodmap
exec wm-exec-command

xmodmap is typically not available as a separate package. It is usually part of a X package (like xorg-x11-server-utils on Fedora). It will likely be installed on your system (you can check with which xmodmap), some rare slimmed-down distributions do not install it by default but all the bigger and common distributions do.

User Configuration[edit]

Permanent keyboard and mouse button mappings can be placed in a file called $HOME/.Xmodmap. It should have entries like to change the outcome of keycodes and/or entries saying certain key-mappings should be removed, added and changed with a keysym entry.

You can test your $HOME/.Xmodmap changes without having to log out and back in with:

xmodmap ~/.Xmodmap

Swapping Ctrl And Caps-Lock[edit]

File: $HOME/.Xmodmap
! swap Caps_Lock and Control_R
!
remove Lock = Caps_Lock
remove Control = Control_R
keysym Control_R = Caps_Lock
keysym Caps_Lock = Control_R
add Lock = Caps_Lock
add Control = Control_R

Change , to . on the number pad if you use a European (or other) keyboard layout where the number pad dot produces a , and you want a comma:

Changing Number-Pad , To .[edit]

File: $HOME/.Xmodmap
! change numpad , to .
keycode 91 = Delete period

Re-Mapping Mouse Buttons[edit]

xmodmap can be used to re-map mouse buttons. The syntax is simple:

pointer = n n n n n

Where n is the physical mouse button and the placement after pointer = is the button X sees.

pointer = 3 2 1 would make X see physical mouse button 3 as button 1, physical mouse button 2 as 2 and physical mouse button 1 as button 3.

If you have a cheap Chinese mouse button with two buttons on the side and you want the middle button (2), typically the button under the mouse wheel on modern mice, to be mapped to one of the buttons on the side then you can use:

pointer = 1 9 3 4 5 6 7 8 2 10

Finding out what mouse button is which can be done by using the xev tool.

Links[edit]


Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.