Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshuar/gokbd
A go library to manipulate keyboards using libevdev
https://github.com/joshuar/gokbd
golang keyboard libevdev
Last synced: about 1 month 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 (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-24T10:18:07.000Z (about 1 year ago)
- Last Synced: 2023-10-25T06:23:38.826Z (about 1 year ago)
- Topics: golang, keyboard, libevdev
- Language: Go
- Homepage:
- Size: 74.2 KB
- Stars: 3
- 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
![GitHub](https://img.shields.io/github/license/joshuar/gokbd)
[![Go Reference](https://pkg.go.dev/badge/github.com/joshuar/gokbd.svg)](https://pkg.go.dev/github.com/joshuar/gokbd)
[![gokbd](https://goreportcard.com/badge/github.com/joshuar/gokbd?style=flat-square)](https://goreportcard.com/report/github.com/joshuar/gokbd)
[![codecov](https://codecov.io/gh/joshuar/gokbd/branch/main/graph/badge.svg?token=2BDVOTORZB)](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
./snoopcd 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
```