Skip to content

A library for consuming evdev-capable devices

Notifications You must be signed in to change notification settings

afshin-parsa/evdev-sharp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

evdev-sharp

A library for consuming evdev-capable devices

What is evdev?

From Linux kernel docs:

Input subsystem is a collection of drivers that is designed to support all input devices under Linux. Most of the drivers reside in drivers/input, although quite a few live in drivers/hid and drivers/platform.

For more information refer to the Linux kernel docs.

How to use this library?

Each evdev device is represented with the EvDevDevice class. This class does not have a public constructor and in order to obtain device objects you must use the EvDevDevice.GetDevices() method. This method will enumerate each /dev/input/event* file and creates an object for each one.

Each EvDevDevice instance contains properties such as device's buttons and axises. It also provides events that you can subscribe to. In order to get events you must call the StartMonitoring() method on the instance. This method will constantly read the device's evdev file on a separate thread and will raise events accordingly.

Examples

The following code will list every evdev device on the system:

var devices = EvDevDevice.GetDevices().OrderBy(d => d.DevicePath).ToList();

for (int i = 0; i < devices.Count; i++)
{
    Console.WriteLine($"{i}) {devices[i].Name}");
}

The following code will get the first gamepad (joystick) on the system and will subscribe to its key events:

var gamepad = EvDevDevice.GetDevices()
    .First(d => d.GuessedDeviceType == EvDevGuessedDeviceType.GamePad);

gamepad.OnKeyEvent += (s, e) =>
{
    Console.WriteLine($"Button: {e.Key}\tState: {e.Value}");
};

gamepad.StartMonitoring();

There is also an example project (EvDevSharp.Example) that you can refer to.

About

A library for consuming evdev-capable devices

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%