private void OnLoaded(object sender, RoutedEventArgs routedEventArgs) { try { // // Initialization of DirectInputManager and registration for // events via EventBus may be done in any order. // // Register for controller button, POV, and axis events EventBus <EventController> .Instance.EventRecieved += OnEventController; // Register for event when connected controller list changes // Occurs when a controller is un/plugged (or otherwise en/disabled) EventBus <EventControllersChanged> .Instance.EventRecieved += OnEventControllersChanged; // Creates and starts threads to either poll or wait for joystick input. // Also synchronously enumerates and connects to all controller devices. // May throw SharpDXException directInput.Initialize(); // This is also happens OnEventControllersChanged() UpdateConnectedDevices(directInput.GetConnectedDeviceInfos()); } catch (SharpDXException exception) { MessageBox.Show(exception.Message, "DirectInput initialization exception"); if (null != directInput) { directInput.Dispose(); } } }
static void Main() { DirectInputManager directInput = null; ExitOnKeypress(); try { // // Creation of DirectInputManager and registration for events via EventBus // may be done in any order. // // Constructs wrapped SharpDX.DirectInput instance but nothing more directInput = new DirectInputManager(); // Starts threads that either poll or wait for joystick input directInput.Initialize(); // Register for controller button, POV, and axis events EventBus <EventController> .Instance.EventRecieved += OnEventController; // Register for event when connected controller list changes // Occurs when a controller is un/plugged (or otherwise en/disabled) EventBus <EventControllersChanged> .Instance.EventRecieved += OnEventControllersChanged; // Runs until application exits via keypress Thread.Sleep(System.Threading.Timeout.Infinite); } catch (SharpDX.SharpDXException e) { Console.WriteLine("SharpDX Exception while initializing DirectInputManager: " + e); } catch (Exception e) { Console.WriteLine(e); } finally { directInput.Dispose(); } }
static void Main(string[] args) { ExitOnKeypress(); using (DirectInputManager directInputManager = new DirectInputManager( // Supply ILogger for DirectInputManager to use new Logger4net(typeof(DirectInputManager).ToString()))) { try { directInputManager.Initialize(); } catch (SharpDXException e) { LOGGER.Error("Exception initializing NerfDX.DirectInputManager", e); } EventBus <EventController> .Instance.EventRecieved += OnEventController; EventBus <EventControllersChanged> .Instance.EventRecieved += OnEventControllersChanged; // Runs until application exits via keypress Thread.Sleep(System.Threading.Timeout.Infinite); } }