16 releases

0.12.2 May 8, 2024
0.12.1 Dec 9, 2022
0.12.0 Aug 18, 2022
0.11.5 Mar 5, 2022
0.9.2 Jul 21, 2015

#115 in Unix APIs

Download history 3458/week @ 2024-08-14 3580/week @ 2024-08-21 4002/week @ 2024-08-28 4553/week @ 2024-09-04 4018/week @ 2024-09-11 3834/week @ 2024-09-18 4617/week @ 2024-09-25 3685/week @ 2024-10-02 3663/week @ 2024-10-09 4015/week @ 2024-10-16 4437/week @ 2024-10-23 5040/week @ 2024-10-30 3716/week @ 2024-11-06 4631/week @ 2024-11-13 4165/week @ 2024-11-20 3461/week @ 2024-11-27

16,797 downloads per month
Used in 41 crates (40 directly)

Apache-2.0 OR MIT

175KB
4K SLoC

evdev

GitHub Workflow Status Crates.io

Documentation

Nice(r) access to evdev devices.

What is evdev?

evdev is the Linux kernel's generic input interface, also implemented by other kernels such as FreeBSD.

libevdev is a userspace library written in c for interacting with this system in a high level way rather than using ioctl system calls directly.

This crate is a re-implementation of libevdev in rust. There is some trickery involved, so please read the crate documentation.

There is also an alternative crate: evdev-rs which wraps libevdev instead.

Overview

This crate provides functionality for reading streams of events from input devices.

Like libevdev, this crate also provides functionality for interacting with uinput. Uinput is a kernel module which allows virtual input devices to be created from userspace.

Synchronization

This library exposes raw evdev events, but uses the Rust Iterator trait to do so. When processing events via fetch_events, the library will handle SYN_DROPPED events by injecting fake state updates in an attempt to ensure callers see state transition messages consistent with actual device state. When processing via *_no_sync this correction is not done, and SYN_DROPPED messages will appear if the kernel ring buffer is overrun before messages are read. I try to match libevdev closely, where possible.

Limitations

There is no abstraction for gamepad-like devices that allows mapping button numbers to logical buttons, nor is one planned. Such a thing should take place in a higher-level crate, likely supporting multiple platforms.

Example

Plenty of nice examples of how to use this crate can be found in the examples directory of this repository. If you feel like an example of how to use a certain part of the evdev crate is missing, then feel free to open a pull request.

A good introduction is the evtest.rs example (which roughly corresponds to the userspace evtest tool.

Releases

Detailed release notes are available in this repository at CHANGELOG.md.

Dependencies

~3–11MB
~136K SLoC