//Gets the currently connected controller public void getCurrentController() { //currentXInputDevice.cs currentXInputDevice getDevice = new currentXInputDevice(); xController = getDevice.getActiveController(); if (xController != null) { Console.WriteLine("Starting xListener thread"); xListener.RunWorkerAsync(); } else { Console.WriteLine("No controller detected"); } }
private void xListener_DoWork(object sender, DoWorkEventArgs e) { Console.WriteLine("xListener Started"); currentXInputDevice xDevice = new currentXInputDevice(); while (xController.IsConnected) { var buttons = xController.GetState().Gamepad.Buttons; var pressedButton = xDevice.getPressedButton(buttons).ToString(); //Check for buttons here! if (pressedButton != "None") { if (pressedButton == "DPadDown") { Dispatcher.Invoke(new Action(() => MoveFocus(0))); } else if (pressedButton == "DPadUp") { Dispatcher.Invoke(new Action(() => MoveFocus(1))); } else if (pressedButton == "A") { Dispatcher.Invoke(new Action(() => A_Press())); } else if (pressedButton == "B") { Dispatcher.Invoke(new Action(() => HideOptions())); } } Thread.Sleep(100); } Console.WriteLine("Disposing of xListener thread!"); }