I\'m trying to create a program that will be able to control another program (in Windows).
I found this code:
// Get a handle to an application window.
[
You can use the following code to simulate mouse click:
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool SetCursorPos(int x, int y);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
public const int MOUSE_LEFTDOWN = 0x02;
public const int MOUSE_LEFTUP = 0x04;
public static void LeftMouseClick(int x, int y)
{
SetCursorPos(x, y);
mouse_event(MOUSE_LEFTDOWN, x, y, 0, 0);
mouse_event(MOUSE_LEFTUP, x, y, 0, 0);
}
Method LeftMouseClick
is getting two parameters x and y representing coordinates on user screen:
LeftMouseClick(400, 200);
Or you can do it by keyboard: Link
private void button2_Click(object sender, EventArgs e)
{
SendKeys.Send("{ENTER}");
}
basically that's what you are doing in your code:
SendKeys.SendWait("111");
SendKeys.SendWait("*");
SendKeys.SendWait("11");
SendKeys.SendWait("=");
I dont think there is another way of doing this.
You may find the answer in other posts:
programmatically mouse click in another window
or
Send mouse clicks to X Y coordinate of another application
I hope they help.