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.
The following GNU/Linux distributions have python-evdev in their 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 usually falls in one of these 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-headers python-pip gcc
Installing python-evdev with pip:
$ sudo pip install evdev
Listing accessible event devices:
>>> from evdev import InputDevice, list_devices >>> devices = [InputDevice(fn) for fn in list_devices()] >>> for dev in devices: ... print(dev.fn, dev.name, dev.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:
>>> from evdev import InputDevice, categorize, ecodes >>> dev = InputDevice('/dev/input/event1') >>> print(dev) device /dev/input/event1, name "Dell Dell USB Keyboard", phys "usb-0000:00:12.1-2/input0" >>> for event in dev.read_loop(): ... if event.type == 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
Accessing evdev constants:
>>> from evdev import ecodes >>> ecodes.KEY_A, ecodes.ecodes['KEY_A'] ... (30, 30) >>> ecodes.KEY ... 'KEY_A' >>> ecodes.bytype[ecodes.EV_KEY] ... 'KEY_A' >>> ecodes.KEY # a single value may correspond to multiple codes ... ['KEY_COFFEE', 'KEY_SCREENLOCK']
- Jul 06, 2014: Version 0.4.5 released.
- Jun 04, 2014: Version 0.4.4 released.
- Dec 19, 2013: Version 0.4.3 released.
- Dec 13, 2013: Version 0.4.2 released.
- Oct 17, 2013: Python-evdev is now available in Ubuntu Saucy.
- Oct 11, 2013: Python-evdev is now available in Arch Linux.
- Jul 24, 2013: Version 0.4.1 released.
- Jul 01, 2013: Version 0.4.0 released.
- May 29, 2013: Version 0.3.3 released.
- Apr 05, 2013: Version 0.3.2 released.
- Nov 23, 2012: Version 0.3.1 released.
- Nov 06, 2012: Version 0.3.0 released.
- Aug 22, 2012: Version 0.2.0 released.
- May 18, 2012: Version 0.1.1 released.
- May 17, 2012: Version 0.1.0 released.
See changelog for a full list of changes.