Permanent caps lock/control swap in XFCE (and maybe console)?
I have setxkbmap -option ctrl:swapcaps in my ~/.xinitrc, and it works, but when I plug in a USB mouse, the setting gets reset. In addition, in VirtualBox, the Ctrl key seems to trigger a Ctrl in the VM while pressing caps lock!
Surely there's a better way to do this. What would you recommend? Bonus points if my console's control and caps lock are swapped, too.
About this post
- Posted
- Archived
- Score
- 5 · 100% up
- Kind
- Text
- ID
- 69caa8
8 comments
You want the nuclear option? Go low level, use udev rules:
https://wiki.archlinux.org/index.php/Map_scancodes_to_keycodes
Because you are literally working on the kernel level, it works everywhere. Xorg, console, wayland, you name it.
Unfortunately if you go this way you need separate rules for every keyboard you own.
This is perfect! Thanks so much!
I use xmodmap. From
man xmodmap:I don't know how to set this for the console.
About the desktop and that USB device getting plugged in, move your settings to an X config file. X will then apply it to all devices as they get connected and you'll have no problems with things like suspend/resume resetting settings because all USB devices disappear and reappear. I think you will still have the VM's window reacting to the original keys.
The "localectl" tool can write an X config for you. It saves the stuff in a file
/etc/X11/xorg.conf.d/00-keyboard.conf. The command to set stuff looks like this:Here's two examples on how you would use it in practice:
The first one sets "us" layout for the keyboard and adds that "caps:swapcaps" keyboard option you asked for. The second one is with all slots for that "set-x11-keymap" parameter filled in, setting a 104-keys PC keyboard, US layout, "altgr-intl" variant of that US layout, and then your "caps:swapcaps" option.
You can check what you are currently using by just typing
localectl. It will print layout, model, variant, options, but only if they are set right now.I think you need to log-out, log-in for the settings to get applied.
Ooooh, interesting! Could I apply the swapcaps stuff to my laptop's internal keyboard only? I have a HHKB that got me into this habit, and the Ctrl key is already in the "caps lock spot."
I think this might be possible, but you will have to take that
00-keyboard.confas an example and make a copy and then do something to it yourself. There's rules like this that you can use in X config files that sound like it should be possible to apply something for just one keyboard and not the other:Those options are described somewhere in
man xorg.conf.The product names should be the same as what you see with
xinput, and you can search for stuff in/var/log/Xorg.0.log.I tried that idea you had, about applying different X configs to different keyboards, and it works. I could use completely different language layouts on two keyboards, and I could also change just those caps-lock key options.
I created a new file for my "special" keyboard in /etc/X11/xorg.conf.d/ and it was applied on top of what I had in 00-keyboard.conf:
That name for the MatchProduct line is the same as what's seen in the output of the command
xinput. My other keyboard is connected to PS/2 instead of USB and shows up as "AT Translated Set 2 keyboard".You can check on what the X server is doing by searching around in the file
/var/log/Xorg.0.log. The server prints the config lines it applies to each device.I don't know how to set this in xorg, but in tty is super-easy.
I'm assuming that you aren't inside xorg:
check the keycode of the key you want to change.
showkeywill echo the keycode of the pressed key. Remember: to stop it just don't type anything for 10 seconds and it will exit.copy your currently map file somewhere. For example mine is
/usr/share/kbd/keymaps/i386/dvorak/dvorak.map.gzun(g)zip that
open that file with your editor of choice
for me the caps lock is the
58while left-ctrl29. Just swap the number at the start of the linerecompress the map file
gzip -c < dvorak.map > dvorak.map.gzcopy that to the original folder
Automatize that with a
PKGBUILDand you're done!I've alredy done something similar with esc and caps lock with a customized variant of the dvorak, my work is here: https://github.com/omar-polo/Latin-Dvorak
edit: formatting