This is a bpftrace-fork program to run locally that turns your keyboard into a noisy typewriter. Keystrokes make a "click" and the enter key makes a "ting".
This works by tracing the Linux tty driver using kprobes. Brendan Gregg first wrote tracing-typewriter tools in 2005.
- C Compiler ( Clang )
- bpftrace
- pipeweire for the
pw-play
command. You can edit the source to use a different audio player.
because the project with bpftrace need root acess and my root user can't play sound on my pipewire configuration, so i created a client-server side, to inform a key press and play the sound on user space.
also the project have use of a lot of resources because relay on OS process level of fork, to have to play the sound, this project relay on greenthreads for that and single-header files like stb
remember that the amount of code used and created may declassify this a fork of project, and maybe another project by it self.
Just use nobuild build system, with some extensions for this project in particular, for meta programming.
make first
./first
./bin/typewriter-song
or just use the old legacy with bpftrace by it self and the daemon to play the sound.
make first
./first
./bin/typewriter-song-daemon &
./typewriter.bt &
also can be run the daemon on another machine and play the typewriter sound on a stereo setup. ( just need some configuration to set network port and socket conection. )
Just the code:
#!/usr/bin/bpftrace --unsafe
/* copy from https://github.com/brendangregg/bpf-typewriter */
kprobe:kbd_event
/arg1 == 1 && arg3 == 1/
{
if (arg2 == 28) {
system("./bin/typewriter-song-sender ENT&");
} else {
system("./bin/typewriter-song-sender &");
}
}
the resource is also a systemd service, and TODO need to make more changes to compile eBPF programs from C source code.
I would have traced kbd_rawcode(), but it appears inlined and unavailable to kprobes. The --unsafe option is necessary because this tool is launching commands via system().