Example #1
0
        public PlaceholderInputDevice([CanBeNull] string id, string displayName, int index)
        {
            Id             = id;
            Index          = index;
            IsController   = DirectInputDeviceUtils.IsController(displayName);
            OriginalIniIds = new List <int> {
                index
            };

            if (id != null && DisplayInputParams.Get(id, out var gotDisplayName, out _axesP, out _buttonsP, out _povsP))
            {
                DisplayName = gotDisplayName;
            }
Example #2
0
        private DirectInputDevice([NotNull] Joystick device, int index)
        {
            Device = device.Information;

            InstanceId     = GuidToString(device.Information.InstanceGuid);
            ProductId      = GuidToString(device.Information.ProductGuid);
            Index          = index;
            IsController   = DirectInputDeviceUtils.IsController(device.Information.InstanceName);
            OriginalIniIds = new List <int>();

            _joystick = device;

            var window = Application.Current?.MainWindow;

            if (window != null)
            {
                try {
                    _joystick.SetCooperativeLevel(new WindowInteropHelper(window).Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
                    _joystick.Properties.AxisMode = DeviceAxisMode.Absolute;

                    if (!Acquire(_joystick))
                    {
                        _joystick.SetCooperativeLevel(new WindowInteropHelper(window).Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
                        Acquire(_joystick);
                    }
                } catch (Exception e) {
                    Logging.Warning("Can’t set cooperative level: " + e);
                }
            }

            Axis    = Enumerable.Range(0, 8).Select(x => new DirectInputAxle(this, x)).ToArray();
            Buttons = Enumerable.Range(0, _joystick.Capabilities.ButtonCount).Select(x => new DirectInputButton(this, x)).ToArray();
            Povs    = Enumerable.Range(0, _joystick.Capabilities.PovCount)
                      .SelectMany(x => Enumerable.Range(0, 4).Select(y => new { Id = x, Direction = (DirectInputPovDirection)y }))
                      .Select(x => new DirectInputPov(this, x.Id, x.Direction)).ToArray();
            RefreshDescription();
            FilesStorage.Instance.Watcher(ContentCategory.Controllers).Update += OnDefinitionsUpdate;
        }