/// <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); }
/// <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(); }
/// <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; } }
/// <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; }
/// <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 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] == 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; } // If the key assignment was found, jump to the mapping for it and highlight it. var 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); } }
/// <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> /// 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(); } }
/// <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> /// 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; } } }
/// <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; } }
/// <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.joyAssign.Length; i++) { neutralButtons[i] = new NeutralButtons(deviceControl.joyAssign[i]); } statusAssign = Status.WaitingforInput; break; case Status.WaitingforInput: for (int i = 0; i < deviceControl.joyAssign.Length; i++) { buttons = deviceControl.joyAssign[i].GetButtons(); for (int ii = 0; ii < CommonConstants.DX128; ii++) { if (buttons[ii] == CommonConstants.PRS128 && deviceControl.joyAssign[i].dx[ii].assign[CommonConstants.DX_PRESS].GetCallback() == "SimHotasPinkyShift" && pressedByHand == false) { Select_PinkyShift.IsChecked = false; } if (buttons[ii] == CommonConstants.PRS0 && deviceControl.joyAssign[i].dx[ii].assign[CommonConstants.DX_PRESS].GetCallback() == "SimHotasPinkyShift" && pressedByHand == false) { Select_PinkyShift.IsChecked = true; } if (neutralButtons[i] == null) { break; // KEY SEARCH WILL NOT WORK IF ENTER HERE } if (buttons[ii] == neutralButtons[i].buttons[ii]) { continue; } statusAssign = Status.GetNeutralPos; if (buttons[ii] == CommonConstants.PRS0) // RELEASE SHIFT { Select_DX_Release.IsChecked = false; } else { Select_DX_Release.IsChecked = true; } if (deviceControl.joyAssign[i].dx[ii].assign[CommonConstants.DX_PRESS].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.joyAssign[i].GetPointOfView(); for (int ii = 0; ii < 4; ii++) { if (neutralButtons[i] == null) { break; // KEY SEARCH WILL NOT WORK IF ENTER HERE } 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] / CommonConstants.POV45].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); } }