aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: c065e25181122171619dc80fbca9cbddea9e1fc5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Keyboard Listener (kl)

## Description

`kl` is a lightweight, command-line global keystroke monitoring and echoing tool for GNU/Linux systems.

This tool is compiled directly to native binary with zero runtime dependencies. No Node.js, No Electron, No Python, **written in pure C**.

## Install

You can install it with aur.

```bash
paru -S kl
```

or build from source

```
git clone https://github.com/yingyu5658/keyboard-listener.git
cd keyboard-listener
sudo make install
```

## Usage

`kl` designs to interaction with low-level kernel input events directly via `/dev/input/eventx`. We need to find the keyboard event file.

```bash
λ ~/ ls /dev/input/by-path
pci-0000:00:14.0-usb-0:1:1.0-event-mouse  pci-0000:00:14.0-usb-0:9:1.1-event
pci-0000:00:14.0-usb-0:1:1.0-mouse        pci-0000:00:14.0-usb-0:9:1.1-event-kbd
pci-0000:00:14.0-usb-0:9:1.0-event-kbd    platform-pcspkr-event-spkr
```

Find a file which includes word like "keyboard", "kbd" and so on. For the first time of running `kl`, it will create a config file: `~/.klrc`, here is an example: 


```
# kl config file (v0.0.1)
#
# Please see your README for details.
#
# This file was auto-generated because it was missing.

device = /dev/input/by-path/pci-0000:00:14.0-usb-0:9:1.0-event-kbd

time = true

```

then run `sudo kl`:

```
λ ~/ sudo kl
Device: /dev/input/by-path/pci-0000:00:14.0-usb-0:9:1.0-event-kbd
2026-05-17 21:54:22.210831: P
2026-05-17 21:54:22.330827: R
2026-05-17 21:54:22.602797: O
2026-05-17 21:54:22.866822: G
2026-05-17 21:54:22.954814: R
2026-05-17 21:54:23.026817: A
2026-05-17 21:54:23.146814: M
2026-05-17 21:54:23.378821: M
2026-05-17 21:54:23.546794: I
2026-05-17 21:54:23.626831: N
2026-05-17 21:54:23.802818: G
2026-05-17 21:54:23.898808: <SPACE>
2026-05-17 21:54:24.082826: I
2026-05-17 21:54:24.554789: N
2026-05-17 21:54:24.746833: <SPACE>
2026-05-17 21:54:24.890809: P
2026-05-17 21:54:25.066811: U
2026-05-17 21:54:25.170807: R
2026-05-17 21:54:25.210811: E
2026-05-17 21:54:25.570792: <SPACE>
2026-05-17 21:54:25.762816: C
```

You can also disable time echo with `time = false`:

```
λ ~/dev/key-catcher/ main* sudo kl    
Device: /dev/input/by-path/pci-0000:00:14.0-usb-0:9:1.0-event-kbd
L
E
S
S
<SPACE>
I
S
<SPACE>
M
O
R
E
.

```

---

## SECURITY & PERMISSIONS

Due to the security model of modern Linux distributions (especially on Wayland/systemd-logind), direct access to these device nodes from an unprivileged GUI session is blocked to prevent unauthorized key logging.

If it can't work properly, add your user to `input` group, and reboot your computer.

```bash
sudo usermod -aG input $USER
```

## Report Bug

Feel free to create an issue or a pull request :)