public static void WindowsWindowCreatedHook(IntPtr handle) { var windowName = WinApiProxy.GetWindowText(handle); if (string.IsNullOrEmpty(windowName)) { return; } Debug.WriteLine($"Window Created = {windowName}"); var names = QuickTypeCommandManager.Instance.AutoKillWindowNames(); if (names.Any(x => x.Item1 == windowName)) { var command = names.First(x => x.Item1 == windowName); var keys = command.Item2; if (!string.IsNullOrEmpty(keys)) { WinApiProxy.SetForegroundWindow(handle); SendKeys.SendWait(keys); } else { WinApiProxy.CloseWindow(handle); } } }
public static IntPtr WindowsKeyHookCallback(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { const int WM_HOTKEY = 0x0312; switch (msg) { case WM_HOTKEY: switch (wParam.ToInt32()) { case KeyHookConstants.HOTKEY_ID: { if (View.IsVisible) { View.Hide(); break; } else { (View.DataContext as QuickTypeViewModel).LastFocusedWindow = WinApiProxy.GetForegroundWindow(); View.Show(); WinApiProxy.SetForegroundWindow(View.Handle); break; } } } break; } return(IntPtr.Zero); }
public static List <QueryResult> KeyboardShortcutsProvider(IntPtr window, List <SingleCommand> cmd) { return(cmd.Select(x => new QueryResult() { Data = () => { WinApiProxy.SetForegroundWindow(window); SendKeys.SendWait(x.Keys); }, Name = x.Name }).OrderBy(x => x.Name).ToList()); }
public static List <QueryResult> ProcessShortcutsCreator(List <SingleCommand> commands, string filter) { var cmd = commands; if (!string.IsNullOrEmpty(filter)) { cmd = cmd.Where(x => x.WindowContext == filter).ToList(); } return(cmd.Select(x => new QueryResult() { Data = () => { try { var expanded = (Environment.ExpandEnvironmentVariables(x.Parameter)); if (!string.IsNullOrEmpty(x.Additional)) { var args = QuickTypeEvnVariables.Resolve(x.Additional, QuickTypeCommandManager.Instance.WindowFocus, x.VisualStudioContext); var process = Process.Start($"{expanded}", $"{args}"); if (process != null) { WinApiProxy.SetForegroundWindow(process.Handle); } } else { var process = Process.Start($"{expanded}"); if (process != null) { WinApiProxy.SetForegroundWindow(process.Handle); } } } catch (Exception ex) { MessageBox.Show($"{ex.Message}\n{ex?.InnerException?.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }, Name = x.Name }).OrderBy(x => x.Name).ToList()); }