Forwarding MouseEvents from one WPF application to another

107 views Asked by At

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?

0

There are 0 answers