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 7857211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:58:00+00:00 2026-06-02T20:58:00+00:00

Is it possible to click programmatically a location in another window without moving the

  • 0

Is it possible to click programmatically a location in another window without moving the mouse to that location and even if the window is not on-top? I want to send a kind of message to another window to simulate a mouse click on a location.

I tried to accomplish this with PostMessage:

PostMessage(WindowHandle, 0x201, IntPtr.Zero, CreateLParam(300,300));
PostMessage(WindowHandle, 0x202, IntPtr.Zero, CreateLParam(300,300));

I made the CreateLParam function this way:

private static IntPtr CreateLParam(int LoWord, int HiWord)
{
     return (IntPtr)((HiWord << 16) | (LoWord & 0xffff));
}

The problem is that the window gets locked on his location. I think that my application clicks on the (1,1) coordinate. Can some on help me with this problem?

Edit:
This is PostMessage:

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll")]
public static extern bool PostMessage(IntPtr WindowHandle, int Msg, IntPtr wParam, IntPtr lParam);

And 0x201 and 0x202 are WM_LBUTTONDOWN and WM_LBUTTONUP respectively.

  • 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-02T20:58:02+00:00Added an answer on June 2, 2026 at 8:58 pm

    You can’t do that by sending messages, instead use SendInput Windows API.

    Call method ClickOnPoint, this is an example from form click event, so this.handle is form handle, note that these are client coordinates on window witch handle is send, you can easily change this and send screen coordinates, and in that case you don’t need handle or ClientToScreen call below.

    ClickOnPoint(this.Handle, new Point(375, 340));
    

    UPDATE: using SendInput now, tnx Tom.

    btw. I used only declarations needed for this sample, for anything more there is a nice library : Windows Input Simulator (C# SendInput Wrapper – Simulate Keyboard and Mouse)

      public class ClickOnPointTool
      {
    
        [DllImport("user32.dll")]
        static extern bool ClientToScreen(IntPtr hWnd, ref Point lpPoint);
    
        [DllImport("user32.dll")]
        internal static extern uint SendInput(uint nInputs, [MarshalAs(UnmanagedType.LPArray), In] INPUT[] pInputs,  int cbSize);
    
    #pragma warning disable 649
        internal struct INPUT
        {
          public UInt32 Type;
          public MOUSEKEYBDHARDWAREINPUT Data;
        }
    
        [StructLayout(LayoutKind.Explicit)]
        internal struct MOUSEKEYBDHARDWAREINPUT
        {
          [FieldOffset(0)]
          public MOUSEINPUT Mouse;
        }
    
        internal struct MOUSEINPUT
        {
          public Int32 X;
          public Int32 Y;
          public UInt32 MouseData;
          public UInt32 Flags;
          public UInt32 Time;
          public IntPtr ExtraInfo;
        }
    
    #pragma warning restore 649
    
    
        public static void ClickOnPoint(IntPtr wndHandle , Point clientPoint)
        {
          var oldPos = Cursor.Position;
    
          /// get screen coordinates
          ClientToScreen(wndHandle, ref clientPoint);
    
          /// set cursor on coords, and press mouse
          Cursor.Position = new Point(clientPoint.X, clientPoint.Y);
    
          var inputMouseDown = new INPUT();
          inputMouseDown.Type = 0; /// input type mouse
          inputMouseDown.Data.Mouse.Flags = 0x0002; /// left button down
    
          var inputMouseUp = new INPUT();
          inputMouseUp.Type = 0; /// input type mouse
          inputMouseUp.Data.Mouse.Flags = 0x0004; /// left button up
    
          var inputs = new INPUT[] { inputMouseDown, inputMouseUp };
          SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
    
          /// return mouse 
          Cursor.Position = oldPos;
        }
    
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to programmatically send click events to a view? if so, how?
Possible Duplicate: In jQuery, why does programmatically triggering ‘click()’ on a checkbox not immediately
is it not possible to have both CLICK and DOUBLE_CLICK on the same display
Is it possible to handle such events as: Ctrl + mouse left button click;
Possible Duplicate: In JavaScript can I make a “click” event fire programmatically for a
I have been trying to find a way to make a mouse click programmatically
How would I programmatically click a Swing JButton in a way that would register
I want to click the back button in the navigationBar programmatically in my second
Is it possible to make it so that the user can click on an
Is it possible to programmatically fire mouse events in DOM? My sample case would

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.