https://github.com/joshuar/gokbd
A go library to manipulate keyboards using libevdev
https://github.com/joshuar/gokbd
golang keyboard libevdev
Last synced: 9 months ago
JSON representation
A go library to manipulate keyboards using libevdev
- Host: GitHub
- URL: https://github.com/joshuar/gokbd
- Owner: joshuar
- License: mit
- Created: 2021-10-17T05:07:06.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-10-24T10:18:07.000Z (over 2 years ago)
- Last Synced: 2025-06-28T05:46:24.805Z (about 1 year ago)
- Topics: golang, keyboard, libevdev
- Language: Go
- Homepage:
- Size: 74.2 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# gokbd

[](https://pkg.go.dev/github.com/joshuar/gokbd)
[](https://goreportcard.com/report/github.com/joshuar/gokbd)
[](https://codecov.io/gh/joshuar/gokbd)
## About
gokbd is a package that uses
[libevdev](https://www.freedesktop.org/wiki/Software/libevdev/) to talk to a
keyboard on Linux. It allows snooping the keys pressed as well as typing out
keys.
## Usage
```go
import gokbd "github.com/joshuar/gokbd"
```
Examples for reading what keys are being typed (snooping) and writing to a
virtual keyboard are available under the `examples/` directory. To run them:
```shell
cd examples/snoop
go build
sudo setcap cap_setgid,cap_setuid=p ./snoop
./snoop
cd examples/type
go build
sudo setcap cap_setgid,cap_setuid=p ./type
./type
```
## Permissions
You may need to grant additional permissions to the user running any program
using `gokbd`.
- To read (snoop) from keyboards, the user will need to be part of the `input`
group. Typically, the user can be added with the following command:
```shell
sudo gpasswd -a $USER input
```
- To create a virtual keyboard and write to it, the user will need access to the
[kernel uinput
device](https://kernel.org/doc/html/latest/input/uinput.html). Typically, this
can be granted with a [udev rule](https://opensource.com/article/18/11/udev)
like the following:
```shell
echo KERNEL==\"uinput\", GROUP=\"$USER\", MODE:=\"0660\" | sudo tee /etc/udev/rules.d/99-$USER.rules
sudo udevadm trigger
```
You will also need to grant your compiled binary the `CAP_SETUID` and
`CAP_SETGID` Linux capabilities. You can do this with:
```shell
sudo setcap cap_setgid,cap_setuid=p /path/to/binary
```