This package provides bindings to the generic input event interface in Linux. The evdev interface serves the purpose of passing events generated in the kernel directly to userspace through character devices that are typically located in /dev/input/.

This package also comes with bindings to uinput, the userspace input subsystem. Uinput allows userspace programs to create and handle input devices that can inject events directly into the input subsystem.

In other words, python-evdev allows you to read and write input events on Linux. An event can be a key or button press, a mouse movement or a tap on a touchscreen.

Quick Start


The following GNU/Linux distributions have python-evdev in their package repositories:

The latest stable version of python-evdev can be installed from pypi, provided that you have gcc/clang, pip and the Python and Linux development headers installed on your system. Installing them is distribution specific and typically falls in one of the following categories:

On a Debian compatible OS:

$ apt-get install python-dev python-pip gcc
$ apt-get install linux-headers-$(uname -r)

On a Redhat compatible OS:

$ yum install python-devel python-pip gcc
$ yum install kernel-headers-$(uname -r)

On Arch Linux and derivatives:

$ pacman -S core/linux-api-headers python-pip gcc

Installing python-evdev with pip:

$ sudo pip install evdev

Listing accessible event devices:

>>> import evdev

>>> devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
>>> for device in devices:
...    print(device.fn,, device.phys)
/dev/input/event1    Dell Dell USB Keyboard   usb-0000:00:12.1-2/input0
/dev/input/event0    Dell USB Optical Mouse   usb-0000:00:12.0-2/input0

Reading events from a device:

>>> import evdev

>>> device = evdev.InputDevice('/dev/input/event1')
>>> print(device)
device /dev/input/event1, name "Dell Dell USB Keyboard", phys "usb-0000:00:12.1-2/input0"

>>> for event in device.read_loop():
...     if event.type == evdev.ecodes.EV_KEY:
...         print(categorize(event))
... # pressing 'a' and holding 'space'
key event at 1337016188.396030, 30 (KEY_A), down
key event at 1337016188.492033, 30 (KEY_A), up
key event at 1337016189.772129, 57 (KEY_SPACE), down
key event at 1337016190.275396, 57 (KEY_SPACE), hold
key event at 1337016190.284160, 57 (KEY_SPACE), up

Reading events using async/await:

Python-evdev proudly supports the new async/await syntax in Python 3.5:

import asyncio, evdev

async def print_events(device):
    async for event in device.async_read_loop():
        print(device.fn, evdev.categorize(event), sep=': ')

device = evdev.InputDevice('/dev/input/event4')

loop = asyncio.get_event_loop()

Accessing evdev constants:

>>> from evdev import ecodes

>>> ecodes.KEY_A, ecodes.ecodes['KEY_A']
... (30, 30)
>>> ecodes.KEY[30]
... 'KEY_A'
>>> ecodes.bytype[ecodes.EV_KEY][30]
... 'KEY_A'
>>> ecodes.KEY[152]  # a single value may correspond to multiple codes

Listing and monitoring input devices:

The python-evdev package also comes with a small command-line program for listing and monitoring input devices:

$ python -m evdev.evtest


Please refer to the changelog for a full list of changes.


The evdev package is released under the terms of the Revised BSD License.