Skip to content
/ gokbd Public

A go library to manipulate keyboards using libevdev

License

Notifications You must be signed in to change notification settings

joshuar/gokbd

Repository files navigation

gokbd

GitHub Go Reference gokbd codecov

About

gokbd is a package that uses libevdev to talk to a keyboard on Linux. It allows snooping the keys pressed as well as typing out keys.

Usage

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:

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:
sudo gpasswd -a $USER input
  • To create a virtual keyboard and write to it, the user will need access to the kernel uinput device. Typically, this can be granted with a udev rule like the following:
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:

sudo setcap cap_setgid,cap_setuid=p /path/to/binary

About

A go library to manipulate keyboards using libevdev

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages