janus-key provides keys with a secondary function, so that they send one input when pressed and released, but another input when held down and used in combination with other keys.
janus-key sits at a relatively low level, so it works regardless of whether you are using X, Wayland or neither.
janus-key does not require systemd.
Configuration is simple.
- Turning normal keys (e.g. CAPSLOCK or ENTER) into modifiers (e.g. CTRL or ALT) when held down. Emacs users, for example, can do so to keep their pinkie healthy without indulging in the keybindings of the beast.
- Turning modifiers into normal keys when pressed and released. Vim/evil users, for example, can do so to exit insert mode by pressing an easily reachable modifier.
Install libevdev on your system if you have not already.
Edit the mod_map in config.h
For example, the following simply turns ESC into CAPSLOCK:
{ KEY_ESC, KEY_CAPSLOCK }
The following makes ENTER behave as RIGHTALT when held down, leaving untouched ENTER’s behaviour when pressed and released:
{ KEY_ENTER, 0, KEY_RIGHTALT }
The following changes both CAPSLOCK’s primary function and secondary function, so that it behaves as ESC when pressed and released, but as LEFTALT when held down:
{ KEY_CAPSLOCK, KEY_ESC, KEY_LEFTALT }
You can find the names of the keys of a certain device by using evtest.
A key sends its primary function if pressed and relased within a
certain time. To set this time change the value of max_delay
(see
the config.h file for info).
Compile with
gcc `pkg-config --cflags libevdev` janus-key.c `pkg-config --libs libevdev` -o janus-key
Run
sudo ./janus-key /dev/input/event<NUMBER>
janus-key
Copyright (C) 2021, 2022, 2023 Giulio Pietroiusti
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.