将Click Message发送到另一个应用程序进程

我有一个场景,我需要将点击事件发送到一个独立的应用程序。 我使用以下代码启动了该应用程序。

private Process app; app = new Process(); app.StartInfo.FileName = app_path; app.StartInfo.WorkingDirectory = dir_path; app.Start(); 

现在我想将鼠标点击消息发送到该应用程序,我有相对于应用程序窗口的特定坐标。 我如何使用Windows Messaging或任何其他技术来完成。

我用了

 [DllImport("user32.dll")] private static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, IntPtr dwExtraInfo); 

它运行良好但导致指针移动。 所以不适合我的需要。

然后我用。

 [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); 

它适用于最小化最大化,但不适用于鼠标事件。

我正在使用的mousevents代码是,

 WM_LBUTTONDOWN = 0x201, //Left mousebutton down WM_LBUTTONUP = 0x202, //Left mousebutton up WM_LBUTTONDBLCLK = 0x203, //Left mousebutton doubleclick WM_RBUTTONDOWN = 0x204, //Right mousebutton down WM_RBUTTONUP = 0x205, //Right mousebutton up WM_RBUTTONDBLCLK = 0x206, //Right mousebutton do 

感谢您提前帮助,并等待反馈。

对于单击,您应该同时发送两个鼠标事件以进行精确的鼠标单击事件。

 SendMessage(nChildHandle, 0x201, 0, 0); //Mouse left down SendMessage(nChildHandle, 0x202, 0, 0); //Mouse left up 

它正在我的项目中工作。

保存光标位置,使用mouse_event并向后移动光标。 mouse_event确实是最好的方法。