public gamepad_aq() { var directInput = new DirectInput(); var joystickGuid = Guid.Empty; // tenta encontrar um gamepad ou joystick foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } if (joystickGuid == Guid.Empty) { foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } } if (joystickGuid == Guid.Empty) { throw new Exception(string.Format("Nao encontrou Gamepad, Pressione qqr tecla para sair.")); } // cria o joystick joystickState = new JoystickState(); Rjoystick = new Joystick(directInput, joystickGuid); Rjoystick.Properties.BufferSize = 128; Rjoystick.Acquire(); }
static void MainForJoystick() { // Initialize DirectInput var directInput = new DirectInput(); // Find a Joystick Guid var joystickGuid = Guid.Empty; foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } // If Gamepad not found, look for a Joystick if (joystickGuid == Guid.Empty) { foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } } // If Joystick not found, throws an error if (joystickGuid == Guid.Empty) { Console.WriteLine("No joystick/Gamepad found."); Console.ReadKey(); Environment.Exit(1); } // Instantiate the joystick var joystick = new Joystick(directInput, joystickGuid); Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid); // Query all suported ForceFeedback effects var allEffects = joystick.GetEffects(); foreach (var effectInfo in allEffects) { Console.WriteLine("Effect available {0}", effectInfo.Name); } // Set BufferSize in order to use buffered data. joystick.Properties.BufferSize = 128; // Acquire the joystick joystick.Acquire(); // Poll events from joystick while (true) { joystick.Poll(); var datas = joystick.GetBufferedData(); foreach (var state in datas) { Console.WriteLine(state); } } }
/** * Obtiene los dispositivos conectacos */ public void SearchConnectedDevices() { IList <DeviceInstance> devs = Di.GetDevices(); foreach (DeviceInstance di in devs) { if (di.Type.ToString() == "Driving" || di.Type.ToString() == "Gamepad" || di.Type.ToString() == "Joystick" || di.Type.ToString() == "Flight" || di.Type.ToString() == "Keyboard") { if (!isInDevices(di)) { Device device = new Device(); device.Instace = di; if (di.Type.ToString() == "Keyboard") { device.Keyboard = new Keyboard(Di); device.Keyboard.Acquire(); device.GetPressedKeys(); } else { device.Joystick = new Joystick(Di, di.InstanceGuid); device.Joystick.Acquire(); } //Console.WriteLine("Se elimina el dispositivo " + di.ProductName); Devices.Add(device); } } } RemoveDisconnectedDevices(); }
void InitializeController() { var directInput = new DirectInput(); // Find a Gamepad var joystickGuid = directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices) .Select(d => d.InstanceGuid) .FirstOrDefault(); // Find a Joystick if (joystickGuid == Guid.Empty) { joystickGuid = directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices) .Select(d => d.InstanceGuid) .FirstOrDefault(); } // Find a FirstPerson controller if (joystickGuid == Guid.Empty) { joystickGuid = directInput.GetDevices(DeviceType.FirstPerson, DeviceEnumerationFlags.AllDevices) .Select(d => d.InstanceGuid) .FirstOrDefault(); } // If Joystick not found, throws an error if (joystickGuid != Guid.Empty) { // Instantiate the joystick this.joystick = new Joystick(directInput, joystickGuid); // Acquire the joystick joystick.Acquire(); } }
private void controllerList() { foreach (var device in dInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AttachedOnly)) { controllers.Add(device); listBoxDevices.Items.Add(device.ProductName); } foreach (var device in dInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AttachedOnly)) { controllers.Add(device); listBoxDevices.Items.Add(device.ProductName); } foreach (var device in dInput.GetDevices(DeviceType.Driving, DeviceEnumerationFlags.AttachedOnly)) { controllers.Add(device); listBoxDevices.Items.Add(device.ProductName); } foreach (var device in dInput.GetDevices(DeviceType.Flight, DeviceEnumerationFlags.AttachedOnly)) { controllers.Add(device); listBoxDevices.Items.Add(device.ProductName); } foreach (var device in dInput.GetDevices(DeviceType.FirstPerson, DeviceEnumerationFlags.AttachedOnly)) { controllers.Add(device); listBoxDevices.Items.Add(device.ProductName); } }
private void joystickInit() { foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } // If Gamepad not found, look for a Joystick if (joystickGuid == Guid.Empty) { foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } } // If Joystick not found, throws an error if (joystickGuid == Guid.Empty) { MessageBox.Show("No joystick/gamepad found", "Joystick Error", MessageBoxButtons.OK); } else { try { joystick = new Joystick(directInput, joystickGuid); Console.WriteLine("Found Joystick with GUID: {0}", joystickGuid); Console.WriteLine(joystick.Capabilities.ButtonCount.ToString() + " buttons available."); joystick.Acquire(); joystickExists = true; } catch (Exception e1) { MessageBox.Show(e1.Message, "Joystick Error", MessageBoxButtons.OK); } } }
/// <summary> /// Detects the devices. /// </summary> public IList <JoystickDescriptor> DetectDevices() { return(directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices) .Concat(directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) .Select(d => new JoystickDescriptor(d.InstanceGuid, d.InstanceName)) .ToList()); }
public void CaptureJoysticks() { // Initialize DirectInput var directInput = new DirectInput(); // Find all joysticks connected to the system IList <DeviceInstance> connectedJoysticks = new List <DeviceInstance>(); // - look for gamepads foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { connectedJoysticks.Add(deviceInstance); } // - look for joysticks foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { connectedJoysticks.Add(deviceInstance); } // Use the two first joysticks found if (connectedJoysticks.Count >= 1) { joystick1 = new Joystick(directInput, connectedJoysticks[0].InstanceGuid); Joystick1DeviceName = connectedJoysticks[0].InstanceName; joystick1.Acquire(); } if (connectedJoysticks.Count >= 2) { joystick2 = new Joystick(directInput, connectedJoysticks[1].InstanceGuid); Joystick2DeviceName = connectedJoysticks[1].InstanceName; joystick2.Acquire(); } }
private void button1_Click(object sender, EventArgs e) { deviceInstanceList.Items.Clear(); foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { devicesList.Add(deviceInstance); deviceInstanceList.Items.Add(deviceInstance.InstanceName); } foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { devicesList.Add(deviceInstance); deviceInstanceList.Items.Add(deviceInstance.InstanceName); } if (deviceInstanceList.Items.Count > 0) { button2.Enabled = true; } else { button2.Enabled = false; button3.Enabled = false; } }
public void Connect() { directInput = new DirectInput(); joystickGuid = Guid.Empty; foreach (DeviceInstance deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } if (joystickGuid == Guid.Empty) { foreach (DeviceInstance deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } } if (joystickGuid == Guid.Empty) { connected = false; return; } connected = true; joystick = new Joystick(directInput, joystickGuid); System.Collections.Generic.IList <EffectInfo> allEffects = joystick.GetEffects(); foreach (EffectInfo effectInfo in allEffects) { ; } joystick.Properties.BufferSize = 128; joystick.Acquire(); joystick.Poll(); }
private Joystick initJoystick() { // Initialize DirectInput var directInput = new DirectInput(); // Find a Joystick Guid var joystickGuid = Guid.Empty; foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, // Ищем среди всех девайсов джойстик DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } // If Joystick not found, look for a Gamepad if (joystickGuid == Guid.Empty) { foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } } // If Gamepad not found, throws an error if (joystickGuid == Guid.Empty) { return(null); } joystick = new Joystick(directInput, joystickGuid); return(joystick); }
public JoystickController(JoyEventFireMode fmode) { var directInput = new DirectInput(); var joystickGuid = Guid.Empty; foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } if (joystickGuid == Guid.Empty) { foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } } if (joystickGuid == Guid.Empty) { Console.WriteLine("No joystick/Gamepad found."); //Console.ReadKey(); //Environment.Exit(1); return; } joystick = new Joystick(directInput, joystickGuid); Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid); var allEffects = joystick.GetEffects(); foreach (var effectInfo in allEffects) { Console.WriteLine("Effect available {0}", effectInfo.Name); } joystick.Properties.BufferSize = 128; firemode = fmode; }
public void poll() { while (true) { if (stick != null) { if (input.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly).ToArray().Length > 0) { stickHandle(stick); } else { Invoke(new MethodInvoker(delegate { debug.Text += "Controller Disconnected"; })); stick = null; sticks = GetSticks(); } } else { try { Invoke(new MethodInvoker(delegate { debug.Text += "Controller Disconnected"; })); sticks = GetSticks(); } catch (Exception e) { } } Thread.Sleep(13); } }
private void InitializeDevices() { DirectInput di = new DirectInput(); Guid joystickGuid = Guid.Empty; foreach (var dev in di.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AttachedOnly)) { if (dev.InstanceGuid != Guid.Empty) { joystickGuid = dev.InstanceGuid; break; } } if (joystickGuid == Guid.Empty) { foreach (var dev in di.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AttachedOnly)) { if (dev.InstanceGuid != Guid.Empty) { joystickGuid = dev.InstanceGuid; break; } } } joystick = new Joystick(di, joystickGuid); }
void Start() { var di = new DirectInput(); foreach (var device in di.GetDevices(SharpDX.DirectInput.DeviceType.Gamepad, DeviceEnumerationFlags.AttachedOnly)) { GameObject deviceObj = Instantiate(deviceObject); deviceObj.transform.SetParent(content.transform); deviceObj.GetComponentInChildren <TextMeshProUGUI>().text = device.ProductName; deviceObj.GetComponentInChildren <Controls_DevicePress>().joystick = new Joystick(di, device.InstanceGuid); deviceObj.GetComponentInChildren <Controls_DevicePress>().productName = device.ProductName; deviceObj.GetComponentInChildren <Controls_DevicePress>().currentDeviceText = currentDeviceText; deviceObj.GetComponentInChildren <Controls_DevicePress>().button1 = button1; deviceObj.GetComponentInChildren <Controls_DevicePress>().button2 = button2; deviceObj.GetComponentInChildren <Controls_DevicePress>().joystick.Acquire(); deviceObj.transform.localScale = new Vector3(1, 1, 1); } foreach (var device in di.GetDevices(SharpDX.DirectInput.DeviceType.Joystick, DeviceEnumerationFlags.AttachedOnly)) { GameObject deviceObj = Instantiate(deviceObject); deviceObj.transform.SetParent(content.transform); deviceObj.GetComponentInChildren <TextMeshProUGUI>().text = device.ProductName; deviceObj.GetComponentInChildren <Controls_DevicePress>().joystick = new Joystick(di, device.InstanceGuid); deviceObj.GetComponentInChildren <Controls_DevicePress>().productName = device.ProductName; deviceObj.GetComponentInChildren <Controls_DevicePress>().currentDeviceText = currentDeviceText; deviceObj.GetComponentInChildren <Controls_DevicePress>().button1 = button1; deviceObj.GetComponentInChildren <Controls_DevicePress>().button2 = button2; deviceObj.GetComponentInChildren <Controls_DevicePress>().joystick.Acquire(); deviceObj.transform.localScale = new Vector3(1, 1, 1); } }
public void InitializeController(Guid initGuid) { controllerGuid = Guid.Empty; var deviceInst = input.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly); if (deviceInst.Count == 0) { deviceInst = input.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AttachedOnly); } if (deviceInst.Count > 0) { foreach (var device in deviceInst) { if (device.InstanceGuid == initGuid) { controllerGuid = initGuid; } } if (controllerGuid == Guid.Empty) { controllerGuid = deviceInst[0].InstanceGuid; } controller = new Joystick(input, controllerGuid); controller.Acquire(); defaultControllerState = controller.GetCurrentState(); } }
public static void init() { // Initialize DirectInput var directInput = new DirectInput(); // Find a Joystick Guid var joystickGuid = Guid.Empty; foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } // If Gamepad not found, look for a Joystick if (joystickGuid == Guid.Empty) { foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } } // If Joystick not found, return. if (joystickGuid == Guid.Empty) { Console.WriteLine("No joystick/Gamepad found."); return; } // Instantiate the joystick var joystick = new Joystick(directInput, joystickGuid); Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid); // Query all suported ForceFeedback effects var allEffects = joystick.GetEffects(); foreach (var effectInfo in allEffects) { Console.WriteLine("Effect available {0}", effectInfo.Name); } // Set BufferSize in order to use buffered data. joystick.Properties.BufferSize = 128; // Acquire the joystick joystick.Acquire(); Task.Factory.StartNew(async() => { while (true) { joystick.Poll(); joystick.GetCurrentState(ref joyState); onUpdate(joyState); Thread.Sleep(10); } }); }
/// <summary> /// Listens given joystick. /// </summary> public void Listen() { _joystickCollection.Clear(); var devices = new List <DeviceInstance>(); _stopListening = false; if (File.Exists("DirectInputOverride.txt")) { var devs = _directInput.GetDevices(); var guids = FetchValidGuids(); foreach (var guid in guids) { var result = devs.FirstOrDefault(x => x.InstanceGuid == guid); if (result != null) { devices.Add(result); } } } else { devices.AddRange(_directInput.GetDevices().Where(x => x.Type != DeviceType.Mouse && x.UsagePage != UsagePage.VendorDefinedBegin && x.Usage != UsageId.AlphanumericBitmapSizeX && x.Usage != UsageId.AlphanumericAlphanumericDisplay && x.UsagePage != unchecked ((UsagePage)0xffffff43) && x.UsagePage != UsagePage.Vr).ToList()); } foreach (var t in devices) { var joystick = new Joystick(new DirectInput(), t.InstanceGuid); joystick.Properties.BufferSize = 512; joystick.Acquire(); new Thread(() => SpawnDirectInputListener(joystick, t)).Start(); } }
public Boolean Connect() { // Joystick finder code adapted from SharpDX Samples - (c) Alexandre Mutel 2012 Guid joystickGuid = Guid.Empty; foreach (DeviceInstance deviceInstance in di.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } if (joystickGuid == Guid.Empty) { foreach (DeviceInstance deviceInstance in di.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } } if (joystickGuid == Guid.Empty) { MessageBox.Show("No joystick found."); return(false); } joystick = new Joystick(di, joystickGuid); joystick.Properties.BufferSize = 128; joystick.Acquire(); return(true); }
public ControllerHotkey(int index) { var directInput = new DirectInput(); var joystickGuids = new List <Guid>(); foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { joystickGuids.Add(deviceInstance.InstanceGuid); } foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { joystickGuids.Add(deviceInstance.InstanceGuid); } if (joystickGuids.Count < index) { throw new Exception("Joystick not found"); } var joystick = new Joystick(directInput, joystickGuids[index]); joystick.Properties.BufferSize = 128; joystick.Acquire(); this.joystick = joystick; }
public static bool IsInstanceConnected(Guid instanceGuid) { using (DirectInput directInput = new DirectInput()) { return(directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices).Any(d => d.InstanceGuid == instanceGuid) || directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices).Any(d => d.InstanceGuid == instanceGuid)); } }
public static int DeviceCount() { var directInput = new DirectInput(); int joystickCount = directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices).Count; int gamepadCount = directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices).Count; return(joystickCount + gamepadCount); }
public void SetJoystick() { foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } // If Gamepad not found, look for a Joystick if (joystickGuid == Guid.Empty) { foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } } if (joystickGuid == Guid.Empty) { foreach (var deviceInstance in directInput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } } // If Joystick not found, throws an error if (joystickGuid == Guid.Empty) { Console.WriteLine("No joystick/Gamepad found."); Console.ReadKey(); Environment.Exit(1); } // Instantiate the joystick joystick = new Joystick(directInput, joystickGuid); Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid); // Query all suported ForceFeedback effects var allEffects = joystick.GetEffects(); foreach (var effectInfo in allEffects) { Console.WriteLine("Effect available {0}", effectInfo.Name); } // Set BufferSize in order to use buffered data. joystick.Properties.BufferSize = 128; // Acquire the joystick joystick.Acquire(); joystickThread.Start(); }
static void Main(string[] args) { // Initialize DirectInput var directInput = new DirectInput(); var devices = SearchDevice(directInput); var joystickState = new JoystickState(); // Find a Joystick Guid var joystickGuid = Guid.Empty; var joystickName = ""; foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; joystickName = deviceInstance.ProductName; } // If Gamepad not found, look for a Joystick if (joystickGuid == Guid.Empty) { foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; joystickName = deviceInstance.InstanceName; Console.WriteLine(deviceInstance.ProductGuid); } } // If Joystick not found, throws an error if (joystickGuid == Guid.Empty) { Console.WriteLine("No joystick/Gamepad found."); Console.ReadKey(); Environment.Exit(1); } // Instantiate the joystick var joystick = new Joystick(directInput, joystickGuid); joystick.Properties.BufferSize = 128; joystick.Acquire(); while (true) { joystick.Poll(); var datas = joystick.GetBufferedData(); foreach (var state in datas) { Console.WriteLine(state); } } }
public static List <DeviceInstance> GetJoysticks() { List <DeviceInstance> instances = new List <DeviceInstance>(); var gamepads = directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices); instances.AddRange(gamepads); var joysticks = directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices); instances.AddRange(joysticks); return(instances); }
public DirectInputBroker() { foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { this.joystickGuids.Add(deviceInstance.InstanceGuid); } foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { this.joystickGuids.Add(deviceInstance.InstanceGuid); } }
private void SearchForJoysticks() { foreach (var di in m_di.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { CheckOneDevice(di); } foreach (var di in m_di.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { CheckOneDevice(di); } }
/// <summary> /// Checks if joystick or gamepad GUID is found. /// </summary> /// <param name="joystickGuid">Joystick GUID;:</param> /// <returns></returns> private bool DoesJoystickExist(Guid joystickGuid) { if (File.Exists("DirectInputOverride.txt")) { // Don't care about filters when using override! return(_diInput.GetDevices().Any(x => x.InstanceGuid == joystickGuid)); } return(_diInput.GetDevices() .Any( x => x.InstanceGuid == joystickGuid && x.Type != DeviceType.Device)); }
public void CaptureJoyStick() { // Initialize DirectInput var directInput = new DirectInput(); // Find a Joystick Guid var joystickGuid = Guid.Empty; foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } // If Gamepad not found, look for a Joystick if (joystickGuid == Guid.Empty) { foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } } // If Joystick not found, throws an error if (joystickGuid == Guid.Empty) { Console.WriteLine("No joystick/Gamepad found."); this.JoyStickError(this, new Exception("No joystick/Gamepad found.")); return; } this.joystick = new Joystick(directInput, joystickGuid); JoystickState stato = new JoystickState(); // specifico se relativo o assoluto joystick.Properties.AxisMode = DeviceAxisMode.Absolute; // effettuo un collegamento con il joystick joystick.Acquire(); // qui faccio una acquisizione dello stato che memorizzo joystick.Poll(); // effettuo una lettura dello stato joystick.GetCurrentState(ref stato); DispatcherTimer aTimer = new DispatcherTimer(); aTimer.Tick += aTimer_Tick; aTimer.Interval = new TimeSpan(10); aTimer.IsEnabled = true; }
private void InitiallizeGamePad() { // Initialize DirectInput var directInput = new DirectInput(); // Find a Joystick Guid var joystickGuid = Guid.Empty; foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } // If Gamepad not found, look for a Joystick if (joystickGuid == Guid.Empty) { foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } } // If Joystick not found, throws an error if (joystickGuid == Guid.Empty) { MessageBox.Show("HopScotch Matte nicht gefunden! "); } else { // Instantiate the joystick joystick = new Joystick(directInput, joystickGuid); Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid); // Query all suported ForceFeedback effects var allEffects = joystick.GetEffects(); foreach (var effectInfo in allEffects) { Console.WriteLine("Effect available {0}", effectInfo.Name); } // Set BufferSize in order to use buffered data. joystick.Properties.BufferSize = 128; // Acquire the joystick joystick.Acquire(); tHopScotch.Start(); } }
/// /// Construct, attach the joystick /// public SimpleJoystick() { DirectInput dinput = new DirectInput(); // Search for device foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { // Create device try { Joystick = new Joystick(dinput, device.InstanceGuid); break; } catch (DirectInputException) { } } if (Joystick == null) throw new Exception("No joystick found"); foreach (DeviceObjectInstance deviceObject in Joystick.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) Joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-100, 100); } // Acquire sdevice Joystick.Acquire(); }
public GamepadReader() { Buttons = _buttons; Analogs = _analogs; _dinput = new DirectInput(); var devices = _dinput.GetDevices (DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly); if (devices.Count < 1) { throw new IOException ("GamepadReader could not find a connected gamepad."); } _joystick = new Joystick (_dinput, devices[0].InstanceGuid); foreach (var obj in _joystick.GetObjects()) { if ((obj.ObjectType & ObjectDeviceType.Axis) != 0) { _joystick.GetObjectPropertiesById ((int)obj.ObjectType).SetRange (-RANGE, RANGE); } } if (_joystick.Acquire().IsFailure) { throw new IOException ("Connected gamepad could not be acquired."); } _timer = new DispatcherTimer (); _timer.Interval = TimeSpan.FromMilliseconds (TIMER_MS); _timer.Tick += tick; _timer.Start (); }
public void ConnectJoysticks() { // make sure that DirectInput has been initialized DirectInput dinput = new DirectInput(); // search for devices foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { // create the device try { JoysticksConnected.AddLast(new Joystick(dinput, device.InstanceGuid)); } catch (DirectInputException) { Utils.Log("Warning: Joystick did not init (DirectInputException)"); } } Utils.Log("joysticks connected: " + JoysticksConnected.Count); //Set the axises of all of the analog sticks, then claim the joystick foreach (Joystick joystick in JoysticksConnected) { foreach (DeviceObjectInstance deviceObject in joystick.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-AxisRange, AxisRange); } joystick.Acquire(); } }
private Joystick GetJoystick() { var directInput = new DirectInput(); var form = new Form(); foreach (var device in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { var controller = new Joystick(directInput, device.InstanceGuid); controller.SetCooperativeLevel(form.Handle, CooperativeLevel.Exclusive | CooperativeLevel.Background); var retries = 0; while (controller.Acquire().IsFailure) { retries++; if (retries > 500) throw new Exception("Couldnt acquire SlimDX stick"); } if (controller.Information.InstanceName.Contains("PPJoy")) { foreach (DeviceObjectInstance deviceObject in controller.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) controller.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000); } return controller; } } return null; }
public static Joystick[] GetSticks(DirectInput input) { List<SlimDX.DirectInput.Joystick> sticks = new List<SlimDX.DirectInput.Joystick>(); // Creates the list of joysticks connected to the computer via USB. foreach (DeviceInstance device in input.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { // Creates a joystick for each game device in USB Ports try { Joystick stick = new SlimDX.DirectInput.Joystick(input, device.InstanceGuid); stick.Acquire(); // Gets the joysticks properties and sets the range for them. foreach (DeviceObjectInstance deviceObject in stick.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) stick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-100, 100); } // Adds how ever many joysticks are connected to the computer into the sticks list. sticks.Add(stick); } catch (DirectInputException) { } } return sticks.ToArray(); }
public Joystick() { var di = new DirectInput(); // Get the first device try { var device = di.GetDevices()[0]; joystick = new SlimDX.DirectInput.Joystick(di, device.InstanceGuid); } catch (IndexOutOfRangeException e) { Console.WriteLine("No devices: {0}", e.Message); Environment.Exit(1); } catch (DirectInputException e) { Console.WriteLine(e.Message); Environment.Exit(1); } foreach (DeviceObjectInstance deviceObject in joystick.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000); } joystick.Acquire(); }
public Joystick() { var di = new DirectInput(); foreach (var device in di.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { try { joystick = new SlimDX.DirectInput.Joystick(di, device.InstanceGuid); Connected = true; joystick.RunControlPanel(); break; } catch { } } /*foreach (DeviceObjectInstance deviceObject in joystick.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) { joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000); } }*/ if (Connected) joystick.Acquire(); }
public MainController() { var directInput = new DirectInput(); LogicState = new LogicState(); foreach (var deviceInstance in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { try { gamepad = new Joystick(directInput, deviceInstance.InstanceGuid); gamepad.SetCooperativeLevel(Parent, CooperativeLevel.Exclusive | CooperativeLevel.Foreground); break; } catch (DirectInputException) { } } if (gamepad == null) return; foreach (var deviceObject in gamepad.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) gamepad.GetObjectPropertiesById((int) deviceObject.ObjectType).SetRange(-1000, 1000); } gamepad.Acquire(); }
public static Joystick[] AllJoysticks() { using(DirectInput directInput = new DirectInput()) { IList<DeviceInstance> devices = directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly); return devices.Select(x => new Joystick(x.InstanceGuid)).ToArray(); } }
public static int NumJoysticks() { DirectInput direct = new DirectInput(); int count = direct.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly).Count; direct.Dispose(); return count; }
private Joystick[] obtenerDispositivos() { var sticks = new List<SlimDX.DirectInput.Joystick>(); DirectInput dinput = new DirectInput(); foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { // crear los dispositivos try { var stick = new SlimDX.DirectInput.Joystick(dinput, device.InstanceGuid); stick.Acquire(); foreach (DeviceObjectInstance deviceObject in stick.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) stick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000); } sticks.Add(stick); } catch (DirectInputException) { } } return sticks.ToArray(); }
/// <summary> /// Získání prvního gamepadu, ketrý je připojený k počítači /// </summary> /// <returns>zařízení</returns> /// <exception>Pokud se nepodařilo najít žádné funkční zařízení</exception> private SlimDX.DirectInput.Joystick getGamepad() { dinput = new DirectInput(); SlimDX.DirectInput.Joystick gamepad; string errorMessage = "Nebylo nalezeno žádné vnější ovládací zařízení."; foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { try { gamepad = new SlimDX.DirectInput.Joystick(dinput, device.InstanceGuid); gamepad.Acquire(); foreach (DeviceObjectInstance deviceObject in gamepad.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) { gamepad.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-100, 100); } } return gamepad; } catch (DirectInputException e) { dinput.Dispose(); errorMessage = e.Message; } } dinput.Dispose(); throw new DirectInputException(errorMessage); }
public static IList<ControllerDevice> Available() { var dinput = new DirectInput(); return dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly) .Select(di => new ControllerDevice {Guid = di.InstanceGuid, Name = di.InstanceName}) .ToList(); }
public ControllerU() { // Initialize DirectInput this.directInput = new DirectInput(); // Find a Joystick Guid this.joystickGuid = Guid.Empty; foreach (var deviceInstance in directInput.GetDevices(SlimDX.DirectInput.DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) this.joystickGuid = deviceInstance.InstanceGuid; // If Gamepad not found, look for a Joystick if (this.joystickGuid == Guid.Empty) foreach (var deviceInstance in directInput.GetDevices(SlimDX.DirectInput.DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) this.joystickGuid = deviceInstance.InstanceGuid; // If Joystick not found, throws an error if (this.joystickGuid == Guid.Empty) { Console.WriteLine("No joystick/Gamepad found."); Console.ReadKey(); Environment.Exit(1); } // Instantiate the joystick this.joystick = new Joystick(directInput, joystickGuid); Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid); // Query all suported ForceFeedback effects var allEffects = this.joystick.GetEffects(); foreach (var effectInfo in allEffects) Console.WriteLine("Effect available {0}", effectInfo.Name); // Set BufferSize in order to use buffered data. this.joystick.Properties.BufferSize = 128; // Acquire the joystick this.joystick.Acquire(); }
/// <summary> /// All SlimDX - compatible input devices are initialised and added to a List of the type <see cref="IInputDeviceImp"./> /// </summary> /// <returns>A list containing all SlimDX - compatible input devices.</returns> public List<IInputDeviceImp> DeviceImps() { var directInput = new DirectInput(); var devices = directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly); foreach (DeviceInstance deviceInstance in devices) { Devices.Add(deviceInstance); } var retList = new List<IInputDeviceImp>(); foreach (DeviceInstance instance in Devices) { retList.Add(new InputDeviceImp(instance)); } return retList; }
public override object CreateGlobal() { var directInput = new DirectInput(); var handle = Process.GetCurrentProcess().MainWindowHandle; devices = new List<Device>(); foreach (var device in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { var controller = new Joystick(directInput, device.InstanceGuid); controller.SetCooperativeLevel(handle, CooperativeLevel.Exclusive | CooperativeLevel.Background); controller.Acquire(); devices.Add(new Device(controller)); } return devices.Select(d => new JoystickGlobal(d)).ToArray(); }
public override void Initialize() { buttonDown = -1; joystickIsReady = false; // Make sure that DirectInput has been initialized DirectInput dinput = new DirectInput(); state = new JoystickState(); // search for devices foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { // create the device try { joystick = new Joystick(dinput, device.InstanceGuid); joystick.SetCooperativeLevel(Core.Settings.RenderForm.Handle, CooperativeLevel.Exclusive | CooperativeLevel.Foreground); break; } catch (DirectInputException) { } } if (joystick != null) { foreach (DeviceObjectInstance deviceObject in joystick.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000); } } else { return; } // acquire the device joystick.Acquire(); timer = new Timer(); timer.Interval = 1000 / 10; timer.Tick += new EventHandler(timer_Tick); timer.Start(); }
void CreateDevice() { // make sure that DirectInput has been initialized DirectInput dinput = new DirectInput(); // search for devices foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { // create the device try { joystick = new Joystick(dinput, device.InstanceGuid); joystick.SetCooperativeLevel(this, CooperativeLevel.Exclusive | CooperativeLevel.Foreground); break; } catch (DirectInputException) { } } if (joystick == null) { MessageBox.Show("There are no joysticks attached to the system."); return; } foreach (DeviceObjectInstance deviceObject in joystick.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) { joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(0, 255); } UpdateControl(deviceObject); } // acquire the device joystick.Acquire(); // set the timer to go off 12 times a second to read input // NOTE: Normally applications would read this much faster. // This rate is for demonstration purposes only. timer.Interval = 5; // 1000 / 1000; timer.Start(); }
public InputManager(IntPtr handle) { _devices = new List<InputDevice>(); var di = new DirectInput(); foreach (var device in di.GetDevices(DeviceClass.All, DeviceEnumerationFlags.AttachedOnly)) { if ((device.Type & DeviceType.Keyboard) == DeviceType.Keyboard) { var keyboard = new Keyboard(di); keyboard.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground); _devices.Add(new InputDevice(keyboard)); } else if ((device.Type & DeviceType.Joystick) == DeviceType.Joystick) { var joystick = new Joystick(di, device.InstanceGuid); joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground); _devices.Add(new InputDevice(joystick)); } } }
private void RefreshDevices() { comboBox_device.Items.Clear(); DirectInput di = new DirectInput(); deviceGuides = new List<string>(); deviceTypes = new List<SlimDX.DirectInput.DeviceType>(); foreach (DeviceInstance ins in di.GetDevices()) { if (ins.Type == SlimDX.DirectInput.DeviceType.Joystick || ins.Type == SlimDX.DirectInput.DeviceType.Keyboard) { comboBox_device.Items.Add(ins.InstanceName); deviceGuides.Add(ins.InstanceGuid.ToString()); deviceTypes.Add(ins.Type); } } // Add the X inputs devices if available if (c1.IsConnected) { comboBox_device.Items.Add("X Controller Player One"); deviceGuides.Add("x-controller-1"); deviceTypes.Add(SlimDX.DirectInput.DeviceType.Other); } if (c2.IsConnected) { comboBox_device.Items.Add("X Controller Player Two"); deviceGuides.Add("x-controller-2"); deviceTypes.Add(SlimDX.DirectInput.DeviceType.Other); } if (c3.IsConnected) { comboBox_device.Items.Add("X Controller Player Three"); deviceGuides.Add("x-controller-3"); deviceTypes.Add(SlimDX.DirectInput.DeviceType.Other); } if (c4.IsConnected) { comboBox_device.Items.Add("X Controller Player Four"); deviceGuides.Add("x-controller-1"); deviceTypes.Add(SlimDX.DirectInput.DeviceType.Other); } }
void CreateDevice() { DirectInput dinput = new DirectInput(); int joy = 0; foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { try { joysticks.Add(new Joystick(dinput, device.InstanceGuid)); CBJoystick.Items.Add(joysticks[joy].Information.ProductName); joy++; } catch (DirectInputException) { } } if (joysticks.Count == 0) { MessageBox.Show("There are no joysticks attached to the system! Plug a joystick in and restart the program if you want to use a joystick."); return; } else { CBJoystick.SelectedIndex = cj; joysticks[cj].SetCooperativeLevel(this, SlimDX.DirectInput.CooperativeLevel.Exclusive | SlimDX.DirectInput.CooperativeLevel.Background); } foreach (DeviceObjectInstance deviceObject in joysticks[cj].GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) joysticks[cj].GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(0, 1000); } joysticks[cj].Acquire(); timerJoystickRead.Interval = 1000 / 50; timerJoystickRead.Start(); }
public void Initialize() { DirectInput dInput = new DirectInput(); IList<DeviceInstance> deviceList = dInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly); if (deviceList.Count == 0) { throw new Exception("No Device is connected to the system."); } else { _gamePads = new Joystick[deviceList.Count]; _states = new JoystickState[deviceList.Count]; //Initialize all GamePads Connected to the System for (int i = 0; i < deviceList.Count; i++) { _gamePads[i] = new Joystick(dInput, deviceList[i].InstanceGuid); _states[i] = new JoystickState(); //DONT know what to sned in this .. its a handle to the window .. so the gui handle will be send i guess .. maybe //pGamePads[i].SetCooperativeLevel(this, CooperativeLevel.Exclusive | CooperativeLevel.Foreground); } for (int i = 0; i < _gamePads.Length; i++) { foreach (DeviceObjectInstance deviceObject in _gamePads[i].GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) { _gamePads[i].GetObjectPropertiesById((int)deviceObject.ObjectType) .SetRange(_joyStickMin, _joyStickMax); } } //Get Access to the Input Device _gamePads[i].Acquire(); } } }
// --- INITIALIZTION --- public int GetSticks(IMatchDisplay form) { _form = form; DirectInput Input = new DirectInput(); List<Joystick> sticks = new List<Joystick>(); // Creates the list of joysticks connected to the computer via USB. foreach (DeviceInstance device in Input.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { // Creates a joystick for each game device in USB Ports try { var stick = new Joystick(Input, device.InstanceGuid); stick.Acquire(); // Gets the joysticks properties and sets the range for them. foreach (DeviceObjectInstance deviceObject in stick.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) stick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-100, 100); } // Adds how ever many joysticks are connected to the computer into the sticks list. sticks.Add(stick); } catch (DirectInputException) { } } Sticks = sticks.ToArray(); var count = Sticks.Length; if (count > 0) { tm1939LoadSticks(); } return count; // sticks.ToArray(); }
private void InitializeDevices() { var handle = WrenCore.WindowHandle; _joysticks = new List<Joystick>(); DirectInput di = new DirectInput(); foreach (var device in di.GetDevices(DeviceClass.All, DeviceEnumerationFlags.AttachedOnly)) { if ((device.Type & DeviceType.Keyboard) == DeviceType.Keyboard) { Keyboard keyboard = new Keyboard(di); keyboard.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground); _keyboard = keyboard; } else if ((device.Type & DeviceType.Joystick) == DeviceType.Joystick) { Joystick joystick = new Joystick(di, device.InstanceGuid); joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground); _joysticks.Add(joystick); } } }
private void LoadJoysticks() { DirectInput di = new DirectInput(); List<DeviceInstance> devices = new List<DeviceInstance>(); devices.AddRange(di.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)); foreach (DeviceInstance i in devices) { if (i.Type == DeviceType.Joystick) { Joystick j = new Joystick(di, i.InstanceGuid); j.Acquire(); sticks.Add(j); stickstate.Add(j.GetCurrentState()); } } // set up a timer to poll joystick state at 10Hz timer.Tick += new EventHandler(timer_Tick); timer.Interval = new TimeSpan(0, 0, 0, 0, 100); timer.Start(); }
public void InitializeInputRenderer() { // prepare things IJoypadConnecter joy1 = null; IJoypadConnecter joy2 = null; IJoypadConnecter joy3 = null; IJoypadConnecter joy4 = null; // Refresh input devices ! DirectInput di = new DirectInput(); List<DeviceInstance> devices = new List<DeviceInstance>(di.GetDevices()); bool found = false; #region Player 1 switch (Program.Settings.ControlSettings.Joypad1DeviceGuid) { default: { foreach (DeviceInstance dev in devices) { if (dev.InstanceGuid.ToString().ToLower() == Program.Settings.ControlSettings.Joypad1DeviceGuid) { // We found the device !! // Let's see if we have the settings for this device foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad1Devices) { if (con.DeviceGuid.ToLower() == dev.InstanceGuid.ToString().ToLower()) { // This is it ! switch (dev.Type) { case SlimDX.DirectInput.DeviceType.Keyboard: { joy1 = new NesJoypadPcKeyboardConnection(this.Handle, con); found = true; break; } case SlimDX.DirectInput.DeviceType.Joystick: { joy1 = new NesJoypadPcJoystickConnection(this.Handle, dev.InstanceGuid.ToString(), con); found = true; break; } } break; } } break; } } break; } case "x-controller-1": { SlimDX.XInput.Controller c1 = new Controller(UserIndex.One); if (c1.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad1Devices) { if (con.DeviceGuid == "x-controller-1") { joy1 = new NesJoypadXControllerConnection("x-controller-1", con); found = true; break; } } } break; } case "x-controller-2": { SlimDX.XInput.Controller c2 = new Controller(UserIndex.Two); if (c2.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad1Devices) { if (con.DeviceGuid == "x-controller-2") { joy1 = new NesJoypadXControllerConnection("x-controller-2", con); found = true; break; } } } break; } case "x-controller-3": { SlimDX.XInput.Controller c3 = new Controller(UserIndex.Three); if (c3.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad1Devices) { if (con.DeviceGuid == "x-controller-3") { joy1 = new NesJoypadXControllerConnection("x-controller-3", con); found = true; break; } } } break; } case "x-controller-4": { SlimDX.XInput.Controller c4 = new Controller(UserIndex.Four); if (c4.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad1Devices) { if (con.DeviceGuid == "x-controller-4") { joy1 = new NesJoypadXControllerConnection("x-controller-4", con); found = true; break; } } } break; } } if (!found && Program.Settings.ControlSettings.Joypad1AutoSwitchBackToKeyboard) { foreach (DeviceInstance dev in devices) { if (dev.Type == SlimDX.DirectInput.DeviceType.Keyboard) { // We found the device !! // Let's see if we have the settings for this device foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad1Devices) { if (con.DeviceGuid.ToLower() == dev.InstanceGuid.ToString().ToLower()) { // This is it ! joy1 = new NesJoypadPcKeyboardConnection(this.Handle, con); break; } } break; } } } #endregion #region Player 2 found = false; switch (Program.Settings.ControlSettings.Joypad2DeviceGuid) { default: { foreach (DeviceInstance dev in devices) { if (dev.InstanceGuid.ToString().ToLower() == Program.Settings.ControlSettings.Joypad2DeviceGuid) { // We found the device !! // Let's see if we have the settings for this device foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad2Devices) { if (con.DeviceGuid.ToLower() == dev.InstanceGuid.ToString().ToLower()) { // This is it ! switch (dev.Type) { case SlimDX.DirectInput.DeviceType.Keyboard: { joy2 = new NesJoypadPcKeyboardConnection(this.Handle, con); found = true; break; } case SlimDX.DirectInput.DeviceType.Joystick: { joy2 = new NesJoypadPcJoystickConnection(this.Handle, dev.InstanceGuid.ToString(), con); found = true; break; } } break; } } break; } } break; } case "x-controller-1": { SlimDX.XInput.Controller c1 = new Controller(UserIndex.One); if (c1.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad2Devices) { if (con.DeviceGuid == "x-controller-1") { joy2 = new NesJoypadXControllerConnection("x-controller-1", con); found = true; break; } } } break; } case "x-controller-2": { SlimDX.XInput.Controller c2 = new Controller(UserIndex.Two); if (c2.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad2Devices) { if (con.DeviceGuid == "x-controller-2") { joy2 = new NesJoypadXControllerConnection("x-controller-2", con); found = true; break; } } } break; } case "x-controller-3": { SlimDX.XInput.Controller c3 = new Controller(UserIndex.Three); if (c3.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad2Devices) { if (con.DeviceGuid == "x-controller-3") { joy2 = new NesJoypadXControllerConnection("x-controller-3", con); found = true; break; } } } break; } case "x-controller-4": { SlimDX.XInput.Controller c4 = new Controller(UserIndex.Four); if (c4.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad2Devices) { if (con.DeviceGuid == "x-controller-4") { joy2 = new NesJoypadXControllerConnection("x-controller-4", con); found = true; break; } } } break; } } if (!found && Program.Settings.ControlSettings.Joypad2AutoSwitchBackToKeyboard) { foreach (DeviceInstance dev in devices) { if (dev.Type == SlimDX.DirectInput.DeviceType.Keyboard) { // We found the device !! // Let's see if we have the settings for this device foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad2Devices) { if (con.DeviceGuid.ToLower() == dev.InstanceGuid.ToString().ToLower()) { // This is it ! joy2 = new NesJoypadPcKeyboardConnection(this.Handle, con); break; } } break; } } } #endregion #region Player 3 found = false; switch (Program.Settings.ControlSettings.Joypad3DeviceGuid) { default: { foreach (DeviceInstance dev in devices) { if (dev.InstanceGuid.ToString().ToLower() == Program.Settings.ControlSettings.Joypad3DeviceGuid) { // We found the device !! // Let's see if we have the settings for this device foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad3Devices) { if (con.DeviceGuid.ToLower() == dev.InstanceGuid.ToString().ToLower()) { // This is it ! switch (dev.Type) { case SlimDX.DirectInput.DeviceType.Keyboard: { joy3 = new NesJoypadPcKeyboardConnection(this.Handle, con); found = true; break; } case SlimDX.DirectInput.DeviceType.Joystick: { joy3 = new NesJoypadPcJoystickConnection(this.Handle, dev.InstanceGuid.ToString(), con); found = true; break; } } break; } } break; } } break; } case "x-controller-1": { SlimDX.XInput.Controller c1 = new Controller(UserIndex.One); if (c1.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad3Devices) { if (con.DeviceGuid == "x-controller-1") { joy3 = new NesJoypadXControllerConnection("x-controller-1", con); found = true; break; } } } break; } case "x-controller-2": { SlimDX.XInput.Controller c2 = new Controller(UserIndex.Two); if (c2.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad3Devices) { if (con.DeviceGuid == "x-controller-2") { joy3 = new NesJoypadXControllerConnection("x-controller-2", con); found = true; break; } } } break; } case "x-controller-3": { SlimDX.XInput.Controller c3 = new Controller(UserIndex.Three); if (c3.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad3Devices) { if (con.DeviceGuid == "x-controller-3") { joy3 = new NesJoypadXControllerConnection("x-controller-3", con); found = true; break; } } } break; } case "x-controller-4": { SlimDX.XInput.Controller c4 = new Controller(UserIndex.Four); if (c4.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad3Devices) { if (con.DeviceGuid == "x-controller-4") { joy3 = new NesJoypadXControllerConnection("x-controller-4", con); found = true; break; } } } break; } } if (!found && Program.Settings.ControlSettings.Joypad3AutoSwitchBackToKeyboard) { foreach (DeviceInstance dev in devices) { if (dev.Type == SlimDX.DirectInput.DeviceType.Keyboard) { // We found the device !! // Let's see if we have the settings for this device foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad3Devices) { if (con.DeviceGuid.ToLower() == dev.InstanceGuid.ToString().ToLower()) { // This is it ! joy3 = new NesJoypadPcKeyboardConnection(this.Handle, con); break; } } break; } } } #endregion #region Player 4 found = false; switch (Program.Settings.ControlSettings.Joypad4DeviceGuid) { default: { foreach (DeviceInstance dev in devices) { if (dev.InstanceGuid.ToString().ToLower() == Program.Settings.ControlSettings.Joypad4DeviceGuid) { // We found the device !! // Let's see if we have the settings for this device foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad4Devices) { if (con.DeviceGuid.ToLower() == dev.InstanceGuid.ToString().ToLower()) { // This is it ! switch (dev.Type) { case SlimDX.DirectInput.DeviceType.Keyboard: { joy4 = new NesJoypadPcKeyboardConnection(this.Handle, con); found = true; break; } case SlimDX.DirectInput.DeviceType.Joystick: { joy4 = new NesJoypadPcJoystickConnection(this.Handle, dev.InstanceGuid.ToString(), con); found = true; break; } } break; } } break; } } break; } case "x-controller-1": { SlimDX.XInput.Controller c1 = new Controller(UserIndex.One); if (c1.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad4Devices) { if (con.DeviceGuid == "x-controller-1") { joy4 = new NesJoypadXControllerConnection("x-controller-1", con); found = true; break; } } } break; } case "x-controller-2": { SlimDX.XInput.Controller c2 = new Controller(UserIndex.Two); if (c2.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad4Devices) { if (con.DeviceGuid == "x-controller-2") { joy4 = new NesJoypadXControllerConnection("x-controller-2", con); found = true; break; } } } break; } case "x-controller-3": { SlimDX.XInput.Controller c3 = new Controller(UserIndex.Three); if (c3.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad4Devices) { if (con.DeviceGuid == "x-controller-3") { joy4 = new NesJoypadXControllerConnection("x-controller-3", con); found = true; break; } } } break; } case "x-controller-4": { SlimDX.XInput.Controller c4 = new Controller(UserIndex.Four); if (c4.IsConnected) { foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad4Devices) { if (con.DeviceGuid == "x-controller-4") { joy4 = new NesJoypadXControllerConnection("x-controller-4", con); found = true; break; } } } break; } } if (!found && Program.Settings.ControlSettings.Joypad3AutoSwitchBackToKeyboard) { foreach (DeviceInstance dev in devices) { if (dev.Type == SlimDX.DirectInput.DeviceType.Keyboard) { // We found the device !! // Let's see if we have the settings for this device foreach (IInputSettingsJoypad con in Program.Settings.ControlSettings.Joypad4Devices) { if (con.DeviceGuid.ToLower() == dev.InstanceGuid.ToString().ToLower()) { // This is it ! joy4 = new NesJoypadPcKeyboardConnection(this.Handle, con); break; } } break; } } } #endregion NesEmu.SetupJoypads(joy1, joy2, joy3, joy4); #region VSUnisystem DIP found = false; switch (Program.Settings.ControlSettings.VSUnisystemDIPDeviceGuid) { default: { foreach (DeviceInstance dev in devices) { if (dev.InstanceGuid.ToString().ToLower() == Program.Settings.ControlSettings.VSUnisystemDIPDeviceGuid) { // We found the device !! // Let's see if we have the settings for this device foreach (IInputSettingsVSUnisystemDIP con in Program.Settings.ControlSettings.VSUnisystemDIPDevices) { if (con.DeviceGuid.ToLower() == dev.InstanceGuid.ToString().ToLower()) { // This is it ! switch (dev.Type) { case SlimDX.DirectInput.DeviceType.Keyboard: { NesEmu.SetupVSUnisystemDIP(new NesVSUnisystemDIPKeyboardConnection(this.Handle, con)); found = true; break; } case SlimDX.DirectInput.DeviceType.Joystick: { NesEmu.SetupVSUnisystemDIP(new NesVSUnisystemDIPJoystickConnection(this.Handle, dev.InstanceGuid.ToString(), con)); found = true; break; } } break; } } break; } } break; } case "x-controller-1": { SlimDX.XInput.Controller c1 = new Controller(UserIndex.One); if (c1.IsConnected) { foreach (IInputSettingsVSUnisystemDIP con in Program.Settings.ControlSettings.VSUnisystemDIPDevices) { if (con.DeviceGuid == "x-controller-1") { NesEmu.SetupVSUnisystemDIP(new NesVSUnisystemDIPXControllerConnection("x-controller-1", con)); found = true; break; } } } break; } case "x-controller-2": { SlimDX.XInput.Controller c2 = new Controller(UserIndex.Two); if (c2.IsConnected) { foreach (IInputSettingsVSUnisystemDIP con in Program.Settings.ControlSettings.VSUnisystemDIPDevices) { if (con.DeviceGuid == "x-controller-2") { NesEmu.SetupVSUnisystemDIP(new NesVSUnisystemDIPXControllerConnection("x-controller-2", con)); found = true; break; } } } break; } case "x-controller-3": { SlimDX.XInput.Controller c3 = new Controller(UserIndex.Three); if (c3.IsConnected) { foreach (IInputSettingsVSUnisystemDIP con in Program.Settings.ControlSettings.VSUnisystemDIPDevices) { if (con.DeviceGuid == "x-controller-3") { NesEmu.SetupVSUnisystemDIP(new NesVSUnisystemDIPXControllerConnection("x-controller-3", con)); found = true; break; } } } break; } case "x-controller-4": { SlimDX.XInput.Controller c4 = new Controller(UserIndex.Four); if (c4.IsConnected) { foreach (IInputSettingsVSUnisystemDIP con in Program.Settings.ControlSettings.VSUnisystemDIPDevices) { if (con.DeviceGuid == "x-controller-4") { NesEmu.SetupVSUnisystemDIP(new NesVSUnisystemDIPXControllerConnection("x-controller-4", con)); found = true; break; } } } break; } } if (!found && Program.Settings.ControlSettings.VSUnisystemDIPAutoSwitchBackToKeyboard) { foreach (DeviceInstance dev in devices) { if (dev.Type == SlimDX.DirectInput.DeviceType.Keyboard) { // We found the device !! // Let's see if we have the settings for this device foreach (IInputSettingsVSUnisystemDIP con in Program.Settings.ControlSettings.VSUnisystemDIPDevices) { if (con.DeviceGuid.ToLower() == dev.InstanceGuid.ToString().ToLower()) { // This is it ! NesEmu.SetupVSUnisystemDIP(new NesVSUnisystemDIPKeyboardConnection(this.Handle, con)); break; } } break; } } } #endregion // ZAPPER NesEmu.SetupZapper(zapper = new ZapperConnecter(this.Handle, this.Location.X, this.Location.Y + menuStrip1.Height, panel_surface.Width, panel_surface.Height)); video.SetupZapperBounds(); }
public static void BuildDefaultControlSettings() { Program.Settings.ControlSettings = new ControlMappingSettings(); Program.Settings.ControlSettings.Joypad1Devices = new List<IInputSettingsJoypad>(); Program.Settings.ControlSettings.Joypad2Devices = new List<IInputSettingsJoypad>(); Program.Settings.ControlSettings.Joypad3Devices = new List<IInputSettingsJoypad>(); Program.Settings.ControlSettings.Joypad4Devices = new List<IInputSettingsJoypad>(); Program.Settings.ControlSettings.VSUnisystemDIPDevices = new List<IInputSettingsVSUnisystemDIP>(); DirectInput di = new DirectInput(); foreach (DeviceInstance ins in di.GetDevices()) { if (ins.Type == DeviceType.Keyboard) { // Player 1 joypad IInputSettingsJoypad joy1 = new IInputSettingsJoypad(); joy1.DeviceGuid = ins.InstanceGuid.ToString(); joy1.ButtonA = "X"; joy1.ButtonB = "Z"; joy1.ButtonTurboA = "S"; joy1.ButtonTurboB = "A"; joy1.ButtonDown = "DownArrow"; joy1.ButtonLeft = "LeftArrow"; joy1.ButtonRight = "RightArrow"; joy1.ButtonUp = "UpArrow"; joy1.ButtonSelect = "C"; joy1.ButtonStart = "V"; Program.Settings.ControlSettings.Joypad1Devices.Add(joy1); Program.Settings.ControlSettings.Joypad1DeviceGuid = joy1.DeviceGuid; Program.Settings.ControlSettings.Joypad1AutoSwitchBackToKeyboard = true; // Player 2 joypad IInputSettingsJoypad joy2 = new IInputSettingsJoypad(); joy2.DeviceGuid = ins.InstanceGuid.ToString(); joy2.ButtonA = "K"; joy2.ButtonB = "L"; joy2.ButtonTurboA = "I"; joy2.ButtonTurboB = "O"; joy2.ButtonDown = "S"; joy2.ButtonLeft = "A"; joy2.ButtonRight = "D"; joy2.ButtonUp = "W"; joy2.ButtonSelect = "B"; joy2.ButtonStart = "N"; Program.Settings.ControlSettings.Joypad2Devices.Add(joy2); Program.Settings.ControlSettings.Joypad2DeviceGuid = joy2.DeviceGuid; Program.Settings.ControlSettings.Joypad2AutoSwitchBackToKeyboard = true; // Player 3 Program.Settings.ControlSettings.Joypad3Devices = new List<IInputSettingsJoypad>(); Program.Settings.ControlSettings.Joypad3DeviceGuid = ""; Program.Settings.ControlSettings.Joypad3AutoSwitchBackToKeyboard = true; // Player 4 Program.Settings.ControlSettings.Joypad4Devices = new List<IInputSettingsJoypad>(); Program.Settings.ControlSettings.Joypad4DeviceGuid = ""; Program.Settings.ControlSettings.Joypad4AutoSwitchBackToKeyboard = true; // VSUnisystem IInputSettingsVSUnisystemDIP vs = new IInputSettingsVSUnisystemDIP(); vs.DeviceGuid = ins.InstanceGuid.ToString(); vs.CreditServiceButton = "End"; vs.DIPSwitch1 = "NumberPad1"; vs.DIPSwitch2 = "NumberPad2"; vs.DIPSwitch3 = "NumberPad3"; vs.DIPSwitch4 = "NumberPad4"; vs.DIPSwitch5 = "NumberPad5"; vs.DIPSwitch6 = "NumberPad6"; vs.DIPSwitch7 = "NumberPad7"; vs.DIPSwitch8 = "NumberPad8"; vs.CreditLeftCoinSlot = "Insert"; vs.CreditRightCoinSlot = "Home"; Program.Settings.ControlSettings.VSUnisystemDIPDevices.Add(vs); Program.Settings.ControlSettings.VSUnisystemDIPDeviceGuid = vs.DeviceGuid; Program.Settings.ControlSettings.VSUnisystemDIPAutoSwitchBackToKeyboard = true; break; } } }
public void Connect(int index) { List<DeviceInstance> devices = new List<DeviceInstance>(); Declare(); dinput = new DirectInput(); //Get connected devices foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { devices.Add(device); } if (devices.Count() > 0) { try { //Connect to selected device joystick = new SlimDX.DirectInput.Joystick(dinput, devices[index].InstanceGuid); foreach (DeviceObjectInstance deviceObject in joystick.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000); } joystick.Acquire(); Connected = true; } catch (DirectInputException) { Connected = false; } //Get data from selected gamepad ThreadTransmit = new Thread(delegate() { while (Connected) { Thread.Sleep(50); GetInput(); } }); ThreadTransmit.Start(); } }
private void InitializeGamepad() { // make sure that DirectInput has been initialized DirectInput dinput = new DirectInput(); // search for devices foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { // create the device try { joystick = new SlimDX.DirectInput.Joystick(dinput, device.InstanceGuid); break; } catch (DirectInputException) { } } if (joystick == null) { MessageBox.Show("There are no joysticks attached to the system."); return; } foreach (DeviceObjectInstance deviceObject in joystick.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000); //UpdateControl(deviceObject); } // acquire the device joystick.Acquire(); }
private void InitDeviceList() { DirectInput di = new DirectInput(); _deviceList = di.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly); }