private void OnKeyPressed(GlobalKeyPressed obj) { if (currentShortcutWindow != null) { switch (obj.Key) { case 0x0000001B: //Escape obj.ProcessKey = false; CloseShortcutWindow(); break; case 0x00000028: //Down shortcutViewModel?.IncrementSelection(1); break; case 0x00000026: //Up shortcutViewModel?.IncrementSelection(-1); break; case 0x0000000D: //Enter obj.ProcessKey = false; //If the current shortcut window is open and doesn't have args, then execute it if (currentShortcutWindow != null) { isPasting = true; var selectedItem = shortcutViewModel.SelectedItem; CloseShortcutWindow(); Clipboard.SetDataObject(selectedItem); Thread.Sleep(5); System.Windows.Forms.SendKeys.SendWait("^{v}"); Console.WriteLine("PASTED FROM SHORTCUT WINDOW!!!!"); isPasting = false; } break; } } else if (Keyboard.Modifiers == (ModifierKeys.Shift | ModifierKeys.Control) && obj.Key == (int)System.Windows.Forms.Keys.V) { currentShortcutWindow = new ShortcutWindow(); currentShortcutWindow.DataContext = shortcutViewModel; currentShortcutWindow.Show(); currentShortcutWindow.Activate(); obj.ProcessKey = false; //Don't process key in order to avoid pasting } //if (Keyboard.Modifiers == (ModifierKeys.Control) && obj.Key == (int)System.Windows.Forms.Keys.V && isPasting) //{ // //currentShortcutWindow = new ShortcutWindow(); // //currentShortcutWindow.DataContext = shortcutViewModel; // //currentShortcutWindow.Show(); // //currentShortcutWindow.Activate(); // Console.WriteLine("PASTED FROM KEYBOARD!!"); // obj.ProcessKey = false; //Don't process key in order to avoid pasting //} }
private void CloseShortcutWindow() { shortcutViewModel.Reset(); currentShortcutWindow?.Close(); currentShortcutWindow = null; }
private void OnKeyPressed(GlobalKeyPressed obj) { if (currentShortcutWindow != null || currentArgumentsWindow != null) { switch (obj.Key) { case 0x0000001B: //Escape obj.ProcessKey = false; CloseShortcutWindow(); CloseArgumentWindow(); break; case 0x00000028: //Down shortcutViewModel?.IncrementSelection(1); break; case 0x00000026: //Up shortcutViewModel?.IncrementSelection(-1); break; case 0x0000000D: //Enter obj.ProcessKey = false; //If the current shortcut window is open and doesn't have args, then execute it if (currentShortcutWindow != null && !IsArgumentShortcut()) { shortcutViewModel.ExecuteSelection(); CloseShortcutWindow(); break; } //If the arg window is open and it's not filled out then open the arg window if (currentArgumentsWindow != null && IsArgumentShortcut() && !IsArgumentShortcutFilled()) { argumentsViewModel.ExecuteArgument(); var command = argumentsViewModel.Command; var arguments = GetArgs(); CloseArgumentWindow(); if (arguments.Count() <= shortcutExecutor.Arguments.Count) { shortcutExecutor.Execute(command.Title, command); break; } var argumentKey = arguments.ElementAt(shortcutExecutor.Arguments.Count); argumentsViewModel.Command = command; argumentsViewModel.ArgumentKey = argumentKey; if (IsArgumentShortcutFilled()) { break; } OpenArgumentWindow(); } //If the shortcut window is open and it has args, then open the arg window if (currentShortcutWindow != null && IsArgumentShortcut() && !IsArgumentShortcutFilled()) { var command = shortcutViewModel.SelectedItem.Value; var argumentKey = GetArgs().ElementAt(shortcutExecutor.Arguments.Count); CloseShortcutWindow(); argumentsViewModel.Command = command; argumentsViewModel.ArgumentKey = argumentKey; OpenArgumentWindow(); break; } //if the arg window is open and it's filled out, then execute the shortcut if (currentArgumentsWindow != null && IsArgumentShortcut() && IsArgumentShortcutFilled()) { argumentsViewModel.Execute(); CloseArgumentWindow(); break; } break; } } else if (Keyboard.Modifiers == (settingsViewModel.Modifier1 | settingsViewModel.Modifier2) && obj.Key == (int)settingsViewModel.Key) //Space { currentShortcutWindow = new ShortcutWindow(); currentShortcutWindow.DataContext = shortcutViewModel; currentShortcutWindow.Show(); currentShortcutWindow.Activate(); obj.ProcessKey = false; shortcutViewModel.Reset(); } }