private static List <EvDevDevice> OpenMouseDevices() { var rv = new List <EvDevDevice>(); foreach (var dev in Directory.GetFiles("/dev/input", "event*").Select(Open)) { if (!dev.IsMouse) { NativeUnsafeMethods.close(dev.Fd); } else { rv.Add(dev); } } return(rv); }
public static EvDevDevice Open(string device) { var fd = NativeUnsafeMethods.open(device, 2048, 0); if (fd <= 0) { throw new Exception($"Unable to open {device} code {Marshal.GetLastWin32Error()}"); } IntPtr dev; var rc = NativeUnsafeMethods.libevdev_new_from_fd(fd, out dev); if (rc < 0) { NativeUnsafeMethods.close(fd); throw new Exception($"Unable to initialize evdev for {device} code {Marshal.GetLastWin32Error()}"); } return(new EvDevDevice(fd, dev)); }