2016-08-05 55 views
-2

Ich versuchte How to simulate Mouse Click in C#?Simulieren Mausklick - Maus nicht bewegt

public void DoMouseClick(uint X, uint Y) 
    { 
     //Call the imported function with the cursor's current position 
     mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0); 
    } 

Mein Problem ist, dass der Klick auf diesen Punkt ausgeführt habe, mein Cursor ist und nicht an diesem Punkt, habe ich für x und y. Meine Koordinaten sind nicht falsch. Ich habe es auch mit x = 1 und y = 1 versucht.

Antwort

1
[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 MOUSEEVENTF_LEFTDOWN = 0x0002;//0x02; 
    public const int MOUSEEVENTF_LEFTUP = 0x0004;//0x04; 

    public void Click(int x, int y) 
    { 
     Thread.Sleep(2000); 
     SetCursorPos(x, y); 
     Thread.Sleep(1000); 
     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); 
     Thread.Sleep(1000); 
     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); 
    } 
+0

SetCursorPos (x, y); hat funktioniert. Ich danke dir sehr! – ElDiabolo