C# // SendKeys.SendWait works only when process'es window is minimzed

杀马特。学长 韩版系。学妹 提交于 2019-11-29 05:07:16

Try using the SetForegroundWindow Win32 API call, instead of ShowWindow, to activate the game window. (Signature from pinvoke.net.)

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

static void Main(string[] args)
{
    Process[] processes = Process.GetProcessesByName("game");
    Process game1 = processes[0];

    IntPtr p = game1.MainWindowHandle;

    SetForegroundWindow(p);
    SendKeys.SendWait("{DOWN}");
    Thread.Sleep(1000);
    SendKeys.SendWait("{DOWN}");
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!