Search code examples
c#automationmouseclick

How to Set mouse cursor position to a specified point on screen in C#?


How to Set mouse cursor position to a specified point on screen in C#?

am i must hacke the motherboard buffer that receive the mouse and keyboard coordinates and presses ???

is there another one to do clicks or i am imagine ???


Solution

  • Get and set mouse position in Windows 10:

    Much simpler in c# .NET Framework 4.0 using Cursor.Position Property

    https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.cursor.position?view=netcore-3.1

        public static void ClickSomePoint()
        {
    
            // get mouse position
            System.Drawing.Point screenPos = System.Windows.Forms.Cursor.Position;
    
            // create X,Y point (0,0) explicitly with System.Drawing 
            System.Drawing.Point leftTop = new System.Drawing.Point(0,0);
    
            // set mouse position
            Cursor.Position = leftTop; 
            Console.WriteLine(screenPos);
        }