0

I would like to simulate Mouseevents in one WPF application by forwarding them from another windows application. Here is what I tried so far: Overriding WndProc in a Windows Forms NativeWindow to get the Mouse Messages.

   [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
protected override void WndProc(ref Message m)
{
        var mUIApps = new UIApps(System.Diagnostics.Process.GetProcesses());
        var app = mUIApps.FirstOrDefault(x => x.Caption.StartsWith("WPF to Receive"));
        var mHwnd = app.HWnd;

        switch (m.Msg)
        {
            case WM_LBUTTONDOWN:
            case WM_LBUTTONUP:
            case WM_MOUSEMOVE:
                PostMessageSafe(new HandleRef(app, mHwnd), (uint)m.Msg, m.WParam, m.LParam);
                break;
        }
}

PostMessageSafe was taken from http://www.pinvoke.net/default.aspx/user32/PostMessage.html

this runs through fine, but on the other app no mouse events are received. something i am missing here?

oleole
  • 207
  • 2
  • 10
  • Do you think that a messaging system might be better? Perhaps something like Akka.NET or SignalR would work very well for this. – Maderas Aug 23 '17 at 13:29
  • How about using the [`SendInput`](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx) function? – dymanoid Aug 23 '17 at 13:45
  • [You can’t simulate keyboard input with PostMessage](https://blogs.msdn.microsoft.com/oldnewthing/20050530-11/?p=35513). The same principles apply to mouse input. Once input was handled in a window, there is no way to pass it on to another window underneath it. – IInspectable Aug 25 '17 at 15:22

0 Answers0