public_gemini/comp/capslock.gmi
2024-11-21 23:01:28 +00:00

79 lines
3.7 KiB
Plaintext

# Making the CapsLock Key More Useful
The CapsLock key is one of the most useless keys on the keyboard for me, yet placed in the single best place a non-letter key could be placed. It's an obvious candidate for people looking to improve their keyboard layout.
I often heard people saying they rebound it to control or escape, which both sounded equally good to me, so I was never sure which to use. Then I heard someone mention that they use the key for BOTH at once. You press it and get the escape key, and hold it to get the control key. This sounded perfect, and is now in fact my single most-used key rebinding, to the point where I feel helpless when on a system without it.
Originally, I used some odd X11-specific software to achieve the rebind, but it was really flaky, and, of course, didn't work in a TTY or on Wayland. I then switched to interception-tools with the dual-function-keys plugin, but it's Linux-specific, and I couldn't even get it working on Gentoo, but it worked flawlessly on Arch.
## Keyd
Nowadays I use a piece of software called keyd. Its super simple, works on X11, TTY, and Wayland, and works* on FreeBSD.
=> https://github.com/rvaiya/keyd Keyd Github
> *On FreeBSD, it currently locks your input in a TTY, so it really only works on X11 and Wayland.
### Configuration
The configuration file goes in /etc/keyd/default.conf. Its capable of a lot of things, which you can find in its documentation, but this particular rebind is incredibly simple:
```
[ids]
*
[main]
capslock = overload(control, esc)
```
### Starting the Daemon
Now you just need to start the daemon. It comes with a systemd service file out of the box, so nothing special is needed there.
On systems running OpenRC, such as Gentoo, I recommend using the service file written in this blog post:
=> https://technex.us/2024/07/keyd-on-gentoo-with-openrc-and-kde-plasma/ Keyd on Gentoo with OpenRC and KDE Plasma
For convenience, I'll paste the script here. It should be put into /etc/init.d/keyd:
```
#!/sbin/openrc-run
# Description of the service
description="keyd key remapping daemon"
# The location of the keyd binary
command="/usr/local/bin/keyd"
#command_args="-d"
pidfile="/run/keyd.pid"
depend() {
need localmount
after bootmisc
}
start() {
ebegin "Starting keyd"
start-stop-daemon --start --exec $command --background --user root --make-pidfile --pidfile $pidfile --
eend $?
}
stop() {
ebegin "Stopping keyd"
start-stop-daemon --stop --pidfile $pidfile
eend $?
}
restart() {
ebegin "Restarting keyd"
start
eend $?
}
```
Once you have that, you can start and enable the daemon like any other.
FreeBSD has a service script built-in, but, as mentioned earlier, keyd on FreeBSD doesn't work in a TTY, so I actually just recommend starting keyd with your window manager. Note that you have to run it as root, though. I put the following into my /etc/doas.conf to let me run it without a password:
```
permit nopass :wheel cmd keyd
```
## Caveats
I find keyd to work great for my use-case, but I have noticed some caveats. Of course, there's the big one with FreeBSD, which does suck, but I don't use a TTY often enough to be too annoyed.
Another caveat is that it isn't particularly good at Unicode. It seems to emit Unicode characters as macros, using a really hacky solution, and I never actually managed to get it working. Github issues suggest that even when it does work, Wayland users still can't do it in Electron apps. Not that I use Electron anymore, but it's still something to look out for.
These caveats are fine with me, but I could see them being deal-breakers for others, so do be aware of them. There're plenty of alternatives, like interception-tools/dual-function-keys, or kmodmap, which can achieve the same thing.