public InputDeviceManager(Window window, MainWindow.ToggleOverlayCallback _toggleOverlayCallback) { InputConfig = new InputConfiguration(); _directInput = new DirectInput(); var deviceInstances = _directInput.GetDevices(); WindowHelper = new WindowInteropHelper(window); this._toggleOverlayCallback = _toggleOverlayCallback; foreach (var deviceInstance in deviceInstances) { //Workaround for Bad Devices that pretend to be joysticks if (!IsBlackListed(deviceInstance.ProductGuid)) { Logger.Info("Found " + deviceInstance.ProductGuid + " Instance: " + deviceInstance.InstanceGuid + " " + deviceInstance.ProductName.Trim().Replace("\0", "") + " Usage: " + deviceInstance.UsagePage); if (deviceInstance.Type == DeviceType.Keyboard) { Logger.Info("Adding " + deviceInstance.ProductGuid + " Instance: " + deviceInstance.InstanceGuid + " " + deviceInstance.ProductName.Trim().Replace("\0", "")); var device = new Keyboard(_directInput); device.SetCooperativeLevel(WindowHelper.Handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); device.Acquire(); _inputDevices.Add(device); } else if (deviceInstance.Type >= DeviceType.Joystick && deviceInstance.Type <= DeviceType.FirstPerson || IsWhiteListed(deviceInstance.ProductGuid)) { var device = new Joystick(_directInput, deviceInstance.InstanceGuid); Logger.Info("Adding " + deviceInstance.ProductGuid + " Instance: " + deviceInstance.InstanceGuid + " " + deviceInstance.ProductName.Trim().Replace("\0", "")); device.SetCooperativeLevel(WindowHelper.Handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); device.Acquire(); _inputDevices.Add(device); } } else { Logger.Info("Found but ignoring " + deviceInstance.ProductGuid + " Instance: " + deviceInstance.InstanceGuid + " " + deviceInstance.ProductName.Trim().Replace("\0", "") + " Type: " + deviceInstance.Type); } } }
public InputDeviceManager(Window window, MainWindow.ToggleOverlayCallback _toggleOverlayCallback) { _directInput = new DirectInput(); WindowHelper = new WindowInteropHelper(window); this._toggleOverlayCallback = _toggleOverlayCallback; LoadWhiteList(); LoadBlackList(); InitDevices(); }
public InputDeviceManager(Window window, MainWindow.ToggleOverlayCallback _toggleOverlayCallback) { _directInput = new DirectInput(); var deviceInstances = _directInput.GetDevices(); WindowHelper = new WindowInteropHelper(window); this._toggleOverlayCallback = _toggleOverlayCallback; LoadWhiteList(); LoadBlackList(); Logger.Info("Starting Device Search. Expand Search: " + (_settings.GetClientSetting(SettingsKeys.ExpandControls).BoolValue)); foreach (var deviceInstance in deviceInstances) { //Workaround for Bad Devices that pretend to be joysticks if (!IsBlackListed(deviceInstance.ProductGuid)) { Logger.Info("Found Device ID:" + deviceInstance.ProductGuid + " " + deviceInstance.ProductName.Trim().Replace("\0", "") + " Usage: " + deviceInstance.UsagePage + " Type: " + deviceInstance.Type); if (deviceInstance.Type == DeviceType.Keyboard) { Logger.Info("Adding Device ID:" + deviceInstance.ProductGuid + " " + deviceInstance.ProductName.Trim().Replace("\0", "")); var device = new Keyboard(_directInput); device.SetCooperativeLevel(WindowHelper.Handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); device.Acquire(); _inputDevices.Add(device); } else if (deviceInstance.Type == DeviceType.Mouse) { Logger.Info("Adding Device ID:" + deviceInstance.ProductGuid + " " + deviceInstance.ProductName.Trim().Replace("\0", "")); var device = new Mouse(_directInput); device.SetCooperativeLevel(WindowHelper.Handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); device.Acquire(); _inputDevices.Add(device); } else if (((deviceInstance.Type >= DeviceType.Joystick) && (deviceInstance.Type <= DeviceType.FirstPerson)) || IsWhiteListed(deviceInstance.ProductGuid)) { var device = new Joystick(_directInput, deviceInstance.InstanceGuid); Logger.Info("Adding ID:" + deviceInstance.ProductGuid + " " + deviceInstance.ProductName.Trim().Replace("\0", "")); device.SetCooperativeLevel(WindowHelper.Handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); device.Acquire(); _inputDevices.Add(device); } else if (SettingsStore.Instance.GetClientSetting(SettingsKeys.ExpandControls).BoolValue) { Logger.Info("Adding (Expanded Devices) ID:" + deviceInstance.ProductGuid + " " + deviceInstance.ProductName.Trim().Replace("\0", "")); var device = new Joystick(_directInput, deviceInstance.InstanceGuid); device.SetCooperativeLevel(WindowHelper.Handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); device.Acquire(); _inputDevices.Add(device); Logger.Info("Added (Expanded Device) ID:" + deviceInstance.ProductGuid + " " + deviceInstance.ProductName.Trim().Replace("\0", "")); } } else { Logger.Info("Found but ignoring blacklist device " + deviceInstance.ProductGuid + " Instance: " + deviceInstance.InstanceGuid + " " + deviceInstance.ProductName.Trim().Replace("\0", "") + " Type: " + deviceInstance.Type); } } }