I am using Kubuntu Linux 12.04 on a Macbook Pro, and I am seeking the ability to use the Command/Meta key for common shortcuts such as copy, paste, and select all.
Attempted solutions:
- Remap Copy, Paste, Select All, and others in KDE's System Settings > Shortcuts and Gestures > Standard Keyboard Shortcuts
- Problem: These shortcuts appear to be ignored by most applications. All web browsers that I tested continued expecting the Ctrl key where I indicated desire of using the Meta key. Due to being unable to find a working web browser, I did not attempt any other applications.
- Tested in: Firefox, Chromium, Rekonq, Arora, Konqueror.
- Swap Meta with Ctrl using xmodmap.
- Problem: Terminal emulators would then require the use of the Meta key in place of the Ctrl key for commands such as the keyboard interrupt, most Emacs bindings, and countless other bindings in various CLI applications.
Considered Solutions:
- Individually change common shortcuts within GUI applications. Unfortunately, being able to change the bindings for Copy, Paste, and Select All appears to be rare.
- Change Ctrl modifier for only Konsole (or another terminal emulator.) This would ideally cause Meta–x to produce the keystroke Ctrl–x and vice-versa. I cannot find any way to accomplish this, however.
- Use stty to change the bindings for terminal key commands to use meta and additionally write custom config files for all other CLI applications. This would require an unreasonable amount of effort to accomplish.
I am extremely surprised at how much effort this simple modification is appearing to require, and I will appreciate any help that can be provided to find a reasonable working solution.
Best Answer
The Linux kernel generates a code each time a key is pressed on a keyboard. That code is compared to a table of
keycodes
defining a figure that is then displayed.This process is complicated by
Xorg
, which starts its own table ofkeycodes
. Eachkeycode
can belong to akeysym
. Akeysym
is like a function, started by typing a key.Xmodmap
allows you to edit thesekeycode-keysym
relations.To get the current keymap table using
Xmodmap
use:This will print out the full table in the following format:
Before moving anything around be sure to backup the original
keycode
layout usingxmodmap -pke >> $HOME/Xmodmap.orig
This will place the fileXmodmap.orig
in your users home directory.Tip: There are also some predefined keycodes (e.g.
XF86AudioMute
,XF86Mail
). Those keycodes can be found in:/usr/include/X11/XF86keysym.h
You can also also edit the keys:
Shift
,Ctrl
,Alt
andSuper
(there always exists a left and a right one (Alt_R=AltGr
)).Here's a quick example of how your configuration would look if you wanted to swap
CTRL
andSuper
(Windows Key):(the
!
is used to comment / ignore the line. in this example onlySuper
andControl
keys get adjusted)This configuration would be saved in
$HOME/.Xmodmap
and loaded withxmodmap ~/.Xmodmap
You could also start this with xwindows by adding it to your
~/.xinitrc
And if things get hairy you can always revert back to
Xmodmap.org
.Any bindings for applications that rely on these keys would also be moved. So make sure that everything remains bound so you don't lose any functionality. It's a tug-of-war match.