private void InterceptMouse_MouseClick(object sender, MouseClickEventArgs e) { Application.Current.Dispatcher.Invoke(new Action(() => { Rect rect = new Rect(this.Left, this.Top, this.Width, this.Height); Point pt = RealPixelsToWpf(this, e.Location); // message.Content = $"x={e.Location.X},y={e.Location.Y}"; if (rect.Contains(pt)) { // System.Windows.Forms.SendKeys.SendWait($"x={e.Location.X},y={e.Location.Y}\r\n"); OnClicked(); e.Handled = true; } })); }
private static IntPtr HookCallback( int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam) { MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)); MouseClickEventArgs e = new MouseClickEventArgs { Location = new Point(hookStruct.pt.x, hookStruct.pt.y) }; MouseClick?.Invoke(null, e); if (e.Handled == true) { return((IntPtr)1); } // Console.WriteLine(hookStruct.pt.x + ", " + hookStruct.pt.y); } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }