问题
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