Skip to content

Go interface to Linux uinput kernel module that makes it possible to emulate input devices from userspace

License

Notifications You must be signed in to change notification settings

sashko/go-uinput

Repository files navigation

go-uinput

License: MIT Build Status Coverage Status Go Report Card

go-uinput is a Go interface to the Linux uinput kernel module, allowing userspace to emulate input devices.

The interface aims to make it incredibly simple to create virtual input devices, such as keyboards, joysticks, or mice, for generating arbitrary input events programmatically.

System requirements

First, the system must have the uinput kernel module loaded:

sudo modprobe -i uinput

Second, the /dev/uinput device is owned by root, and therefore its default permissions must either be changed using chmod:

sudo chmod 666 /dev/uinput

Or, which is a much more preferred option, add the udev rule to allow a user to use the device:

echo KERNEL=="uinput", MODE="0666" | sudo tee /etc/udev/rules.d/90-$USER.rules
sudo udevadm trigger

Installation

To build the package from sources, clone the repository and run:

go build
go install

Alternatively, use go get to obtain and install the package in your $GOPATH:

go get github.com/sashko/go-uinput

Usage

The following example demonstrates how to create a new virtual keyboard and send a key press event, omitting all the default imports and error handling for the sake of simplicity:

func main() {
	keyboard, err := uinput.CreateKeyboard()

	defer keyboard.Close()

	// Press left Shift key, press G, release Shift
	keyboard.KeyDown(uinput.KeyLeftShift)
	keyboard.KeyPress(uinput.KeyG)
	keyboard.KeyUp(uinput.KeyLeftShift)

	// Press O key
	keyboard.KeyPress(uinput.KeyO)
}

About

Go interface to Linux uinput kernel module that makes it possible to emulate input devices from userspace

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages