Esempio n. 1
0
        /// <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)
        {
            this.KeyMappingTimer.Stop();

            var 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();

            this.KeyMappingTimer.Start();
        }
Esempio n. 2
0
        /// <summary>
        /// User has changed the text in the search box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SearchBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            KeyMappingGrid.UnselectAllCells();
            string filter = SearchBox.Text.Trim().ToLower();

            KeyMappingGrid.Items.Filter = x => String.IsNullOrWhiteSpace(filter) || ((KeyAssgn)x).Mapping.Trim().ToLower().Contains(filter);
        }
Esempio n. 3
0
        /// <summary>
        /// User has changed the text in the search box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SearchBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            KeyMappingGrid.UnselectAllCells();
            string filter        = SearchBox.Text.Trim().ToLower();
            var    isFilterEmpty = String.IsNullOrWhiteSpace(filter);

            // Enable the category selector only if there's no search filter active.
            Category.IsEnabled = isFilterEmpty;

            KeyMappingGrid.Items.Filter = x => isFilterEmpty || ((KeyAssgn)x).Mapping.Trim().ToLower().Contains(filter);
        }
        /// <summary>
        /// Something has been entered to a search box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Search_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Input.Keyboard.ClearFocus();

            if (SearchBox.Text == "")
            {
                return;
            }

            KeyMappingGrid.UnselectAllCells();
            KeyMappingGrid.ItemsSource = null;

            //if (SearchBox.Text == "")
            //{
            //    foreach (KeyAssgn Assgn in keyFile.keyAssign)
            //        Assgn.Visibility = Assgn.GetVisibility();
            //    KeyMappingGrid.Items.Refresh();
            //    KeyMappingGrid.UnselectAllCells();
            //    return;
            //}

            string target = SearchBox.Text;

            //foreach (KeyAssgn Assgn in keyFile.keyAssign)
            //{
            //    if (Assgn.Mapping.Trim().Contains(target))
            //        Assgn.Visibility = Assgn.GetVisibility();
            //    else
            //    {
            //        Assgn.Visibility = "Hidden";
            //    }
            //}

            this.KeyMappingGrid.ItemsSource = keyFile.keyAssign;
            KeyMappingGrid.Items.Refresh();

            int i = 0;

            foreach (KeyAssgn keys in keyFile.keyAssign)
            {
                if (keys.Mapping.Trim().Contains(target))
                {
                    KeyMappingGrid.ScrollIntoView(KeyMappingGrid.Items[KeyMappingGrid.Items.Count - 1]);
                    KeyMappingGrid.UpdateLayout();
                    KeyMappingGrid.ScrollIntoView(KeyMappingGrid.Items[i]);

                    return;
                }
                i += 1;
            }
        }
Esempio n. 5
0
        /// <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)
        {
            var selectedItem = (KeyAssgn)KeyMappingGrid.SelectedItem;

            KeyMappingGrid.ScrollIntoView(selectedItem);

            if (KeyMappingGrid.CurrentColumn == null)
            {
                return;
            }
            int Rows    = KeyMappingGrid.SelectedIndex;
            int Columns = KeyMappingGrid.CurrentColumn.DisplayIndex;

            if (Columns == 1)
            {
                if (Rows < 0)
                {
                    return;
                }
                if (selectedItem.Visibility != "White")
                {
                    return;
                }

                selectedItem.UnassignKeyboard();
            }
            if (Columns > 1)
            {
                if (Rows < 0)
                {
                    return;
                }
                string target = selectedItem.GetCallback();
                deviceControl.joyAssign[Columns - 3].UnassigntargetCallback(target);
            }
            KeyMappingGrid.Items.Refresh();
            KeyMappingGrid.UnselectAllCells();
            statusSearch = Search.Search;
        }
Esempio n. 6
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;
        }
Esempio n. 7
0
        /// <summary>
        /// Check your keyboard/joysticks button behaviour every 60 frames per seconds.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void KeyMappingTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                directInputDevice.GetCurrentKeyboardState();
                for (int i = 1; i < 238; i++)
                {
                    if (directInputDevice.KeyboardState[(Microsoft.DirectX.DirectInput.Key)i])
                    {
                        KeyMappingGrid_KeyDown();
                    }
                }

                int Rows         = KeyMappingGrid.SelectedIndex;
                var selectedItem = (KeyAssgn)KeyMappingGrid.SelectedItem;

                if (Rows == -1 || statusSearch == Search.Search)
                {
                    JumptoAssignedKey();
                    return;
                }
                if (KeyMappingGrid.CurrentColumn == null)
                {
                    return;
                }
                if (selectedItem.GetVisibility() != "White")
                {
                    return;
                }


                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] == neutralButtons[i].buttons[ii])
                            {
                                continue;
                            }
                            statusAssign = Status.GetNeutralPos;
                            if (buttons[ii] == 0)
                            {
                                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;
                            }

                            // Construct DX button instance.
                            if (selectedItem.GetCallback() == "SimHotasPinkyShift")
                            {
                                deviceControl.joyAssign[i].dx[ii].Assign(selectedItem.GetCallback(), Pinky.UnShift, Behaviour.Press, Invoke.Default, 0);
                                deviceControl.joyAssign[i].dx[ii].Assign(selectedItem.GetCallback(), Pinky.Shift, Behaviour.Press, Invoke.Default, 0);
                            }
                            else
                            {
                                deviceControl.joyAssign[i].dx[ii].Assign(selectedItem.GetCallback(), pinkyStatus, behaviourStatus, invokeStatus, 0);
                            }

                            KeyMappingGrid.Items.Refresh();
                            KeyMappingGrid.UnselectAllCells();
                        }
                        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;
                            }

                            // Construct POV button instance.
                            deviceControl.joyAssign[i].pov[ii].Assign(povs[ii], selectedItem.GetCallback(), pinkyStatus, 0);

                            KeyMappingGrid.Items.Refresh();
                            KeyMappingGrid.UnselectAllCells();
                        }
                    }
                    break;
                }
            }
            catch (System.IO.FileNotFoundException ex)
            {
                System.Console.WriteLine(ex.Message);

                System.IO.StreamWriter sw = new System.IO.StreamWriter(appReg.GetInstallDir() + "\\Error.txt", false, System.Text.Encoding.GetEncoding("shift_jis"));
                sw.Write(ex.Message);
                sw.Close();

                MessageBox.Show("Error Log Saved To " + appReg.GetInstallDir() + "\\Error.txt", "WARNING", MessageBoxButton.OK, MessageBoxImage.Information);

                this.Close();
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Unfocus a Datagrid cell and KeyMapping page backs to search mode.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void KeyMappingGrid_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
 {
     KeyMappingGrid.UnselectAllCells();
     statusSearch = Search.Search;
     Label_AssgnStatus.Content = "KEYSEARCH MODE";
 }
        /// <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;
        }
        /// <summary>
        /// Check your keyboard/joysticks button behaviour every 60 frames per seconds.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void KeyMappingTimer_Tick(object sender, EventArgs e)
        {
            directInputDevice.GetCurrentKeyboardState();
            for (int i = 1; i < 238; i++)
            {
                if (directInputDevice.KeyboardState[(Microsoft.DirectX.DirectInput.Key)i])
                {
                    KeyMappingGrid_KeyDown();
                }
            }

            int Rows = KeyMappingGrid.SelectedIndex;

            if (Rows == -1 | statusSearch == Search.Search)
            {
                JumptoAssignedKey();
                return;
            }
            if (KeyMappingGrid.CurrentColumn == null)
            {
                return;
            }
            if (keyFile.keyAssign[Rows].GetVisibility() != "White")
            {
                return;
            }


            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] == neutralButtons[i].buttons[ii])
                        {
                            continue;
                        }
                        statusAssign = Status.GetNeutralPos;
                        if (buttons[ii] == 0)
                        {
                            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;
                        }

                        // Construct DX button instance.
                        deviceControl.joyAssign[i].dx[ii].Assign(keyFile.keyAssign[Rows].GetCallback(), pinkyStatus, behaviourStatus, invokeStatus, 0);

                        KeyMappingGrid.Items.Refresh();
                        KeyMappingGrid.UnselectAllCells();
                    }
                    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;
                        }

                        // Construct POV button instance.
                        deviceControl.joyAssign[i].pov[ii].Assign(povs[ii], keyFile.keyAssign[Rows].GetCallback(), pinkyStatus, 0);

                        KeyMappingGrid.Items.Refresh();
                        KeyMappingGrid.UnselectAllCells();
                    }
                }
                break;
            }
        }