Swapping Ctrl and Alt keys on a GNU Debian system
if you're a touch typist you might notice that you use the Ctrl key much more often than Alt, and stretching the finger to Alt feels a little uncomfortable. One tip you can use to mitigate the uncomfortable feeling is to press the Ctrl key with a side of your palm, giving that your keyboard has sufficiently big and protruding buttons.
When it's not the case, especially true with a laptop keyboard, programmatically swapping the keys might be something you'd give a try. This way you can comfortably reach the Ctrl buttons with your thumbs.
For TTY
First you need to create a regular text file that will hold the key mappings and fill it with the following contents:
keymaps 0-127
keycode 56 = Control ! left alt to ctrl.
keycode 100 = Control ! right alt to ctrl.
keycode 29 = Alt ! left ctrl to alt.
keycode 97 = Alt ! right ctrl to alt.
sudo loadkeys $HOME/.config/Alt2Ctrl_TTY.map
Note that after rebooting your machine the functions of the Alt and Ctrl keys will be restored to the original state.
For the X Window System - X11 (GUI)
A similar procedure is used with the X Window System, create a file and put this into it:
clear control
clear mod1
keycode 37 = Alt_L Meta_L
keycode 105 = Alt_R Meta_R
keycode 64 = Control_L
keycode 108 = Control_R
add control = Control_L Control_R
add mod1 = Alt_L Meta_L
I've saved my file using this path: /home/user/.config/Alt2Ctrl_GUI.xmap
xmodmap $HOME/.config/Alt2Ctrl_GUI.xmap
With the xmodmap for X11 there's no need to be a superuser or use sudo.
As with TTY, after rebooting, the key functions will be restored to the original state.
Making the Remapping Convenient
swap-alt-and-ctrl-keys () {
xmodmap $HOME/.config/Alt2Ctrl_GUI.xmap
sudo loadkeys $HOME/.config/Alt2Ctrl_TTY.map 2>/dev/null
}
Note that this function can remap both TTY and X11 in one go only when being run under the X Window System.