Python-uinput

Pythonic API to the Linux uinput kernel module.

Latest version:0.9
License:GPLv3+
Bug tracker:Launchpad
Source code:GitHub

Python-uinput is Python interface to the Linux uinput kernel module which allows attaching userspace device drivers into kernel. In practice, python-uinput makes it dead simple to create virtual devices which emulate real input devices like joysticks, keyboards and mice.

Usage

The following small example shows how to create a simple keyboard device to emit keyboard press/release events to the kernel.

import uinput

events = (uinput.KEY_E, uinput.KEY_H, uinput.KEY_L, uinput.KEY_O)

device = uinput.Device(events)

device.emit(uinput.KEY_H, 1) # Press.
device.emit(uinput.KEY_H, 0) # Release.
device.emit(uinput.KEY_E, 1)
device.emit(uinput.KEY_E, 0)
device.emit(uinput.KEY_L, 1)
device.emit(uinput.KEY_L, 0)
device.emit(uinput.KEY_L, 1)
device.emit(uinput.KEY_L, 0)
device.emit(uinput.KEY_O, 1)
device.emit(uinput.KEY_O, 0)

Installing

Debian and Ubuntu

If you are using Debian or Ubuntu, by far the easiest way to install python-uinput is install it from a pre-compiled and packaged .deb-package. Each release is packaged in my private package archive (PPA). Add it to your package sources with the following command:

sudo add-apt-repository ppa:tuomasjjrasanen/tjjr

And then install Python-uinput:

sudo apt-get install python-uinput

Others

For other systems, the recommended way to install Python-uinput is to compile it from the source code. To get the source code, you can either clone the development repository or fetch the latest release tarball. For detailed build instructions, please refer to README in the root directory of the source code.