private static void SetTargetProcess(InputAction action) { var process = WinUtils.GetProcessByName(action.ProcessName); if (process == null) { return; } Sender.SetCurrentProcessTarget(process.MainWindowHandle); if (action.BringProcessToForeground) { WindowsApi.SetForegroundWindow(process.MainWindowHandle); } WindowsApi.SetFocus(process.MainWindowHandle); }
public static void SetTargetProcess(string name, bool f) { var process = WinUtils.GetProcessByName(name); if (process == null) { return; } Sender.SetCurrentProcessTarget(process.MainWindowHandle); if (f) { WindowsApi.SetForegroundWindow(process.MainWindowHandle); } WindowsApi.SetFocus(process.MainWindowHandle); }
private static void SetTargetProcess(InputActionExecutionContainer container) { var hasProcess = false; if (container.UseForegroundWindow) { var ptr = WindowsApi.GetForegroundWindow(); if (ptr != IntPtr.Zero) { WindowsApi.SetFocus(ptr); Sender.SetCurrentProcessTarget(ptr); hasProcess = true; } } if (!hasProcess && container.UseDesktop) { var ptr = WindowsApi.GetDesktopWindow(); if (ptr != IntPtr.Zero) { WindowsApi.SetForegroundWindow(ptr); WindowsApi.SetFocus(ptr); Sender.SetCurrentProcessTarget(ptr); hasProcess = true; } } if (hasProcess || string.IsNullOrEmpty(container.ProcessName)) { return; } var process = WinUtils.GetProcessByName(container.ProcessName); if (process == null) { return; } Sender.SetCurrentProcessTarget(process.MainWindowHandle); WindowsApi.SetForegroundWindow(process.MainWindowHandle); WindowsApi.SetFocus(process.MainWindowHandle); }