// Function is recreted as soon as new DirectInput Device is available. public void ResetDiMenuStrip(Device device) { DiMenuStrip.Items.Clear(); ToolStripMenuItem mi; mi = new ToolStripMenuItem(cEmpty); mi.ForeColor = SystemColors.ControlDarkDark; mi.Click += new EventHandler(DiMenuStrip_Click); DiMenuStrip.Items.Add(mi); // Return if direct input device is not available. if (device == null) return; // Add [Record] button. mi = new ToolStripMenuItem(cRecord); mi.Image = new Bitmap(Helper.GetResource("Images.bullet_ball_glass_red_16x16.png")); mi.Click += new EventHandler(DiMenuStrip_Click); DiMenuStrip.Items.Add(mi); // Add Buttons. mi = new ToolStripMenuItem("Buttons"); DiMenuStrip.Items.Add(mi); CreateItems(mi, "Button {0}", "b{0}", device.Capabilities.ButtonCount); // Add Axes. mi = new ToolStripMenuItem("Axes"); DiMenuStrip.Items.Add(mi); var axisCount = diControl.Axis.Length; CreateItems(mi, "Inverted", "IAxis {0}", "a-{0}", axisCount); CreateItems(mi, "Inverted Half", "IHAxis {0}", "x-{0}", axisCount); CreateItems(mi, "Half", "HAxis {0}", "x{0}", axisCount); CreateItems(mi, "Axis {0}", "a{0}", axisCount); // Add Sliders. mi = new ToolStripMenuItem("Sliders"); DiMenuStrip.Items.Add(mi); var slidersCount = 8; CreateItems(mi, "Inverted", "ISlider {0}", "s-{0}", slidersCount); CreateItems(mi, "Inverted Half", "IHSlider {0}", "h-{0}", slidersCount); CreateItems(mi, "Half", "HSlider {0}", "h{0}", slidersCount); CreateItems(mi, "Slider {0}", "s{0}", slidersCount); // Add D-Pads. mi = new ToolStripMenuItem("DPads"); DiMenuStrip.Items.Add(mi); CreateItems(mi, "DPad {0}", "p{0}", device.Capabilities.PovCount); // Add D-Pad Top, Right, Bottom, Left button. for (int i = 0; i < mi.DropDownItems.Count; i++) { var item = (ToolStripMenuItem)mi.DropDownItems[i]; foreach (string p in Enum.GetNames(typeof(DPadEnum))) { var item2 = CreateItem("{0} {2}", "{1}{2}", item.Text, item.Tag, p); item.DropDownItems.Add(item2); } } }
internal DeviceProperties(Device device) : base(device, 0, PropertyHowType.Device) { }
/// <summary> /// Initializes a new instance of the <see cref="Effect"/> class. /// </summary> /// <param name="device">The device.</param> /// <param name="guid">The GUID.</param> /// <param name="parameters">The parameters.</param> public Effect(Device device, Guid guid, EffectParameters parameters) { device.CreateEffect(guid, parameters, this, null); }
// Use special function or comparison fails. public static bool IsSameDevice(Device device, Guid instanceGuid) { return instanceGuid.Equals(device == null ? Guid.Empty : device.Information.InstanceGuid); }
//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; SetJoystickConnected(false); m_joystickType = null; } if (m_joystick == null) { // Joystick disabled? if (m_joystickInstanceName == null) return; // Try to grab the joystick with the correct instance name var attachedDevices = MyDirectInput.DirectInput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly); foreach (var device in attachedDevices) { if (device.InstanceName != m_joystickInstanceName) continue; try { //device.Type m_joystick = new Joystick(MyDirectInput.DirectInput, device.InstanceGuid); m_joystickType = device.Type; //MethodInfo setCooperativeLevel = typeof(Device).GetMethod("SetCooperativeLevel", // new[] // { // typeof (IntPtr), // typeof (CooperativeLevel) // }); m_joystick.SetCooperativeLevel(m_windowHandle, CooperativeLevel.NonExclusive | CooperativeLevel.Background); //// Workaround for not need to reference System.Windows.Forms //setCooperativeLevel.Invoke(m_joystick, // new object[] // { // m_windowHandle, // CooperativeLevel.NonExclusive | CooperativeLevel.Background // }); 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 try { m_joystick.Acquire(); SetJoystickConnected(true); } catch (SharpDX.SharpDXException) { } } } }
internal ObjectProperties(Device device, int code, PropertyHowType howType) : base(device, code, howType) { }
void ShowDeviceInfo(Device device) { if (device == null) { // clean everything here. SetValue(DeviceProductNameTextBox, ""); SetValue(DeviceProductGuidTextBox, ""); SetValue(DeviceInstanceGuidTextBox, ""); DiCapFfLabel.Text = string.Empty; DiCapAxesLabel.Text = string.Empty; DiCapButtonsLabel.Text = string.Empty; DiCapDPadsLabel.Text = string.Empty; DiEffectsTable.Rows.Clear(); return; } lock (MainForm.XInputLock) { var isLoaded = XInput.IsLoaded; if (isLoaded) XInput.FreeLibrary(); device.Unacquire(); device.SetCooperativeLevel(MainForm.Current, CooperativeLevel.Foreground | CooperativeLevel.Exclusive); effects = new List<EffectInfo>(); try { device.Acquire(); var forceFeedback = device.Capabilities.Flags.HasFlag(DeviceFlags.ForceFeedback); forceFeedbackState = forceFeedback ? "YES" : "NO"; effects = device.GetEffects(EffectType.All); } catch (Exception) { forceFeedbackState = "ERROR"; } DiEffectsTable.Rows.Clear(); foreach (var eff in effects) { DiEffectsTable.Rows.Add(new object[]{ eff.Name, ((EffectParameterFlags)eff.StaticParameters).ToString(), ((EffectParameterFlags)eff.DynamicParameters).ToString() }); } device.Unacquire(); device.SetCooperativeLevel(MainForm.Current, CooperativeLevel.Background | CooperativeLevel.NonExclusive); if (isLoaded) XInput.ReLoadLibrary(XInput.LibraryName); } DiCapFfLabel.Text = string.Format("Force Feedback: {0}", forceFeedbackState); DiCapAxesLabel.Text = string.Format("Axes: {0}", device.Capabilities.AxeCount); DiCapButtonsLabel.Text = string.Format("Buttons: {0}", device.Capabilities.ButtonCount); DiCapDPadsLabel.Text = string.Format("D-Pads: {0}", device.Capabilities.PovCount); var di = device.Information; // Update pid and vid always so they wont be overwritten by load settings. short vid = BitConverter.ToInt16(di.ProductGuid.ToByteArray(), 0); short pid = BitConverter.ToInt16(di.ProductGuid.ToByteArray(), 2); SetValue(DeviceVidTextBox, "0x{0}", vid.ToString("X4")); SetValue(DevicePidTextBox, "0x{0}", pid.ToString("X4")); SetValue(DeviceProductNameTextBox, di.ProductName); SetValue(DeviceProductGuidTextBox, di.ProductGuid.ToString()); SetValue(DeviceInstanceGuidTextBox, di.InstanceGuid.ToString()); SetValue(DeviceTypeTextBox, di.Type.ToString()); }
private string GetNiceInputName(string deviceInput, Device device) { switch (device.Information.Type) { case DeviceType.Keyboard: return deviceInput.Replace ("Menu", "Alt"); case DeviceType.Mouse: return "Mouse " + (Int32.Parse(deviceInput) + 1); default: string[] parts = deviceInput.Split (';'); string r = device.Properties.ProductName + " " + device.Information.InstanceName; if (parts.Length == 2) r += parts[1]; return r; } }