/// <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();
        }
Example #2
0
        /// <summary>
        /// Write Joy Assignment Status to KeyMappingGridCell.
        /// </summary>
        public string KeyMappingPreviewPOV(KeyAssgn keyAssign)
        {
            string result;

            result = "";

            for (int i = 0; i < this.pov.Length; i++)
            {
                for (int ii = 0; ii < this.pov[i].direction.Length; ii++)
                {
                    string direction = this.pov[i].GetDirection(ii);
                    for (int iii = 0; iii < 2; iii++)
                    {
                        if (this.pov[i].direction[ii].GetCallback((Pinky)iii) == "SimDoNothing")
                        {
                            continue;
                        }
                        if (keyAssign.GetCallback() != this.pov[i].direction[ii].GetCallback((Pinky)iii))
                        {
                            continue;
                        }
                        if (result != "")
                        {
                            result += "\n";
                        }
                        result += " POV" + (i + 1) + "." + direction;
                        if (iii == 1) //PRESS + SHIFT
                        {
                            result += " SHFT";
                        }
                    }
                }
            }
            return(result);
        }
Example #3
0
 public void getOtherKeyInstance(KeyAssgn otherInstance)
 {
     this.callback    = otherInstance.callback;
     this.soundID     = otherInstance.soundID;
     this.none        = otherInstance.none;
     this.keyboard    = otherInstance.keyboard;
     this.modifier    = otherInstance.modifier;
     this.keycombo    = otherInstance.keycombo;
     this.keycomboMod = otherInstance.keycomboMod;
     this.visibility  = otherInstance.visibility;
     this.description = otherInstance.description;
 }
Example #4
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();
        }
Example #5
0
        /// <summary>
        /// Write Joy Assignment Status to KeyMappingGridCell.
        /// </summary>
        public string KeyMappingPreviewDX(KeyAssgn keyAssign)
        {
            string result;

            result = "";

            for (int i = 0; i < this.dx.Length; i++)
            {
                for (int ii = 0; ii < this.dx[i].assign.Length; ii++)
                {
                    if (this.dx[i].assign[ii].GetCallback() == "SimDoNothing")
                    {
                        continue;
                    }
                    if (keyAssign.GetCallback() != this.dx[i].assign[ii].GetCallback())
                    {
                        continue;
                    }
                    if (result != "")
                    {
                        result += "\n";
                    }
                    result += " DX" + (i + 1);
                    if (ii == 1) //PRESS + SHIFT
                    {
                        result += " SHFT";
                    }
                    if (ii == 2) //RELEASE
                    {
                        result += " REL";
                    }
                    if (ii == 3) //RELEASE + SHIFT
                    {
                        result += " REL SHFT";
                    }
                    if (this.dx[i].assign[ii].GetInvoke() == Invoke.Down)
                    {
                        result += " INV: DN";
                    }
                    if (this.dx[i].assign[ii].GetInvoke() == Invoke.Up)
                    {
                        result += " INV: UP";
                    }
                }
            }
            return(result);
        }
Example #6
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();
        }
Example #7
0
        public KeyFile(string Filename, AppRegInfo appReg)
        {
            string stParentName = Path.GetDirectoryName(Filename);

            // Do BMS - FULL.key file exists at User/Config?
            if (File.Exists(Filename) == false)
            {
                MessageBoxResult result = MessageBox.Show
                                              ("App could not find " + Filename, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            string[] lines = File.ReadAllLines(Filename, Encoding.UTF8);

            keyAssign = new KeyAssgn[lines.Length];

            int i = -1;

            foreach (string stBuffer in lines)
            {
                string[] stArrayData = stBuffer.Split(' ');

                if (stArrayData.Length < 7)
                {
                    continue;
                }
                if (stBuffer.Substring(0, 1) == "#")
                {
                    continue;
                }
                if (stArrayData[3] == "-2" | stArrayData[3] == "-3")
                {
                    continue;
                }

                // Okay now this line is confirmed to be a line that shows keyboard assignment.

                i           += 1;
                keyAssign[i] = new KeyAssgn(stBuffer);

                // What if the line format was broken?

                if (keyAssign[i].CheckFileCollapsing() == false)
                {
                    continue;
                }

                MessageBoxResult result = MessageBox.Show
                                              ("App found " + appReg.getKeyFileName() + " broken\nWould you like to restore it to the default?", "Error", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);
                if (result == MessageBoxResult.OK)
                {
                    string fnamestock = appReg.GetInstallDir() + "\\Docs\\Key Files & Input\\" + appReg.getKeyFileName();
                    string fname      = appReg.GetInstallDir() + "\\User\\Config\\" + appReg.getKeyFileName();;
                    if (File.Exists(fnamestock))
                    {
                        File.Copy(fnamestock, fname, true);
                        Application.Current.Shutdown();
                        System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);
                        return;
                    }
                    MessageBox.Show("App could not find " + appReg.getKeyFileName() + " at\nDocs\\Key Files & Input\\", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    Application.Current.Shutdown();
                    return;
                }
                Application.Current.Shutdown();
                return;
            }
            Array.Resize(ref keyAssign, i + 1);
        }
Example #8
0
        /// <summary>
        /// You pressed keyboard keys? I will check which key was pressed with Shift/Ctrl/Alt.
        /// </summary>
        private void KeyMappingGrid_KeyDown()
        {
            if (SearchBox.IsSelectionActive == true)
            {
                return;
            }
            if (SearchBox.IsFocused == true)
            {
                return;
            }
            if (SearchBox.IsKeyboardFocused == true)
            {
                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.
            var 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);
            }
        }
Example #9
0
        /// <summary>
        /// You pressed keyboard keys? I will check which key was pressed with Shift/Ctrl/Alt.
        /// </summary>
        private void KeyMappingGrid_KeyDown()
        {
            if (currentIndex < 0)
            {
                currentIndex = 1;
                statusSearch = Search.Search;
                return;
            }
            if (SearchBox.IsSelectionActive == true)
            {
                return;
            }
            if (SearchBox.IsFocused == true)
            {
                return;
            }
            if (SearchBox.IsKeyboardFocused == true)
            {
                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 (statusSearch == Search.Search)
            {
                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.
                var 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);
                }

                return;
            }
            if (KeyMappingGrid.SelectedIndex == -1)
            {
                return;
            }

            var selectedItem = (KeyAssgn)KeyMappingGrid.SelectedItem;

            if (selectedItem.Visibility != "White")
            {
                return;
            }

            Pinky pinkyStatus = Pinky.UnShift;

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

            KeyMappingGrid.ScrollIntoView(selectedItem);
            KeyMappingGrid.SelectedIndex = currentIndex;

            if (pinkyStatus == Pinky.UnShift)
            {
                selectedItem.SetKeyboard(catchedScanCode, Shift, Ctrl, Alt);
            }
            if (pinkyStatus == Pinky.Shift)
            {
                selectedItem.Setkeycombo(catchedScanCode, Shift, Ctrl, Alt);
            }

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

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

            KeyMappingGrid.Items.Refresh();
            KeyMappingGrid.UnselectAllCells();
            statusSearch = Search.Search;
        }
        /// <summary>
        /// You pressed keyboard keys? I will check which key was pressed with Shift/Ctrl/Alt.
        /// </summary>
        private void KeyMappingGrid_KeyDown()
        {
            if (currentIndex < 0)
            {
                currentIndex = 1;
                statusSearch = Search.Search;
                return;
            }
            if (SearchBox.IsSelectionActive == true)
            {
                return;
            }
            if (SearchBox.IsFocused == true)
            {
                return;
            }
            if (SearchBox.IsKeyboardFocused == true)
            {
                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 (statusSearch == Search.Search)
            {
                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();
                for (int i = 0; i < keyFile.keyAssign.Length; i++)
                {
                    if (keytmp.GetKeyAssignmentStatus() != keyFile.keyAssign[i].GetKeyAssignmentStatus())
                    {
                        continue;
                    }

                    Label_AssgnStatus.Content += "\t/" + keyFile.keyAssign[i].Mapping;

                    KeyMappingGrid.UpdateLayout();
                    KeyMappingGrid.ScrollIntoView(KeyMappingGrid.Items[i]);
                    KeyMappingGrid.SelectedIndex = i;
                }
                return;
            }
            if (KeyMappingGrid.SelectedIndex == -1)
            {
                return;
            }
            if (keyFile.keyAssign[currentIndex].GetVisibility() != "White")
            {
                return;
            }

            Pinky pinkyStatus = Pinky.UnShift;

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

            KeyMappingGrid.ScrollIntoView(KeyMappingGrid.Items[currentIndex]);
            KeyMappingGrid.SelectedIndex = currentIndex;
            if (pinkyStatus == Pinky.UnShift)
            {
                keyFile.keyAssign[currentIndex].SetKeyboard(catchedScanCode, Shift, Ctrl, Alt);
            }
            if (pinkyStatus == Pinky.Shift)
            {
                keyFile.keyAssign[currentIndex].Setkeycombo(catchedScanCode, Shift, Ctrl, Alt);
            }

            for (int i = 0; i < keyFile.keyAssign.Length; i++)
            {
                if (keyFile.keyAssign[i].GetKeyAssignmentStatus() != keyFile.keyAssign[currentIndex].GetKeyAssignmentStatus())
                {
                    continue;
                }
                if (i == currentIndex)
                {
                    continue;
                }
                if (keyFile.keyAssign[i].GetVisibility() != "White")
                {
                    continue;
                }
                keyFile.keyAssign[i].UnassignKeyboard();
            }

            KeyMappingGrid.Items.Refresh();
            KeyMappingGrid.UnselectAllCells();
            statusSearch = Search.Search;
        }
Example #11
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 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);
            }
        }