xcape icon indicating copy to clipboard operation
xcape copied to clipboard

Full-featured alternative to xcape

Open rafaeln opened this issue 5 years ago • 4 comments

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.

rafaeln avatar May 31 '20 14:05 rafaeln

Also consider https://gitlab.com/interception/linux/plugins/caps2esc

zeorin avatar Jun 25 '20 20:06 zeorin

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 which is not going to make any sense to bash. Anyways, what I have been able to achieve is: caps lock gives me escape when tapped and ctrl when chorded, space gives me space when tapped and altgr when chorded, right alt gives me backspace when tapped and meta when chorded, right shift gives me > when tapped and shift when chorded and left shift gives me < when tapped and shift when chorded. Also, the part concerning right and left shift only works out this way if I'm using my personalized Dvorak keyboard layout. If I use querty us, I get _ and + instead of < and >.

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

rafaeln avatar Jun 25 '20 22:06 rafaeln

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/

bbatsov avatar Jul 06 '20 10:07 bbatsov

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.

pataquets avatar Jun 28 '21 17:06 pataquets