How to perform mouse event in c#? where is the probleme here

I’m trying do do three mousclicks in my c# programm.
I found this on the internet: https://forum.chip.de/discussion/1668318/visual-studio-c-2010-mausklick-simulieren

So I’ve tried this, but for me nothing is happening.

        private const UInt32 MouseEventLeftUp = 0x0004;
        [DllImport("user32", EntryPoint = "mouse_event")]
        private static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, IntPtr dwExtraInfo);

And here the mousclicks i’m trying

                Console.WriteLine(DateTime.Now + " Vollbild");
                mouse_event(MouseEventLeftDown, 1700, 1138, 0, new System.IntPtr());
                mouse_event(MouseEventLeftUp, 1700, 1138, 0, new System.IntPtr());
                Thread.Sleep(2000);
                // OEE
                Console.WriteLine(DateTime.Now + " OEE");
                mouse_event(MouseEventLeftDown, 1470, 380, 0, new System.IntPtr());
                mouse_event(MouseEventLeftUp, 1470, 380, 0, new System.IntPtr());
                Thread.Sleep(15000);
                //Astronic
                Console.WriteLine(DateTime.Now + " Astronic");
                mouse_event(MouseEventLeftDown, 220, 370, 0, new System.IntPtr());
                mouse_event(MouseEventLeftUp, 220, 370, 0, new System.IntPtr());

Anyone have a idea where is the problem here

>Solution :

If you were to move mouse to the position of (1700, 1138) then click, try this instead:

 mouse_event(0x0001, 1700, 1138, 0, new IntPtr(0))
 mouse_event(MouseEventLeftDown, 0, 0, 0, new System.IntPtr(0))
 mouse_event(MouseEventLeftUp, 0, 0, 0, new System.IntPtr(0))

Leave a Reply