The problem with all of the other answers is that if you use a USB keyboard and any USB event happens then you will lose your settings. After many years, many failed attempts and visiting this page many times I finally have a solution that survives USB events:
- Install inputplug
For arch this I needed to use community repos: yay -S inputplug
- Create a script that sets up your custom keyboard settings
Here's the script (~/on-new-kbd) I use to maps caps to control and also to set the compose key to be right control (useful for typing things like '€')
#! /bin/sh
echo >&2 "$@"
event=$1 id=$2 type=$3
case "$event $type" in
'XIDeviceEnabled XISlaveKeyboard'
/usr/bin/setxkbmap -option 'ctrl:nocaps'
/usr/bin/setxkbmap -option 'compose:rctrl'
esac
- Make sure it runs at startup
Make it run when xfce starts by adding a new autostart entry. Do this by creating the file .config/autostart/inputplug.desktop
[Desktop Entry]
Encoding=UTF-8
Version=0.9.4
Type=Application
Name=inputplug
Comment=Detect new keyboards and apply settings like caps - > ctrl
Exec=/usr/bin/inputplug --bootstrap --command ~/on-new-kbd
OnlyShowIn=XFCE;
RunHook=0
StartupNotify=false
Terminal=false
Hidden=false