Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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
./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
```