How to remap keys on a user level both with and without X
I want to remap Capslock and I want this remap to work on both my machine with an X server and on machine without X. I also want this remap to be applied on a user level, not on a global level. This answer has a remap solution which works both with and without X. But the remap works globally and requires root permissions. Is it possible to remap a key locally and have it working with and without X?
Solution 1:
Well bummers! I've done some research and discovered that changing the keymap to remap CAPSLOCK (for example) REQUIRES root access. I'm sorry.
In the spirit of information, I'll retain what I had been working on here:
You can set up user-only keyboard configurations by putting options in ~/.keyboard
, these will override the system-wide defaults set in /etc/default/keyboard
-
NOTE: to get
setupcon
to read your~/.keyboard
, you MUST create~/.console-setup
, an empty file will suffice. The logic insetupcon
does not check for ~/.keyboard, it looks for ~/.console-setup and then reads both files. Tsk Tsk
You didn't specify what you'd like CAPSLOCK to be mapped to, so I'll give several examples.
You can use the /etc/default/keyboard
file as a template if you wish, something like one of these entries in ~/.keyboard
would probably work well for you:
(remember you really only need settings which override the system defaults in /etc/default/keyboard
)
XKBOPTIONS="ctrl:nocaps" # CAPSLOCK => CTRL
XKBOPTIONS="caps:escape" # CAPSLOCK => ESC
XKBOPTIONS="compose:caps" # CAPSLOCK => Compose (my favorite!)
There are (many!) more options available, have a look at the man page for setupcon
(1) and the contents of the file: /usr/share/X11/xkb/rules/xorg.lst
on your system.k