/// <summary>True if the device is likely to be a mouse</summary> public static bool isMouse(this RawDevice device) { if (!device.otherHandlers.Any(s => s.startsWith("mouse"))) { return(false); } if (!device.buttonGroups.Contains(eButtonGroup.Mouse)) { return(false); } return(true); }
static RawDevice findDevice(Func <RawDevice, bool> selector, int index) { int i = 0; foreach (var dev in RawDevice.list()) { if (!selector(dev)) { continue; } if (i == index) { return(dev); } i++; } return(null); }
/// <summary>Open a raw mouse device and wrap it into an adapter that will call the provided object when input happens.</summary> public static iInputEventTimeSource openRawMouse(this Dispatcher dispatcher, iMouseHandler handler, CRect clipRect, RawDevice device = null) { // Find the mouse if (null == device) { device = RawDevice.list().FirstOrDefault(isMouse); if (null == device) { throw new ApplicationException("No mice are detected"); } } // Create the adapter to translate raw events into mouse events RawMouse mouse = clipRect.isEmpty ? new RawMouse(device, handler) : new RawMouseClipped(device, clipRect, handler); // Open the device using (iLinuxDispatcher linuxDispatcher = ComLightCast.cast <iLinuxDispatcher>(dispatcher.nativeDispatcher)) linuxDispatcher.openInputDevice(device.eventInterface, mouse); return(mouse); }
/// <summary>True if the device is likely to be a QUERTY keyboard</summary> public static bool isQwertyKeyboard(this RawDevice device) { if (!device.otherHandlers.Any(s => s.equals("kbd"))) { return(false); } byte foundKeys = 0; foreach (var k in device.keys) { if (!requiredKeyboardKeys.TryGetValue(k, out byte bit)) { continue; } foundKeys |= bit; if (foundKeys == requiredKeysMask) { return(true); } } return(false); }
/// <summary>Open a raw input device, interpret the input as a US English keyboard</summary> public static iInputEventTimeSource openRawKeyboard(this Dispatcher dispatcher, iKeyboardHandler handler, RawDevice device = null) { // Find the keyboard if (null == device) { device = RawDevice.list().FirstOrDefault(isQwertyKeyboard); if (null == device) { throw new ApplicationException("No keyboards found"); } } // Create the layout. That object also owns the state, i.e. shift/numlock/etc. iKeyboardLayout layout = new UsEnglishLayout(); // Create the adapter to translate raw events into keyboard events var keyboard = new RawKeyboard(device, layout, handler);; // Open the device using (iLinuxDispatcher linuxDispatcher = ComLightCast.cast <iLinuxDispatcher>(dispatcher.nativeDispatcher)) linuxDispatcher.openInputDevice(device.eventInterface, keyboard); return(keyboard); }
internal RawKeyboard(RawDevice device, iKeyboardLayout layout, iKeyboardHandler handler) { this.layout = layout; this.handler = handler; deviceName = device.name; if (deviceName.isEmpty()) { deviceName = device.productDescription; } if (deviceName.isEmpty()) { string mfg = device.manufacturer; if (mfg.notEmpty()) { deviceName = $"A keyboard made by { mfg }"; } else { deviceName = $"Unidentified { device.bus } keyboard"; } } }
internal RawMouse(RawDevice device, iMouseHandler handler) { this.handler = handler; buttons = device.buttons.ToArray(); deviceName = device.name; if (deviceName.isEmpty()) { deviceName = device.productDescription; } if (deviceName.isEmpty()) { string mfg = device.manufacturer; if (mfg.notEmpty()) { deviceName = $"A mouse made by { mfg }"; } else { deviceName = $"Unidentified { device.bus } mouse"; } } }
/// <summary>Open a raw mouse device and wrap it into an adapter that will call the provided object when input happens.</summary> public static iInputEventTimeSource openRawMouse(this Dispatcher dispatcher, iMouseHandler handler, RawDevice device = null) { return(openRawMouse(dispatcher, handler, CRect.empty, device)); }