How to send a key to game(process) in c#

人走茶凉 提交于 2020-12-15 04:25:33

问题


I am trying to send a key to game(process). The game window is coming foreground but key is not working. I couldn't find the problem. Here is my code;

private void timer1_Tick(object sender, EventArgs e)
    {
        Process p = Process.GetProcessesByName("League of Legends").FirstOrDefault();
        if (p != null)
        {
            IntPtr h = p.MainWindowHandle;
            SetForegroundWindow(h);
            SendKeys.SendWait("q");
        }
    }

来源:https://stackoverflow.com/questions/65263389/how-to-send-a-key-to-gameprocess-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!