private void OnDetectMouseRequested(object parameter)
        {
            var mainWindow = Application.Current.MainWindow as MainWindow;

            if (mainWindow == null)
            {
                return;
            }

            if (mainWindow.Splitter == null || mainWindow.Splitter.InputManager == null)
            {
                return;
            }

            var detector = new InputDetectorWindow(mainWindow.Splitter.InputManager, InputDetectorDeviceFilter.MouseOnly);

            detector.Owner = mainWindow;
            detector.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            detector.InputDetected        += (oo, ss) =>
            {
                if (!ss.InputDevice.IsKeyboard)
                {
                    this.Mouse = ss.InputDevice as Mouse;
                    detector.Close();
                }
            };

            detector.ShowDialog();
        }
        private void OnDetectKeyRequested(object parameter)
        {
            var presetElement = parameter as IPresetElement;

            if (presetElement == null)
            {
                return;
            }

            var slot = Helpers.ParentFinder.FindParent <EmulationSlot>(this);

            if (slot == null)
            {
                return;
            }

            var mainWindow = Application.Current.MainWindow as MainWindow;

            if (mainWindow == null)
            {
                return;
            }

            var splitter = mainWindow.Splitter;

            if (splitter == null)
            {
                return;
            }

            bool isKeyboardSet = slot.Keyboard != null && slot.Keyboard != Keyboard.None;
            bool isMouseSet    = slot.Mouse != null && slot.Mouse != Mouse.None;

            if (!isKeyboardSet && !isMouseSet)
            {
                Controls.MessageBox.Show(
                    "You can not detect an input key, because the slot is not assosiated with any valid input device!",
                    ApplicationInfo.AppNameVersion,
                    MessageBoxButton.OK,
                    MessageBoxImage.Hand);

                return;
            }

            InputDetectorDeviceFilter filter = InputDetectorDeviceFilter.KeyboardAndMouse;

            if (isKeyboardSet && !isMouseSet)
            {
                filter = InputDetectorDeviceFilter.KeyboardOnly;
            }

            if (isMouseSet && !isKeyboardSet)
            {
                filter = InputDetectorDeviceFilter.MouseOnly;
            }

            var detector = new InputDetectorWindow(splitter.InputManager, filter, presetElement, slot);

            detector.Owner = mainWindow;
            detector.WindowStartupLocation = WindowStartupLocation.CenterOwner;

            InputKey newKey = InputKey.None;

            detector.InputDetected += (ss, ee) =>
            {
                newKey = ee.Key;
                detector.Close();
            };

            detector.ShowDialog();
            if (newKey == InputKey.None)
            {
                return;
            }

            int index = 0;

            switch (presetElement.FunctionType)
            {
            case SplitterCore.FunctionType.Button:
                index = this.Preset.Buttons.IndexOf(presetElement as PresetButton);
                this.Preset.Buttons[index] = new PresetButton(this.Preset.Buttons[index].Button, newKey);
                break;

            case SplitterCore.FunctionType.Trigger:
                index = this.Preset.Triggers.IndexOf(presetElement as PresetTrigger);
                this.Preset.Triggers[index] = new PresetTrigger(this.Preset.Triggers[index].Trigger, newKey);
                break;

            case SplitterCore.FunctionType.Axis:
                index = this.Preset.Axes.IndexOf(presetElement as PresetAxis);
                this.Preset.Axes[index] = new PresetAxis(this.Preset.Axes[index].Axis, this.Preset.Axes[index].Value, newKey);
                break;

            case SplitterCore.FunctionType.Dpad:
                index = this.Preset.Dpads.IndexOf(presetElement as PresetDpad);
                this.Preset.Dpads[index] = new PresetDpad(this.Preset.Dpads[index].Direction, newKey);
                break;

            case SplitterCore.FunctionType.Custom:
                index = this.Preset.CustomFunctions.IndexOf(presetElement as PresetCustom);
                this.Preset.CustomFunctions[index] = new PresetCustom(this.Preset.CustomFunctions[index].Function, newKey);
                break;

            default:
                break;
            }
        }