/// <summary>
        /// Unassign keyboard key or joystick button when double clicked a Datagrid cell.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DataGrid_MouseButtonDoubleClick(object sender, MouseButtonEventArgs e)
        {
            KeyMappingTimer.Stop();

            KeyAssgn selectedItem = (KeyAssgn)KeyMappingGrid.SelectedItem;

            if (selectedItem == null)
            {
                return;
            }
            if (KeyMappingGrid.CurrentColumn == null)
            {
                return;
            }
            if (selectedItem.GetVisibility() != "White")
            {
                return;
            }
            if (selectedItem.GetCallback() == "SimDoNothing")
            {
                return;
            }

            KeyMappingWindow.ShowKeyMappingWindow(selectedItem, keyFile, deviceControl, sender);
            KeyMappingGrid.Items.Refresh();
            KeyMappingGrid.UnselectAllCells();

            KeyMappingTimer.Start();
        }
Exemple #2
0
        private void Reset()
        {
            neutralButtons = new NeutralButtons[MainWindow.deviceControl.joyAssign.Length];

            tmpJoyStick = new JoyAssgn[MainWindow.deviceControl.joyAssign.Length];
            for (int i = 0; i < MainWindow.deviceControl.joyAssign.Length; i++)
            {
                tmpJoyStick[i] = MainWindow.deviceControl.joyAssign[i].Clone();
            }
            tmpCallback = SelectedCallback.Clone();
        }
Exemple #3
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            deviceControl.joyAssign = tmpJoyStick;
            SelectedCallback.getOtherKeyInstance(tmpCallback);

            // Unassign the previous mapping that was assigned to this key/key combo.
            KeyAssgn oldKey = keyFile.keyAssign.FirstOrDefault(x => x != SelectedCallback && x.GetKeyAssignmentStatus() == SelectedCallback.GetKeyAssignmentStatus());

            if (oldKey != null)
            {
                oldKey.UnassignKeyboard();
            }

            Close();
        }
Exemple #4
0
        public KeyMappingWindow(MainWindow mainWindow, KeyAssgn SelectedCallback, KeyFile keyFile, DeviceControl deviceControl)
        {
            InitializeComponent();

            this.mainWindow = mainWindow;

            CallbackName.Content = SelectedCallback.GetKeyDescription();

            Select_PinkyShift.IsChecked = true;
            Select_DX_Release.IsChecked = true;

            this.SelectedCallback = SelectedCallback;
            this.keyFile          = keyFile;

            Reset();
        }
Exemple #5
0
        public KeyMappingWindow(KeyAssgn SelectedCallback, KeyFile keyFile, DeviceControl deviceControl)
        {
            InitializeComponent();
            CallbackName.Content        = SelectedCallback.GetKeyDescription();
            Select_PinkyShift.IsChecked = true;
            Select_DX_Release.IsChecked = true;
            this.SelectedCallback       = SelectedCallback;
            this.keyFile       = keyFile;
            this.deviceControl = deviceControl;
            neutralButtons     = new NeutralButtons[deviceControl.devList.Count];

            tmpJoyStick = new JoyAssgn[deviceControl.devList.Count];
            for (int i = 0; i < deviceControl.devList.Count; i++)
            {
                tmpJoyStick[i] = deviceControl.joyAssign[i].Clone();
            }
            tmpCallback = this.SelectedCallback.Clone();
        }
Exemple #6
0
        public static void ShowKeyMappingWindow(KeyAssgn SelectedCallback, KeyFile keyFile, DeviceControl deviceControl, object sender)
        {
            KeyMappingWindow ownWindow = new KeyMappingWindow(SelectedCallback, keyFile, deviceControl);

            ownWindow.ShowDialog();
        }
        /// <summary>
        /// You pressed keyboard keys? I will check which key was pressed with Shift/Ctrl/Alt.
        /// </summary>
        private void KeyMappingGrid_KeyDown()
        {
            if (SearchBox.IsSelectionActive)
            {
                return;
            }
            if (SearchBox.IsFocused)
            {
                return;
            }
            if (SearchBox.IsKeyboardFocused)
            {
                return;
            }

            bool Shift = false;
            bool Ctrl  = false;
            bool Alt   = false;

            int catchedScanCode = 0;

            directInputDevice.GetCurrentKeyboardState();

            for (int i = 1; i < 238; i++)
            {
                if (directInputDevice.KeyboardState[(Microsoft.DirectX.DirectInput.Key)i])
                {
                    if (i == (int)Microsoft.DirectX.DirectInput.Key.LeftShift |
                        i == (int)Microsoft.DirectX.DirectInput.Key.RightShift)
                    {
                        Shift = true;
                        continue;
                    }
                    if (i == (int)Microsoft.DirectX.DirectInput.Key.LeftControl |
                        i == (int)Microsoft.DirectX.DirectInput.Key.RightControl)
                    {
                        Ctrl = true;
                        continue;
                    }
                    if (i == (int)Microsoft.DirectX.DirectInput.Key.LeftAlt |
                        i == (int)Microsoft.DirectX.DirectInput.Key.RightAlt)
                    {
                        Alt = true;
                        continue;
                    }
                    catchedScanCode = i;
                }
            }
            if (catchedScanCode == 0)
            {
                return;
            }
            if (Select_PinkyShift.IsChecked == false)
            {
                return;
            }

            KeyAssgn keytmp = new KeyAssgn("SimDoNothing - 1 0 0XFFFFFFFF 0 0 0 - 1 \"nothing\"");

            keytmp.SetKeyboard(catchedScanCode, Shift, Ctrl, Alt);
            Label_AssgnStatus.Content = "INPUT " + keytmp.GetKeyAssignmentStatus();

            // If the key assignment was found, jump to the mapping for it and highlight it.
            KeyAssgn key = keyFile.keyAssign.FirstOrDefault(x => x.GetKeyAssignmentStatus() == keytmp.GetKeyAssignmentStatus());

            if (key != null)
            {
                Label_AssgnStatus.Content += "\t/" + key.Mapping;

                KeyMappingGrid.UpdateLayout();
                KeyMappingGrid.ScrollIntoView(key);
                KeyMappingGrid.SelectedIndex = KeyMappingGrid.Items.IndexOf(key);
            }
        }
        /// <summary>
        /// You pressed a joystick button to search which callback is it assigned to? OK let's go there.
        /// </summary>
        public void JumptoAssignedKey()
        {
            string target = "";

            switch (statusAssign)
            {
            case Status.GetNeutralPos:
                for (int i = 0; i < deviceControl.devList.Count; i++)
                {
                    neutralButtons[i] = new NeutralButtons(deviceControl.joyStick[i]);
                }
                statusAssign = Status.WaitingforInput;
                break;

            case Status.WaitingforInput:
                for (int i = 0; i < deviceControl.devList.Count; i++)
                {
                    buttons = deviceControl.joyStick[i].CurrentJoystickState.GetButtons();
                    for (int ii = 0; ii < 32; ii++)
                    {
                        if (buttons[ii] == 128 && deviceControl.joyAssign[i].dx[ii].assign[0].GetCallback() == "SimHotasPinkyShift" && pressedByHand == false)
                        {
                            Select_PinkyShift.IsChecked = false;
                        }
                        if (buttons[ii] == 0 && deviceControl.joyAssign[i].dx[ii].assign[0].GetCallback() == "SimHotasPinkyShift" && pressedByHand == false)
                        {
                            Select_PinkyShift.IsChecked = true;
                        }

                        if (buttons[ii] == neutralButtons[i].buttons[ii])
                        {
                            continue;
                        }
                        statusAssign = Status.GetNeutralPos;
                        if (buttons[ii] == 0)     // RELEASE SHIFT
                        {
                            Select_DX_Release.IsChecked = false;
                        }
                        else
                        {
                            Select_DX_Release.IsChecked = true;
                        }

                        if (deviceControl.joyAssign[i].dx[ii].assign[0].GetCallback() == "SimHotasPinkyShift" && pressedByHand == false)
                        {
                            continue;
                        }

                        Pinky     pinkyStatus     = Pinky.UnShift;
                        Behaviour behaviourStatus = Behaviour.Press;
                        if (Select_PinkyShift.IsChecked == false)
                        {
                            pinkyStatus = Pinky.Shift;
                        }
                        if (Select_DX_Release.IsChecked == false)
                        {
                            behaviourStatus = Behaviour.Release;
                        }

                        target = deviceControl.joyAssign[i].dx[ii].assign[(int)pinkyStatus + (int)behaviourStatus].GetCallback();
                        if (target == "SimDoNothing" && behaviourStatus == Behaviour.Release)
                        {
                        }
                        else
                        {
                            Label_AssgnStatus.Content = "DX" + (ii + 1) + "\t: " + deviceControl.joyAssign[i].GetProductName();
                        }
                    }
                    povs = deviceControl.joyStick[i].CurrentJoystickState.GetPointOfView();
                    for (int ii = 0; ii < 4; ii++)
                    {
                        if (povs[ii] == neutralButtons[i].povs[ii])
                        {
                            continue;
                        }
                        statusAssign = Status.GetNeutralPos;
                        if (povs[ii] == -1)
                        {
                            continue;
                        }

                        Pinky pinkyStatus = Pinky.UnShift;
                        if (Select_PinkyShift.IsChecked == false)
                        {
                            pinkyStatus = Pinky.Shift;
                        }

                        target = deviceControl.joyAssign[i].pov[ii].direction[povs[ii] / 4500].GetCallback(pinkyStatus);

                        string direction = deviceControl.joyAssign[i].pov[ii].GetDirection(povs[ii]);
                        Label_AssgnStatus.Content = "POV" + (ii + 1) + "." + direction + "\t: " + deviceControl.joyAssign[i].GetProductName();
                    }
                }
                break;
            }
            if (target == "")
            {
                return;
            }
            if (target == "SimDoNothing")
            {
                return;
            }
            // If the key assignment was found, jump to the mapping for it and highlight it.
            KeyAssgn key = keyFile.keyAssign.FirstOrDefault(x => x.GetCallback() == target);

            if (key != null)
            {
                Label_AssgnStatus.Content += "   / " + key.Mapping;

                KeyMappingGrid.ScrollIntoView(key);
                KeyMappingGrid.SelectedIndex = KeyMappingGrid.Items.IndexOf(key);
            }
        }