Python-uinput

Pythonic API to Linux uinput kernel module.

  • License: GPLv3+
  • Version: 0.10.2

Python-uinput is Python interface to Linux uinput kernel module which allows attaching userspace device drivers into kernel. In practice, Python-uinput makes it dead simple to create virtual joysticks, keyboards and mice for generating arbitrary input events programmatically.

Usage examples

Generate keyboard clicks

import uinput

device = uinput.Device([
        uinput.KEY_E,
        uinput.KEY_H,
        uinput.KEY_L,
        uinput.KEY_O,
        ])

device.emit_click(uinput.KEY_H)
device.emit_click(uinput.KEY_E)
device.emit_click(uinput.KEY_L)
device.emit_click(uinput.KEY_L)
device.emit_click(uinput.KEY_O)

Move mouse cursor

import uinput

device = uinput.Device([
        uinput.BTN_LEFT,
        uinput.BTN_RIGHT,
        uinput.REL_X,
        uinput.REL_Y,
        ])

for i in range(20):
    device.emit(uinput.REL_X, 5)
    device.emit(uinput.REL_Y, 5)

Generate keyboard combinations

import uinput

device = uinput.Device([
        uinput.KEY_LEFTALT,
        uinput.KEY_TAB,
        ])

device.emit_combo([
        uinput.KEY_LEFTALT,
        uinput.KEY_TAB,
        ])

Download and install

To get the source code, you can either clone the source code repository or fetch the latest source code release.

Then building and installing Python-uinput is just a matter of running:

python setup.py build
python setup.py install

Alternatively, you can use tools such as pip or easy_install to install Python-uinput from Python Package Index:

pip install python-uinput

or:

easy_install python-uinput