osamuaoki / interception-caps2esc

Rebind Caps Lock to Esc at evdev level using interception-tools

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

caps2esc

Transforming the most useless key ever in the most useful one. For vi/Vim/NeoVim addicts at least.

ADM-3A terminal

What is it?

  • Put what's useless in its place By moving the CAPSLOCK function to the far ESC location
  • Make what's useful comfortably present, just below your Pinky By moving both ESC and CTRL functions to the CAPSLOCK location

Why?!

Because CAPSLOCK is just "right there" and making it CTRL when key-chording and ESC when pressed alone is quite handy, specially in vi.

Dependencies

Building

$ git clone https://gitlab.com/interception/linux/plugins/caps2esc.git
$ cd caps2esc
$ cmake -B build -DCMAKE_BUILD_TYPE=Release
$ cmake --build build

Execution

caps2esc - transforming the most useless key ever in the most useful one

usage: caps2esc [-h | [-m mode] [-t delay]]

options:
    -h        show this message and exit
    -t        delay used for key sequences (default: 20000 microseconds)
    -m mode   0: default
                 - caps as esc/ctrl
                 - esc as caps
              1: minimal
                 - caps as esc/ctrl
              2: useful on 60% layouts
                 - caps as esc/ctrl
                 - esc as grave accent
                 - grave accent as caps

caps2esc is an Interception Tools plugin. A suggested udevmon job configuration (check the Interception Tools README for alternatives) is:

- JOB: intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE
  DEVICE:
    EVENTS:
      EV_KEY: [KEY_CAPSLOCK, KEY_ESC]

For more information about the Interception Tools, check the project's website.

Mouse/Touchpad Support

After Interception Tools 0.3.2, caps2esc can observe (or replace) mouse events. An example configuration taken from my laptop:

SHELL: [zsh, -c]
---
- CMD: mux -c caps2esc
- JOB: mux -i caps2esc | caps2esc | uinput -c /etc/interception/keyboard.yaml
- JOB: intercept -g $DEVNODE | mux -o caps2esc
  DEVICE:
    LINK: /dev/input/by-path/platform-i8042-serio-0-event-kbd
- JOB: intercept $DEVNODE | mux -o caps2esc
  DEVICE:
    LINK: /dev/input/by-path/platform-i8042-serio-4-event-mouse

For more information on the topic, check the Interception Tools README about usage of the mux tool and hybrid virtual device configurations.

Installation

Archlinux

It's available from community:

$ pacman -S interception-caps2esc

Void Linux

$ xbps-install -S caps2esc
sudo add-apt-repository ppa:deafmute/interception
sudo apt install interception-caps2esc

For debian and other derivatives you can download directly at https://launchpad.net/~deafmute/+archive/ubuntu/interception/+packages.

Caveats

As always, there's always a caveat:

  • intercept -g will "grab" the detected devices for exclusive access.
  • If you tweak your key repeat settings, check whether they get reset. Please check this report about the resolution.

History

I can't recall when I started using CAPSLOCK as both ESC and CTRL but it has been quite some time already. It started when I was on OS X where it was quite easy to achieve using the Karabiner, which already provides an option to turn CTRL into ESC/CTRL (which can be coupled with OS X system settings that turn CAPSLOCK into CTRL).

Moving on, permanently making Linux my home, I searched and tweaked a similar solution based on xmodmap and xcape:

It's a simple solution but with many annoying drawbacks I couldn't stand in the end:

  • It resets any time a device change happens (bluetooth, usb, any) or the laptop lid is closed or when logging off and needs to be re-executed.
  • It depends on X. Doesn't work on TTY (bare terminal based machine, CTRL-ALT F2, etc).

Meanwhile on Windows land, I had a definitive solution based on my Interception library that always works perfectly, no hiccups.

It made me envy enough, so I ported the Windows Interception caps2esc sample to Linux based upon the Interception Tools.

License

MIT

Copyright © 2017 Francisco Lopes da Silva

About

Rebind Caps Lock to Esc at evdev level using interception-tools

License:MIT License


Languages

Language:C 96.0%Language:CMake 4.0%