Full-featured alternative to xcape
I stopped using xcape a while ago because it wasn't working anymore in my system and I recently found out about dual-function-keys. It allows me to do all I was doing before with xcape and a little bit more. In particular, I've been able to map Space to AltGr when pressed alongside other keys and to Space when tapped, then I mapped AltGr to Meta when pressed alongside other keys and to Backspace when tapped. One feature it has which xcape doesn't is I can tap the Space key twice to get repeated Spaces, or the AltGr twice to get multiple Backspaces. Under Ubuntu 18.04 I am required to compile dual-function-keys, but the process was mostly painless and the instructions given in the repo were flawless.
Also consider https://gitlab.com/interception/linux/plugins/caps2esc
I actually use both caps2esc as well as dual-function-keys. They are all plugins to the interception framework, which by the way you also need to compile. There is also a third interesting plugin, space2meta, which I now don't use anymore. If you follow along the README.md on each of the projects' github page you can figure out how to set up your system to suit your desires. As an example, my recipe that works on my Ubuntu 18.04 boxes is the following, which is not meant to be copied and pasted to anyone's terminal, not even mine, since there is meta-code in there such as
sudo apt install libudev-dev libyaml-cpp-dev libevdev-dev cmake
cd
mkdir src
cd src
git clone https://gitlab.com/interception/linux/tools
git clone https://gitlab.com/interception/linux/plugins/caps2esc
git clone https://gitlab.com/interception/linux/plugins/dual-function-keys
for dir in tools caps2esc ; do
cd $dir
mkdir build
cd build
cmake ..
make
sudo make install
cd ../..
done
cd dual-function-keys
make && sudo make install
sudo su
cat > /etc/udevmon.yaml
- JOB: "intercept -g $DEVNODE | caps2esc | dual-function-keys -c /home/rafael/.dual-function-keys.yaml | uinput -d $DEVNODE"
DEVICE:
EVENTS:
EV_KEY: [KEY_CAPSLOCK, KEY_SPACE, KEY_RIGHTALT, KEY_LEFTSHIFT, KEY_RIGHTSHIFT]
<ctrl-d>
cat > /etc/systemd/system/udevmon.service
[Unit]
Description=udevmon
Wants=systemd-udev-settle.service
After=systemd-udev-settle.service
[Service]
ExecStart=/usr/bin/nice -n -20 /usr/local/bin/udevmon -c /etc/udevmon.yaml
[Install]
WantedBy=multi-user.target
<ctrl-d>
cat > /home/rafael/.dual-function-keys.yaml
TIMING:
TAP_MILLISEC: 200
DOUBLE_TAP_MILLISEC: 150
MAPPINGS:
- KEY: KEY_SPACE
TAP: KEY_SPACE
HOLD: KEY_RIGHTALT
- KEY: KEY_RIGHTALT
TAP: KEY_BACKSPACE
HOLD: KEY_RIGHTMETA
- KEY: KEY_LEFTSHIFT
TAP: [ KEY_LEFTSHIFT, KEY_MINUS , ]
HOLD: KEY_LEFTSHIFT
- KEY: KEY_RIGHTSHIFT
TAP: [ KEY_RIGHTSHIFT, KEY_EQUAL , ]
HOLD: KEY_RIGHTSHIFT
<ctrl-d>
sudo systemctl enable --now udevmon
FYI - I wrote a short article on setting up dual-function-keys https://emacsredux.com/blog/2020/07/05/remap-enter-to-control-in-gnu-linux-2020-edition/
Thank you everyone for the information. Just adding KMonad which can already do this and much more, although it requires more configuration. Going further with the 'space as control' use-case, I've successfully implemented home row mods. Just my 2c.