klack is a lightweight, zero-configuration mechanical keyboard sound simulator for Linux. It runs seamlessly in the background, listens directly to your selected input devices, and is designed to be easily managed as a standard systemd user service.
The application is completely agnostic to the host windowing system or compositor, so will work the same whether you are on Wayland, X11, or running in a bare TTY.
This project started as a quick afternoon project after trying out Opera GX, and liking the typing sounds feature it includes. My original intent was just to implement it for fun as a personal project, but I decided others may find use for it, so cleaned it up and turned it into a proper application.
https://codeberg.org/ForeverZer0/klack
Installation
Ensure you have Zig >= 0.16.0 installed. Clone the repository and build using your preferred release configuration:
git clone ssh://git@codeberg.org/ForeverZer0/klack.git
cd klack
zig build -Doptimize=ReleaseFast
The compiled binary will be available at zig-out/bin/klack.
Arch Linux
klack is provided as an AUR package of the same name. You can use your preferred AUR helper, such as yay, paru, etc, to install it.
yay -S klack
This also installs the systemd units automatically and shell completions for zsh, bash, and fish. To configure any desired options when using the service, the environment variables can be used. Thesse can be defined in a new $HOME/.config/environment.d/10-klack.conf so that systemd picks them up without relying upon initializing scripts of your WM/DE.
# $HOME/.config/environment.d/10-klack.conf
KLACK_SOUNDPACK="$HOME/.config/klack/mechanical"
KLACK_EXCLUDE="modifier_keys"
KLACK_VOLUME="0.8"
Usage
klack - A mechanical keyboard sound simulator
USAGE:
klack [OPTIONS]
OPTIONS:
-s, --soundpack <PATH> Path to a directory or .tar.gz archive containing sounds
-d, --device <PATH> Target device path or name (default: primary keyboard)
-v, --volume <VOLUME> Volume scaling from 0.0 to 1.0 (default: 1.0)
-r, --repeat Enable sound playback on key repeat events
-b, --background Run the process in the background (daemonize)
--list-devices List available input devices and exit
--list-keys List valid key names for custom sounds
--list-buttons List valid button names for custom sounds
--list-groups List valid tokens that define logical groups of keys/buttons
-a, --alsa-device <NAME> The backend device used by ALSA (default: "default")
-e, --exclude <TOKEN>[,...] Comma-separated list of key/buttons/groups to exclude
--max-voices <COUNT> Number of simultaneous effects that can play (1-16)(default: 4)
-h, --help Print this help message and exit
EXAMPLES:
klack --soundpack ~/.config/klack/mx-blues.tar.gz --background
klack -s ./sounds/custom/ -v 0.7 --repeat
klack --list-devices
klack --device "AT Translated Set 2 keyboard"
klack --d platform-i8042-serio-0-event-kbd
klack --exclude modifier_keys,key_esc
Quick Examples
Run manually in the foreground with a specific sound archive:
klack --soundpack ~/.config/klack/typewriter.tar.gz
Run in the background with a lower volume and key-repeat sounds enabled:
klack -s ./sounds/custom/ -v 0.7 --repeat --background
Environment Variables
The following environment variables may also be used to provide default configuration for options not specified on the command-line, which always have precedence.
KLACK_SOUNDPACKKLACK_DEVICEKLACK_VOLUMEKLACK_REPEATKLACK_ALSA_DEVICEKLACK_EXCLUDEKLACK_MAX_VOICES
LLM/AI Usage
- No LLM or AI was used for any code within this project, and never will.
- Google Gemini was used to generate the logo. Full credit goes to all the unnamed artists who had their work used for its training data.
Supported Zig versions
Zig 0.16+
Tested on the following:
- 0.16.0
- 0.17.0-dev.1397+4331ba0fb