Ejemplo n.º 1
0
        public bool 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, throws an error
            if (joystickGuid == Guid.Empty)
            {
                //log.MsgWriteLine(LogWindow.MsgTypes.Error, "No joystick/Gamepad found.");
                return(false);
            }

            // Instantiate the joystick
            dxJoystick = new SharpDX.DirectInput.Joystick(directInput, joystickGuid);

            //log.MsgWriteLine(LogWindow.MsgTypes.Normal, "Found Joystick/Gamepad with GUID: {0}", joystickGuid);

            // Query all suported ForceFeedback effects
            var allEffects = dxJoystick.GetEffects();

            //foreach (var effectInfo in allEffects)
            //log.MsgWriteLine(LogWindow.MsgTypes.Normal, "Effect available {0}", effectInfo.Name);

            // Set BufferSize in order to use buffered data.
            dxJoystick.Properties.BufferSize = 128;

            // Acquire the joystick
            dxJoystick.Acquire();

            return(true);
        }
    protected void GenericControllerConnection()
    {
#if DEBUG
        Console.WriteLine("Launched new thread!");
        Console.WriteLine("Looking for Joystick!");
#endif
        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 (joystickGuid == Guid.Empty)
        {
            return;
        }
#if DEBUG
        Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid);
#endif

        joystick = new Joystick(directInput, joystickGuid);
        var allEffects = joystick.GetEffects();
#if DEBUG
        foreach (var effectInfo in allEffects)
        {
            Console.WriteLine("Effect available {0}", effectInfo.Name);
        }
#endif
        joystick.Properties.BufferSize = 128;
        joystick.Acquire();
    }