private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var    txt = (ComboBox)sender;
            var    t   = txt.Tag as JoystickButtons;
            var    selectedDeviceName = txt.SelectedValue.ToString();
            var    selectedDevice     = _joystickControlRawInput.GetMouseDeviceByName(selectedDeviceName);
            string path = "null";
            var    type = RawDeviceType.None;

            if (selectedDeviceName == "Windows Mouse Cursor")
            {
                path = "Windows Mouse Cursor";
                type = RawDeviceType.Mouse;
            }
            else if (selectedDeviceName == "None")
            {
                path = "None";
                type = RawDeviceType.None;
            }
            else if (selectedDeviceName == "Unknown Device")
            {
                path = "null";
                type = RawDeviceType.Mouse;
            }
            else if (selectedDevice == null)
            {
                MessageBoxHelper.ErrorOK("Selected device is currently not available!");
                return;
            }
            else
            {
                path = selectedDevice.DevicePath;
                type = RawDeviceType.Mouse;
            }

            var button = new RawInputButton
            {
                DevicePath  = path,
                DeviceType  = type,
                MouseButton = RawMouseButton.None,
                KeyboardKey = Keys.None
            };

            t.RawInputButton = button;
            t.BindName       = selectedDeviceName;
            t.BindNameRi     = selectedDeviceName;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets text box text and tag.
        /// </summary>
        /// <param name="key"></param>
        private void SetTextBoxText(string text, RawInputData data)
        {
            Application.Current.Dispatcher.BeginInvoke(
                DispatcherPriority.Background,
                new Action(() =>
            {
                bool save = true;
                var txt   = GetActiveTextBox();

                if (txt == null)
                {
                    return;
                }

                // Ignore first
                if (txt == _lastActiveTextBox)
                {
                    string path = "null";

                    if (data != null && data.Device != null && data.Device.DevicePath != null)
                    {
                        path = data.Device.DevicePath;
                    }

                    var button = new RawInputButton
                    {
                        DevicePath  = path,
                        DeviceType  = RawDeviceType.None,
                        MouseButton = RawMouseButton.None,
                        KeyboardKey = Keys.None
                    };

                    if (data is RawInputMouseData)
                    {
                        RawInputMouseData mouse = data as RawInputMouseData;
                        button.MouseButton      = GetButtonFromFlags(mouse.Mouse.Buttons);
                        button.DeviceType       = RawDeviceType.Mouse;
                    }
                    else if (data is RawInputKeyboardData)
                    {
                        RawInputKeyboardData kb = data as RawInputKeyboardData;
                        button.KeyboardKey      = (Keys)kb.Keyboard.VirutalKey;
                        button.DeviceType       = RawDeviceType.Keyboard;

                        if (button.KeyboardKey == Keys.Escape)
                        {
                            save = false;
                        }
                    }

                    // Save?
                    if (save)
                    {
                        txt.ToolTip = text;
                        txt.Text    = text;

                        var t            = txt.Tag as JoystickButtons;
                        t.RawInputButton = button;
                        t.BindNameRi     = text;
                    }
                    else
                    {
                        txt.ToolTip = "";
                        txt.Text    = "";
                    }

                    // Unfocus textbox
                    Keyboard.ClearFocus();
                    FocusManager.SetFocusedElement(Application.Current.Windows[0], null);
                    _lastActiveTextBox = null;
                }
                else
                {
                    _lastActiveTextBox = txt;
                }
            }));
        }