I am trying to programatically simulate a left button mouse click:
[DllImport("user32.dll")]
static extern bool SetCursorPos(int x, int y);
[DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
public const int MOUSEEVENTF_LEFTDOWN = 0x02;
public const int MOUSEEVENTF_LEFTUP = 0x04;
public static void LeftMouseClick(int xpos, int ypos)
{
SetCursorPos(xpos, ypos);
mouse_event(MOUSEEVENTF_LEFTDOWN, xpos, ypos, 0, 0);
System.Threading.Thread.Sleep(1000);
mouse_event(MOUSEEVENTF_LEFTUP, xpos, ypos, 0, 0);
}
The cursor moves to the appropriate position on the screen, but the click is not firing there. Any thoughts?
EDIT: I did a couple of tests. The method i use does not seem to be the issue (it clicks on applications like steam, skype successfully). When calling the click method when the cursor is above the application that i specifically want to click on (an android emulator) nothing happens. The mouse cursor moves to the spot but wont click... Going to test another emulator now.