0

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");
        }
    }
tester01
  • 116
  • 2
  • 10
  • Does this answer your question? [C# using Sendkey function to send a key to another application](https://stackoverflow.com/questions/15292175/c-sharp-using-sendkey-function-to-send-a-key-to-another-application) –  Dec 12 '20 at 09:40
  • "Pseudo-duplicate" of [how to press the key from the keyboard in c#](https://stackoverflow.com/questions/65262523/how-to-press-the-key-from-the-keyboard-in-c-sharp) –  Dec 12 '20 at 09:40
  • Please, don't post twice a question: you should delete (or why not edit) the previous if very different and inaccurate. –  Dec 12 '20 at 09:42
  • i examined this page that you send me but it didnt solve my problem. I couldnt find the problem. Could you help me what is the problem in this code why doesnt work i didnt understand. – tester01 Dec 12 '20 at 09:48
  • Actually, it is working for notepad but it is not working for this process. – tester01 Dec 12 '20 at 09:51

0 Answers0