// https://www.codeproject.com/Tips/76427/How-to-bring-window-to-top-with-SetForegroundWindo // https://www.cnblogs.com/rosesmall/p/5759804.html // https://blog.csdn.net/chengjunlin0793/article/details/49950387 public static void SetForegroundWindowInternal(IntPtr hWnd) { if (!SetForegroundWindow(hWnd)) { KeyboardSend.Alt_KEYEVENTF_EXTENDEDKEY(); SetForegroundWindow(hWnd); KeyboardSend.Alt_KEYEVENTF_KEYUP(); } }
public static void Launch(string query) { KeyboardSend.KeyDown(KeyboardSend.LWin); if (WindowsRuntimeHelper.IsWindows8()) { KeyboardSend.KeyPress((byte)'S'); } KeyboardSend.KeyUp(KeyboardSend.LWin); if (string.IsNullOrEmpty(query)) { return; } Thread.Sleep(100); var keysToSend = query.Trim().Select(char.ToUpper).Where(OnlyValidWindowsSearchCharacters); foreach (var uc in keysToSend) { KeyboardSend.KeyPress((byte)uc); } }