Esempio n. 1
0
        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();
                }
            }
        }