/// <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; } }
/// <summary> /// Let's jump to a category you have selected. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Category_SelectionChanged(object sender, SelectionChangedEventArgs e) { string target = ""; switch (Category.SelectedIndex) { case 0: target = "BMS - Full"; break; case 1: target = "1. UI & 3RD PARTY SOFTWARE"; break; case 2: target = "2. LEFT CONSOLE"; break; case 3: target = "======== 2.19 THROTTLE QUADRANT SYSTEM ========"; break; case 4: target = "3. LEFT AUX CONSOLE"; break; case 5: target = "4. CENTER CONSOLE"; break; case 6: target = "======== 4.05 LEFT MFD ========"; break; case 7: target = "======== 4.10 RIGHT MFD ========"; break; case 8: target = "5. RIGHT CONSOLE"; break; case 9: target = "======== 5.11 FLIGHT STICK ========"; break; case 10: target = "6. MISCELLANEOUS"; break; case 11: target = "7. VIEWS"; break; case 12: target = "8. RADIO COMMS"; break; } int i = 0; foreach (KeyAssgn keys in keyFile.keyAssign) { if (keys.Mapping.Trim() == target) { KeyMappingGrid.ScrollIntoView(KeyMappingGrid.Items[KeyMappingGrid.Items.Count - 1]); KeyMappingGrid.UpdateLayout(); KeyMappingGrid.ScrollIntoView(KeyMappingGrid.Items[i]); } i += 1; } }
/// <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); } }
/// <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; }
/// <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(); //Microsoft.DirectX.DirectInput.InputLostException: 'アプリケーションでエラーが発生しました。' for (int ii = 0; ii < 32; ii++) { if (buttons[ii] == neutralButtons[i].buttons[ii]) { continue; } statusAssign = Status.GetNeutralPos; if (buttons[ii] == 0) // RELEASE SHIFT { 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(); 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; } for (int i = 0; i < keyFile.keyAssign.Length; i++) { if (keyFile.keyAssign[i].GetCallback() == target) { Label_AssgnStatus.Content += " / " + keyFile.keyAssign[i].Mapping; KeyMappingGrid.UpdateLayout(); KeyMappingGrid.ScrollIntoView(KeyMappingGrid.Items[i]); KeyMappingGrid.SelectedIndex = i; statusSearch = Search.Search; } } }