Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7999715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:34:58+00:00 2026-06-04T15:34:58+00:00

I am trying to send a simulated mouse click to another application. I understand

  • 0

I am trying to send a simulated mouse click to another application. I understand how to actually send the key click, this is not the issue. I need to send the mouse click to the very center of the other application. I can simply test it once and find out the coordinate and send the click to that XY location, but there is an issue… When I move the window, or resize this window the XY coordinates will obviously not be the same.

So I need to find out how to get the size of the window, and its location and then find the center point from this. Anyone know how to do this? Thank you very much to any response!

Here is my code to send the mouse click

public void SendLeftClick(int x, int y)
{
    int old_x, old_y;
    old_x = Cursor.Position.X;
    old_y = Cursor.Position.Y;

    SetCursorPos(x, y);
    mouse_event(MouseEventFlag.LeftDown, x, y, 0, UIntPtr.Zero);
    mouse_event(MouseEventFlag.LeftUp, x, y, 0, UIntPtr.Zero);
    SetCursorPos(old_x, old_y);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:35:00+00:00Added an answer on June 4, 2026 at 3:35 pm

    You can use the GetWindowInfo API:

        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError = true)]
        private static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi);
    
        [StructLayout(LayoutKind.Sequential)]
        struct WINDOWINFO
        {
            public uint cbSize;
            public RECT rcWindow;
            public RECT rcClient;
            public uint dwStyle;
            public uint dwExStyle;
            public uint dwWindowStatus;
            public uint cxWindowBorders;
            public uint cyWindowBorders;
            public ushort atomWindowType;
            public ushort wCreatorVersion;
    
            public WINDOWINFO(Boolean? filler)
                : this()   // Allows automatic initialization of "cbSize" with "new WINDOWINFO(null/true/false)".
            {
                cbSize = (UInt32)(Marshal.SizeOf(typeof(WINDOWINFO)));
            }
    
        }
        [StructLayout(LayoutKind.Sequential)]
        struct RECT
        {
            public int left, top, right, bottom;
        }
    
    
        private void button1_Click_1(object sender, EventArgs e)
        {
            var p = System.Diagnostics.Process.GetProcessesByName("mspaint");
    
            if (p.Length == 0) return;
    
            WINDOWINFO wi = new WINDOWINFO(false);
            GetWindowInfo(p[0].MainWindowHandle, ref wi);
    
            SendLeftClick((wi.rcWindow.left + wi.rcWindow.right) / 2, (wi.rcWindow.top + wi.rcWindow.bottom) / 2);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send some simple mouse down/up messages to Windows Calculator using
I need to interact with an external application running, and send specific keypresses &
Im trying to send a Docx file via this form that I made, the
I need to send an application to someone before submitting it to the app
Im trying to send a mail from a asp.net script, but im getting this
I'm trying to simulate a mouse click on a window. I currently have success
I am trying the following: // Key to send var key = Key.F2; //
I am trying to send a post request through ajax to another domain and
Trying to send some email in my C# app. I am behind a proxy
Trying to send a complex type between two systems that have the same code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.