libevdevxx 0.4.0
A C++ wrapper for libevdev.
Loading...
Searching...
No Matches
Introduction

libevdevxx is a C++20 wrapper for the C library libevdev, which is a high-level C library for the evdev Linux driver. This library exposes all of libevdev as C++ classes and methods, with RAII and type safety.

It's released under the MIT license, the same used by libevdev.

Example

In this example, a virtual device is created to mimick a mouse. Then events are inserted to simulate the mouse moving in a circle.

#include <chrono>
#include <cmath>
#include <iostream>
#include <thread>
using std::cout;
using std::endl;
using std::flush;
using namespace std::literals;
int main()
{
using evdev::Code;
dev.name("Fake Mouse");
dev.enable_rel(Code{REL_X});
dev.enable_rel(Code{REL_Y});
// needs at least one button to be recognized as a mouse
dev.enable_key(Code{BTN_LEFT});
evdev::Uinput udev{dev};
cout << "Created uinput device at "
<< udev.devnode().value()
<< endl;
cout << "Doing a circle... " << flush;
const float radius = 10;
for (int i = 0; i < 100; ++i) {
float angle = i/100.0f * 2 * M_PI;
int x = static_cast<int>(radius * std::cos(angle));
int y = static_cast<int>(radius * std::sin(angle));
udev.rel(Code{REL_X}, x);
udev.rel(Code{REL_Y}, y);
udev.flush();
std::this_thread::sleep_for(16ms);
}
cout << "done." << endl;
}
Represents a device (real of not).
Definition: Device.hpp:52
std::string name() const
void enable_key(Code code)
void enable_rel(Code code)
A class to send events to a virtual device.
Definition: Uinput.hpp:27
Type-safe class for evdev codes (KEY_*, BTN_*, REL_*, etc).
Definition: Code.hpp:32