Giter Club home page Giter Club logo

go-uinput's Introduction

go-uinput

License: MIT Build Status Coverage Status Go Report Card

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

The interface aims to make it dead simple to create virtual input devices, e.g. keyboard, joystick, or mice for generating arbitrary input events programmatically.

System prerequisites

First, the system must have uinput kernel module loaded.

sudo modprobe -i uinput

Second, /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 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 shows how to create a new virtual keyboard, and how to send a key press event.

All the default imports and error handlers were removed 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)
}

go-uinput's People

Contributors

pietrocarrara avatar sashko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.