//Disable all dinput devices for xinput controllers public void Lock_DX_Devices() { var directInput = new DirectInput(); try { IList<DeviceInstance> devicelist = directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AttachedOnly); foreach (DeviceInstance cdevice in devicelist) { if (cdevice.InstanceName.Trim('\0') == XINPUT_NAME) { var joystick = new Joystick(directInput, cdevice.InstanceGuid); joystick.Acquire(); Guid deviceGUID = joystick.Properties.ClassGuid; string devicePath = joystick.Properties.InterfacePath; joystick.Unacquire(); string[] dpstlit = devicePath.Split('#'); devicePath = @"HID\" + dpstlit[1].ToUpper() + @"\" + dpstlit[2].ToUpper(); lockedDevices.Add(new DeviceID(deviceGUID, devicePath)); DeviceHelper.SetDeviceEnabled(deviceGUID, devicePath, false); } } } finally { directInput.Dispose(); } }
/// <summary> /// Implement interface for disposing. /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (disposing) { _directInputAdapter?.Dispose(); } }
protected override void Cleanup() { _subsysKeyboard?.Dispose(); _subsysKeyboard = null; _subsysMouse?.Dispose(); _subsysMouse = null; di?.Dispose(); di = null; base.Cleanup(); }
public void Dispose() { _nativeDirectInput?.Dispose(); }
public void Shutdown() { mouse.Dispose(); keyboard.Dispose(); directInput.Dispose(); }
/// <summary> /// Disposes all resources. /// </summary> public void Dispose() { directInput.Dispose(); }
//call this on call back when something is beeing plugged in or unplugged void InitializeJoystickIfPossible() { // try to dispose of the old joystick if (m_joystick != null) { m_joystick.Dispose(); m_joystick = null; m_joystickConnected = false; m_joystickType = null; } if (m_joystick == null) { // Joystick disabled? if (m_joystickInstanceName == null) return; // Make sure that DirectInput has been initialized DirectInput dinput = new DirectInput(); // Try to grab the joystick with the correct instance name foreach (var device in dinput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly)) { if (device.InstanceName != m_joystickInstanceName) continue; try { //device.Type m_joystick = new Joystick(dinput, device.InstanceGuid); m_joystickType = device.Type; MethodInfo setCooperativeLevel = typeof(Device).GetMethod("SetCooperativeLevel", new[] { typeof (IntPtr), typeof (CooperativeLevel) }); // Workaround for not need to reference System.Windows.Forms setCooperativeLevel.Invoke(m_joystick, new object[] { MyMinerGame.Static.Window.NativeWindow.Handle, CooperativeLevel.Exclusive | CooperativeLevel.Foreground }); break; } catch (SharpDX.SharpDXException) { } } // load and acquire joystick // both joystick and xbox 360 gamepad are treated as joystick device by slimdx if (m_joystick != null) { int sliderCount = 0; m_joystickXAxisSupported = m_joystickYAxisSupported = m_joystickZAxisSupported = false; m_joystickRotationXAxisSupported = m_joystickRotationYAxisSupported = m_joystickRotationZAxisSupported = false; m_joystickSlider1AxisSupported = m_joystickSlider2AxisSupported = false; foreach (DeviceObjectInstance doi in m_joystick.GetObjects()) { if ((doi.ObjectId.Flags & DeviceObjectTypeFlags.Axis) != 0) { // set range 0..65535 for each axis m_joystick.GetObjectPropertiesById(doi.ObjectId).Range = new InputRange(0, 65535); // find out which axes are supported if (doi.ObjectType == ObjectGuid.XAxis) m_joystickXAxisSupported = true; else if (doi.ObjectType == ObjectGuid.YAxis) m_joystickYAxisSupported = true; else if (doi.ObjectType == ObjectGuid.ZAxis) m_joystickZAxisSupported = true; else if (doi.ObjectType == ObjectGuid.RxAxis) m_joystickRotationXAxisSupported = true; else if (doi.ObjectType == ObjectGuid.RyAxis) m_joystickRotationYAxisSupported = true; else if (doi.ObjectType == ObjectGuid.RzAxis) m_joystickRotationZAxisSupported = true; else if (doi.ObjectType == ObjectGuid.Slider) { sliderCount++; if (sliderCount >= 1) m_joystickSlider1AxisSupported = true; if (sliderCount >= 2) m_joystickSlider2AxisSupported = true; } } } // acquire the device m_joystick.Acquire(); m_joystickConnected = true; } dinput.Dispose(); } }