private void detectButton(int ind) { // Still axes position dev.joystick.Poll(); int[] axes = ControllerDevice.GetAxes(dev.joystick.GetCurrentState()); byte[] res; // Wait until button pressed while (isBinding) { res = ifPressed(axes); if (res != null) { // Map Button dev.mapping[ind * 2] = res[0]; dev.mapping[(ind * 2) + 1] = res[1]; Invoke((MethodInvoker) delegate { Hide(); }); DialogResult = DialogResult.OK; isBinding = false; break; } } }
public ButtonBind(ControllerDevice device, int index) { InitializeComponent(); dev = device; isBinding = true; new Thread(() => { detectButton(index); }).Start(); }
public ControllerOptions(ControllerDevice device) { InitializeComponent(); dev = device; int ind = 0; //dev.keyboard.Acquire(); //KeyboardState kState = dev.keyboard.GetCurrentState(); //dev.keyboard.Unacquire(); foreach (MultiLevelComboBox m in this.Controls.OfType <MultiLevelComboBox>()) { //Tag structure: [Type, Number, Index] m.Items[0] = getBindingText(ind); //Change combobox text according to saved binding m.addOption("Disabled", tag: new byte[] { 255, 0, (byte)ind }); ToolStripMenuItem axes = m.addMenu("Axes"); ToolStripMenuItem buttons = m.addMenu("Buttons"); //ToolStripMenuItem keys = m.addMenu("Keys"); ToolStripMenuItem dpads = m.addMenu("D-Pads"); ToolStripMenuItem iaxes = m.addMenu("Inverted Axes", axes); ToolStripMenuItem haxes = m.addMenu("Half Axes", axes); ToolStripMenuItem ihaxes = m.addMenu("Inverted Half Axes", axes); for (int i = 1; i <= dev.joystick.Capabilities.ButtonCount; i++) { m.addOption("Button " + i.ToString(), buttons, new byte[] { 0, (byte)(i - 1), (byte)ind }); } /*for (int i = 0; i < kState.AllKeys.Count; i++) * { * m.addOption(kState.AllKeys[i].ToString(), keys, * new byte[] { 0, (byte)(i), (byte)ind }); * }*/ for (int i = 1; i <= dev.joystick.Capabilities.PovCount; i++) { m.addOption("D-Pad " + i.ToString() + " Up", dpads, new byte[] { 32, (byte)(i - 1), (byte)ind }); m.addOption("D-Pad " + i.ToString() + " Down", dpads, new byte[] { 33, (byte)(i - 1), (byte)ind }); m.addOption("D-Pad " + i.ToString() + " Left", dpads, new byte[] { 34, (byte)(i - 1), (byte)ind }); m.addOption("D-Pad " + i.ToString() + " Right", dpads, new byte[] { 35, (byte)(i - 1), (byte)ind }); } for (int i = 1; i <= dev.joystick.Capabilities.AxesCount; i++) { m.addOption("Axis " + i.ToString(), axes, new byte[] { 16, (byte)(i - 1), (byte)ind }); m.addOption("IAxis " + i.ToString(), iaxes, new byte[] { 17, (byte)(i - 1), (byte)ind }); m.addOption("HAxis" + i.ToString(), haxes, new byte[] { 18, (byte)(i - 1), (byte)ind }); m.addOption("IHAxis" + i.ToString(), ihaxes, new byte[] { 19, (byte)(i - 1), (byte)ind }); } m.SelectionChangeCommitted += new System.EventHandler(SelectionChanged); ind++; } }
public ControllerOptions(ControllerDevice device) { InitializeComponent(); dev = device; int ind = 0; foreach (MultiLevelComboBox m in this.Controls.OfType <MultiLevelComboBox>()) { //Tag structure: [Type, Number, Index] m.Items[0] = getBindingText(ind); //Change combobox text according to saved binding m.addOption("Disabled", tag: new byte[] { 255, 0, (byte)ind }); m.addOption("Detect", tag: new byte[] { 254, 0, (byte)ind }); ToolStripMenuItem axes = m.addMenu("Axes"); ToolStripMenuItem buttons = m.addMenu("Buttons"); ToolStripMenuItem dpads = m.addMenu("D-Pads"); ToolStripMenuItem iaxes = m.addMenu("Inverted Axes", axes); ToolStripMenuItem haxes = m.addMenu("Half Axes", axes); ToolStripMenuItem ihaxes = m.addMenu("Inverted Half Axes", axes); for (int i = 1; i <= dev.joystick.Capabilities.ButtonCount; i++) { m.addOption("Button " + i.ToString(), buttons, new byte[] { 0, (byte)(i - 1), (byte)ind }); } for (int i = 1; i <= dev.joystick.Capabilities.PovCount; i++) { m.addOption("D-Pad " + i.ToString() + " Up", dpads, new byte[] { 32, (byte)(i - 1), (byte)ind }); m.addOption("D-Pad " + i.ToString() + " Down", dpads, new byte[] { 33, (byte)(i - 1), (byte)ind }); m.addOption("D-Pad " + i.ToString() + " Left", dpads, new byte[] { 34, (byte)(i - 1), (byte)ind }); m.addOption("D-Pad " + i.ToString() + " Right", dpads, new byte[] { 35, (byte)(i - 1), (byte)ind }); } for (int i = 1; i <= dev.joystick.Capabilities.AxesCount; i++) { m.addOption("Axis " + i.ToString(), axes, new byte[] { 16, (byte)(i - 1), (byte)ind }); m.addOption("IAxis " + i.ToString(), iaxes, new byte[] { 17, (byte)(i - 1), (byte)ind }); m.addOption("HAxis" + i.ToString(), haxes, new byte[] { 18, (byte)(i - 1), (byte)ind }); m.addOption("IHAxis" + i.ToString(), ihaxes, new byte[] { 19, (byte)(i - 1), (byte)ind }); } m.SelectionChangeCommitted += new System.EventHandler(SelectionChanged); ind++; } trackDeadzoneLeft.Value = dev.mapping[43]; textDeadzoneLeft.Text = dev.mapping[43].ToString(); trackDeadzoneRight.Value = dev.mapping[45]; textDeadzoneRight.Text = dev.mapping[45].ToString(); }
public ControllerOptions(ControllerDevice device) { InitializeComponent(); dev = device; foreach (Button button in Controls.OfType <Button>()) { int ind = Int32.Parse(button.Tag.ToString()); button.Text = getBindingText(ind); button.MouseUp += Button_Click; } }
private void UpdateInfo(ControllerDevice dev) { if (dev != null) { controllerBox.Visible = true; controllerBox.Text = dev.name; } else { controllerBox.Visible = false; } }
private byte[] ifPressed(int[] axesStart) { dev.joystick.Poll(); JoystickState jState = dev.joystick.GetCurrentState(); bool[] buttons = jState.GetButtons(); int[] dPads = jState.GetPointOfViewControllers(); int[] axes = ControllerDevice.GetAxes(jState); // Buttons int i = 0; foreach (bool button in buttons) { if (button) { return new byte[] { 0, (byte)i } } ; i++; } // dPads i = 0; foreach (int dPad in dPads) { bool[] dp = getPov(dPad); for (int x = 0; x < 4; x++) { if (dp[x]) { return new byte[] { (byte)(32 + x), (byte)i } } ; } i++; } // Axes i = 0; foreach (int axis in axes) { if (axis != axesStart[i]) { return new byte[] { 16, (byte)i } } ; i++; } return(null); }
private void XOut_Closing(object sender, FormClosingEventArgs e) { if (controllerManager.IsActive) { controllerManager.Stop(); } ControllerDevice device = controllerManager.getController(); device.joystick.Unacquire(); device.joystick.Dispose(); device.keyboard.Dispose(); controllerManager.directInput.Dispose(); }
public ControllerDevice DetectControllers() { if (device != null && !directInput.IsDeviceAttached(device.joystick.Information.InstanceGuid)) { Console.WriteLine(device.joystick.Properties.InstanceName + " Removed"); device = null; worker.Abort(); worker = null; Unplug(controllerNrPluggedIn); } if (device != null) { return(device); } foreach (var deviceInstance in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { Joystick joystick = new Joystick(directInput, deviceInstance.InstanceGuid); if (joystick.Information.ProductGuid.ToString() == "028e045e-0000-0000-0000-504944564944") //If its an emulated controller skip it { continue; } if (joystick.Capabilities.ButtonCount < 1 && joystick.Capabilities.AxesCount < 1) //Skip if it doesn't have any button and axes { continue; } if (joystick.Information.InstanceName != "Logitech G13 Joystick") { continue; } Logger.Log("Found Logitech G13 Joystick"); if (device != null && device.joystick.Information.InstanceGuid == deviceInstance.InstanceGuid) //If the device is already initialized skip it { Console.WriteLine("Controller Already Acquired " + deviceInstance.InstanceName); break; } joystick.SetCooperativeLevel(handle, CooperativeLevel.Exclusive | CooperativeLevel.Background); joystick.Properties.BufferSize = 128; joystick.Acquire(); device = new ControllerDevice(joystick, keyb); Console.WriteLine("Created new instance and aquired joystick"); break; } return(device); }
public ControllerOptions(ControllerDevice device) { InitializeComponent(); dev = device; int ind = 0; foreach (MultiLevelComboBox m in this.Controls.OfType<MultiLevelComboBox>()) { //Tag structure: [Type, Number, Index] m.Items[0] = getBindingText(ind); //Change combobox text according to saved binding m.addOption("Disabled", tag: new byte[] { 255, 0, (byte)ind }); m.addOption("Detect", tag: new byte[] { 254, 0, (byte)ind }); ToolStripMenuItem axes = m.addMenu("Axes"); ToolStripMenuItem buttons = m.addMenu("Buttons"); ToolStripMenuItem dpads = m.addMenu("D-Pads"); ToolStripMenuItem iaxes = m.addMenu("Inverted Axes", axes); ToolStripMenuItem haxes = m.addMenu("Half Axes", axes); ToolStripMenuItem ihaxes = m.addMenu("Inverted Half Axes", axes); for (int i = 1; i <= dev.joystick.Capabilities.ButtonCount; i++) { m.addOption("Button " + i.ToString(), buttons, new byte[] { 0, (byte)(i - 1), (byte)ind }); } for (int i = 1; i <= dev.joystick.Capabilities.PovCount; i++) { m.addOption("D-Pad " + i.ToString() + " Up", dpads, new byte[] { 32, (byte)(i - 1), (byte)ind }); m.addOption("D-Pad " + i.ToString() + " Down", dpads, new byte[] { 33, (byte)(i - 1), (byte)ind }); m.addOption("D-Pad " + i.ToString() + " Left", dpads, new byte[] { 34, (byte)(i - 1), (byte)ind }); m.addOption("D-Pad " + i.ToString() + " Right", dpads, new byte[] { 35, (byte)(i - 1), (byte)ind }); } for (int i = 1; i <= dev.joystick.Capabilities.AxesCount; i++) { m.addOption("Axis " + i.ToString(), axes, new byte[] { 16, (byte)(i - 1), (byte)ind }); m.addOption("IAxis " + i.ToString(), iaxes, new byte[] { 17, (byte)(i - 1), (byte)ind }); m.addOption("HAxis" + i.ToString(), haxes, new byte[] { 18, (byte)(i - 1), (byte)ind }); m.addOption("IHAxis" + i.ToString(), ihaxes, new byte[] { 19, (byte)(i - 1), (byte)ind }); } m.SelectionChangeCommitted += new System.EventHandler(SelectionChanged); ind++; } }
public void Swap(int i, int p) { if (true)//devices[i - 1] != null && devices[p - 1] != null) { ControllerDevice s = devices[i - 1]; devices[i - 1] = devices[p - 1]; devices[p - 1] = s; devices[p - 1].changeNumber(p); if (devices[i - 1] != null) { devices[i - 1].changeNumber(i); } } }
private void UpdateInfo(ControllerDevice[] dev) { for (int i = 0; i < 4; i++) { if (dev[i] != null) { boxes[i].Visible = true; boxes[i].Text = (i + 1).ToString() + ": " + dev[i].name; checks[i].Visible = true; } else { boxes[i].Visible = false; checks[i].Visible = false; } } }
public List <ControllerDevice> detectControllers() { deviceCount = getDeviceCount()[0]; int allDeviceCount = getDeviceCount()[1]; Console.WriteLine("Detected {0} attached controllers out of {1} controllers in total.", deviceCount, allDeviceCount); for (int i = 0; i < devices.Count(); i++) //Remove disconnected controllers { if (devices[i] != null && !directInput.IsDeviceAttached(devices[i].joystick.Information.InstanceGuid)) { Console.WriteLine("{0} removed.", devices[i].joystick.Properties.InstanceName); devices[i] = null; if (i < workers.Count()) { workers[i].Abort(); workers[i] = null; Unplug(i + 1); } } } Resize(ref devices, deviceCount); int skip = 0; foreach (var deviceInstance in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { Joystick joystick = new Joystick(directInput, deviceInstance.InstanceGuid); if (joystick.Information.ProductGuid.ToString() == "028e045e-0000-0000-0000-504944564944") //If its an emulated controller skip it { skip++; continue; } if (joystick.Capabilities.ButtonCount < 1 && joystick.Capabilities.AxesCount < 1) //Skip if it doesn't have any button and axes { skip++; continue; } int spot = -1; for (int i = 0; i < deviceCount; i++) { if (devices[i] == null) { if (spot == -1) { spot = i; Console.WriteLine("Slot {0} is empty.", i); } } else if (devices[i] != null && devices[i].joystick.Information.InstanceGuid == deviceInstance.InstanceGuid) //If the device is already initialized skip it { Console.WriteLine("Device {0} in Slot {1} already aquired. ", deviceInstance.InstanceName, i); spot = -1; break; } } if (spot == -1) { continue; } devices[spot] = new ControllerDevice(joystick, spot + 1); Console.WriteLine("Device {0} assigned to slot {1}.", devices[spot].name, spot); joystick.Properties.BufferSize = 128; joystick.Acquire(); /*if (IsActive) // seems unnecessary * { * processingData[spot] = new ContData(); * Console.WriteLine("Plug " + spot); * Plugin(spot + 1); * int t = spot; * workers[spot] = new Thread(() => * { ProcessData(t); }); * workers[spot].Start(); * }*/ } Console.WriteLine("Skipped {0} device(s).", skip); return(devices); }
public ControllerDevice[] detectControllers() { for (int i = 0; i < 4; i++) //Remove disconnected controllers { if (devices[i] != null && !directInput.IsDeviceAttached(devices[i].joystick.Information.InstanceGuid)) { Console.WriteLine(devices[i].joystick.Properties.InstanceName + " Removed"); devices[i] = null; workers[i].Abort(); workers[i] = null; Unplug(i + 1); } } foreach (var deviceInstance in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { Joystick joystick = new Joystick(directInput, deviceInstance.InstanceGuid); if (joystick.Information.ProductGuid.ToString() == "028e045e-0000-0000-0000-504944564944") //If its an emulated controller skip it { continue; } if (joystick.Capabilities.ButtonCount < 1 && joystick.Capabilities.AxesCount < 1) //Skip if it doesn't have any button and axes { continue; } int spot = -1; for (int i = 0; i < 4; i++) { if (devices[i] == null) { if (spot == -1) { spot = i; Console.WriteLine("Open Spot " + i.ToString()); } } else if (devices[i] != null && devices[i].joystick.Information.InstanceGuid == deviceInstance.InstanceGuid) //If the device is already initialized skip it { Console.WriteLine("Controller Already Acquired " + i.ToString() + " " + deviceInstance.InstanceName); spot = -1; break; } } if (spot == -1) { continue; } if (isExclusive) { joystick.SetCooperativeLevel(handle, CooperativeLevel.Exclusive | CooperativeLevel.Background); } else { joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Background); } joystick.Properties.BufferSize = 128; joystick.Acquire(); devices[spot] = new ControllerDevice(joystick, spot + 1); if (IsActive) { processingData[spot] = new ContData(); Console.WriteLine("Plug " + spot); Plugin(spot + 1); int t = spot; workers[spot] = new Thread(() => { ProcessData(t); }); workers[spot].Start(); } } return(devices); }
public ControllerDevice[] detectControllers() { for (int i = 0; i < 4; i++) //Remove disconnected controllers { if (devices[i] != null && !directInput.IsDeviceAttached(devices[i].joystick.Information.InstanceGuid)) { Console.WriteLine(devices[i].joystick.Properties.InstanceName + " Removed"); devices[i] = null; workers[i].Abort(); workers[i] = null; Unplug(i + 1); } } foreach (var deviceInstance in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { Joystick joystick = new Joystick(directInput, deviceInstance.InstanceGuid); if (joystick.Information.ProductGuid.ToString() == "028e045e-0000-0000-0000-504944564944") //If its an emulated controller skip it continue; if (joystick.Capabilities.ButtonCount < 1 && joystick.Capabilities.AxesCount < 1) //Skip if it doesn't have any button and axes continue; int spot = -1; for (int i = 0; i < 4; i++) { if (devices[i] == null) { if (spot == -1) { spot = i; Console.WriteLine("Open Spot " + i.ToString()); } } else if (devices[i] != null && devices[i].joystick.Information.InstanceGuid == deviceInstance.InstanceGuid) //If the device is already initialized skip it { Console.WriteLine("Controller Already Acquired " + i.ToString() + " " + deviceInstance.InstanceName); spot = -1; break; } } if (spot == -1) continue; if (isExclusive) { joystick.SetCooperativeLevel(handle, CooperativeLevel.Exclusive | CooperativeLevel.Background); } else { joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Background); } joystick.Properties.BufferSize = 128; joystick.Acquire(); devices[spot] = new ControllerDevice(joystick, spot + 1); if (IsActive) { processingData[spot] = new ContData(); Console.WriteLine("Plug " + spot); Plugin(spot + 1); int t = spot; workers[spot] = new Thread(() => { ProcessData(t); }); workers[spot].Start(); } } return devices; }
public ControllerOptions(ControllerDevice device) { InitializeComponent(); dev = device; int ind = 0; foreach (MultiLevelComboBox m in this.Controls.OfType <MultiLevelComboBox>()) { //Tag structure: [Type, Number, Index] m.Items[0] = getBindingText(ind); //Change combobox text according to saved binding m.addOption("Disabled", tag: new byte[] { 255, 0, (byte)ind }); //m.addOption("Detect", // tag: new byte[] { 254, 0, (byte)ind }); ToolStripMenuItem axes = m.addMenu("Axes"); ToolStripMenuItem buttons = m.addMenu("Buttons"); ToolStripMenuItem dpads = m.addMenu("D-Pads"); ToolStripMenuItem iaxes = m.addMenu("Inverted Axes", axes); ToolStripMenuItem haxes = m.addMenu("Half Axes", axes); ToolStripMenuItem ihaxes = m.addMenu("Inverted Half Axes", axes); for (int i = 1; i <= dev.joystick.Capabilities.ButtonCount; i++) { m.addOption("Button " + i.ToString(), buttons, new byte[] { 0, (byte)(i - 1), (byte)ind }); } for (int i = 1; i <= dev.joystick.Capabilities.PovCount; i++) { m.addOption("D-Pad " + i.ToString() + " Up", dpads, new byte[] { 32, (byte)(i - 1), (byte)ind }); m.addOption("D-Pad " + i.ToString() + " Down", dpads, new byte[] { 33, (byte)(i - 1), (byte)ind }); m.addOption("D-Pad " + i.ToString() + " Left", dpads, new byte[] { 34, (byte)(i - 1), (byte)ind }); m.addOption("D-Pad " + i.ToString() + " Right", dpads, new byte[] { 35, (byte)(i - 1), (byte)ind }); } for (int i = 0; i <= dev.analogs.Length - 1; i++) { if (dev.analogs[i] != 0) { int ii = i + 1; m.addOption("Axis " + ii.ToString(), axes, new byte[] { 16, (byte)(i), (byte)ind }); m.addOption("IAxis " + ii.ToString(), iaxes, new byte[] { 17, (byte)(i), (byte)ind }); m.addOption("HAxis" + ii.ToString(), haxes, new byte[] { 18, (byte)(i), (byte)ind }); m.addOption("IHAxis" + ii.ToString(), ihaxes, new byte[] { 19, (byte)(i), (byte)ind }); } } m.SelectionChangeCommitted += new System.EventHandler(SelectionChanged); ind++; } this.numericCompensation.Tag = new byte[] { 253, (byte)(0), (byte)ind }; int outVal = 0; int.TryParse(getBindingText(ind), out outVal); this.numericCompensation.Value = outVal > 0 ? (outVal) : 0; }
public ControllerOptions(ControllerDevice device) { InitializeComponent(); dev = device; int outputIndex = 0; foreach (MultiLevelComboBox m in this.Controls.OfType <MultiLevelComboBox>()) { m.Items[0] = getBindingText(outputIndex); //Change combobox text according to saved binding m.addOption("Disabled", tag: new ControlMapping(ControlTypeEnum.Disabled) ); ToolStripMenuItem axes = m.addMenu("Axes"); ToolStripMenuItem buttons = m.addMenu("Buttons"); ToolStripMenuItem dpads = m.addMenu("D-Pads"); ToolStripMenuItem iaxes = m.addMenu("Inverted Axes", axes); ToolStripMenuItem haxes = m.addMenu("Half Axes", axes); ToolStripMenuItem ihaxes = m.addMenu("Inverted Half Axes", axes); for (int i = 1; i <= dev.joystick.Capabilities.ButtonCount; i++) { m.addOption(null, buttons, new ControlMapping(ControlTypeEnum.Button, ControlSubTypeEnum.Normal, (byte)(i - 1), (byte)outputIndex) ); } for (int i = 1; i <= dev.joystick.Capabilities.PovCount; i += 1) { m.addOption(null, dpads, new ControlMapping(ControlTypeEnum.Hat, ControlSubTypeEnum.HatUp, (byte)(i - 1), (byte)outputIndex) ); m.addOption(null, dpads, new ControlMapping(ControlTypeEnum.Hat, ControlSubTypeEnum.HatDown, (byte)(i - 1), (byte)outputIndex) ); m.addOption(null, dpads, new ControlMapping(ControlTypeEnum.Hat, ControlSubTypeEnum.HatLeft, (byte)(i - 1), (byte)outputIndex) ); m.addOption(null, dpads, new ControlMapping(ControlTypeEnum.Hat, ControlSubTypeEnum.HatRight, (byte)(i - 1), (byte)outputIndex) ); } for (int i = 0; i <= dev.analogs.Length - 1; i += 1) { if (dev.analogs[i] != 0) { int labelNum = i + 1; m.addOption(null, axes, new ControlMapping(ControlTypeEnum.Axis, ControlSubTypeEnum.Normal, (byte)(i), (byte)outputIndex) ); m.addOption(null, iaxes, new ControlMapping(ControlTypeEnum.Axis, ControlSubTypeEnum.Inverted, (byte)(i), (byte)outputIndex) ); m.addOption(null, haxes, new ControlMapping(ControlTypeEnum.Axis, ControlSubTypeEnum.Half, (byte)(i), (byte)outputIndex) ); m.addOption(null, ihaxes, new ControlMapping(ControlTypeEnum.Axis, ControlSubTypeEnum.InvertedHalf, (byte)(i), (byte)outputIndex) ); } } m.SelectionChangeCommitted += new System.EventHandler(SelectionChanged); outputIndex += 1; } }
public ControllerOptions(ControllerDevice device) { InitializeComponent(); this.Icon = Properties.Resources.AppIcon; dev = device; this.Text = $"{dev.name} ({dev.joystick.Information.InstanceGuid})"; this.dropButtonA.Tag = ControllerInputs.ButtonA; this.dropButtonB.Tag = ControllerInputs.ButtonB; this.dropButtonX.Tag = ControllerInputs.ButtonX; this.dropButtonY.Tag = ControllerInputs.ButtonY; this.dropButtonHome.Tag = ControllerInputs.ButtonHome; this.dropButtonStart.Tag = ControllerInputs.ButtonStart; this.dropButtonBack.Tag = ControllerInputs.ButtonBack; this.dropDigitalUp.Tag = ControllerInputs.DigitalUp; this.dropDigitalDown.Tag = ControllerInputs.DigitalDown; this.dropDigitalLeft.Tag = ControllerInputs.DigitalLeft; this.dropDigitalRight.Tag = ControllerInputs.DigitalRight; this.dropBumperLeft.Tag = ControllerInputs.BumperLeft; this.dropBumperRight.Tag = ControllerInputs.BumperRight; this.dropTriggerLeft.Tag = ControllerInputs.TriggerLeft; this.dropTriggerRight.Tag = ControllerInputs.TriggerRight; this.dropAnalogLeftButton.Tag = ControllerInputs.AnalogLeftButton; this.dropAnalogLeftYPositive.Tag = ControllerInputs.AnalogLeftYPositive; this.dropAnalogLeftYNegative.Tag = ControllerInputs.AnalogLeftYNegative; this.dropAnalogLeftXPositive.Tag = ControllerInputs.AnalogLeftXPositive; this.dropAnalogLeftXNegative.Tag = ControllerInputs.AnalogLeftXNegative; this.dropAnalogRightButton.Tag = ControllerInputs.AnalogRightButton; this.dropAnalogRightYPositive.Tag = ControllerInputs.AnalogRightYPositive; this.dropAnalogRightYNegative.Tag = ControllerInputs.AnalogRightYNegative; this.dropAnalogRightXPositive.Tag = ControllerInputs.AnalogRightXPositive; this.dropAnalogRightXNegative.Tag = ControllerInputs.AnalogRightXNegative; foreach (GroupBox g in this.Controls.OfType <GroupBox>()) { foreach (MultiLevelComboBox m in g.Controls.OfType <MultiLevelComboBox>()) { //Tag structure: [Type, Number, Index] byte index = (byte)(ControllerInputs)m.Tag; m.Items[0] = GetBindingText(index); //Change combobox text according to saved binding m.addOption("Disabled", tag: new byte[] { 255, 0, index }); m.addOption("Detect", tag: new byte[] { 254, 0, index }); ToolStripMenuItem axes = m.addMenu("Axes"); ToolStripMenuItem buttons = m.addMenu("Buttons"); ToolStripMenuItem dpads = m.addMenu("D-Pads"); ToolStripMenuItem incaxes = m.addMenu("+ Axes", axes); ToolStripMenuItem decaxes = m.addMenu("- Axes", axes); for (int i = 1; i <= dev.joystick.Capabilities.ButtonCount; i++) { m.addOption("Button " + i.ToString(), buttons, new byte[] { 0, (byte)(i - 1), index }); //example: type 0 (button), subtype i - 1 (number of button), ind index } //since the types start with powers of two, the four leftmost bytes contain the main type for (int i = 1; i <= dev.joystick.Capabilities.PovCount; i++) //the four rightmost types then contain the subtype which is (type - maintype) { m.addOption("D-Pad " + i.ToString() + " Up", dpads, new byte[] { 32, (byte)(i - 1), index }); m.addOption("D-Pad " + i.ToString() + " Down", dpads, new byte[] { 33, (byte)(i - 1), index }); m.addOption("D-Pad " + i.ToString() + " Left", dpads, new byte[] { 34, (byte)(i - 1), index }); m.addOption("D-Pad " + i.ToString() + " Right", dpads, new byte[] { 35, (byte)(i - 1), index }); } for (int i = 1; i <= dev.analogs.Length; i++) { if (dev.analogs[i - 1] != 0) { m.addOption("+ Axis " + i.ToString(), incaxes, new byte[] { 16, (byte)(i - 1), index }); m.addOption("- Axis " + i.ToString(), decaxes, new byte[] { 17, (byte)(i - 1), index }); } } for (int i = 1; i <= dev.sliders.Length; i++) //placeholder { if (dev.sliders[i - 1] != 0) { m.addOption("+ Slider " + i.ToString(), incaxes, new byte[] { 48, (byte)(i - 1), index }); m.addOption("- Slider " + i.ToString(), decaxes, new byte[] { 49, (byte)(i - 1), index }); } } m.SelectionChangeCommitted += (sender, e) => ComboBox_SelectionChangeCommitted(sender, e, m); m.KeyPress += (sender, e) => ComboBox_KeyPress(sender, e); m.MouseUp += (sender, e) => ComboBox_MouseUp(sender, e); m.MouseEnter += (sender, e) => ComboBox_MouseEnter(sender, e); m.MouseLeave += (sender, e) => ComboBox_MouseLeave(sender, e); } } }