Example #1
0
        public void ObtainJoystick()
        {
            if (DJoystick != null)
            {
                DJoystick.Dispose();
            }

            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 (joystickGuid == Guid.Empty)
            {
                Log.LogMessage("No joystick connected");
                return;
            }

            // Instantiate the joystick
            DJoystick = new DirectJoystick(directInput, joystickGuid);

            Log.LogMessage("Found Joystick with GUID: {0}		Name: {1}", joystickGuid, DJoystick.Information.ProductName);

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

            // Acquire the joystick
            DJoystick.Acquire();
        }
Example #2
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                Unacquire();
                if (DJoystick != null)
                {
                    DJoystick.Dispose();
                }
                directInput.Dispose();
            }

            base.Dispose(disposing);
        }