How to send keys to specified app with title?

Posted by Ishan7 under C# on 2/16/2021 | Points: 10 | Views : 503 | Status : [Member] | Replies : 1
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);

public static void Test()
{
IntPtr zero = IntPtr.Zero;
for (int i = 0; (i < 60) && (zero == IntPtr.Zero); i++)
{
zero = FindWindow(null, "Minecraft 1.8.8");
}
if (zero != IntPtr.Zero)
{
SetForegroundWindow(zero);
SendKeys.Send("D");
SendKeys.Send("D");
SendKeys.Send("D");
SendKeys.Send("D");
SendKeys.Send("D");
SendKeys.Send("D");
SendKeys.Send("D");
SendKeys.Send("D");
SendKeys.Send("D");
SendKeys.Send("D");
SendKeys.Send("D");
}
}





Responses

Posted by: Ishan7 on: 2/22/2021 [Member] Starter | Points: 25

Up
0
Down
Try this:
 SendKeys.Send("{D}");



Ishan7, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response