How can I raise a mouse event in WPF / C# with specific coordinates?

喜夏-厌秋 提交于 2019-11-29 14:37:12

问题


I'd like to raise a mouse event (a click, mousedown, or mouseup) by taking a user's click anywhere in a WPF window and translating it by a known difference, e.g. click at x,y, raise the click event at x+100, y+100.

The underlying problem is that there's a display monitor that physically moves relative to an overlaying touch screen. Rather than recalibrating the touchscreen with every move, I'd like to add the translation offset to the click event.

I've looked at the Win32 API for mouse_event and its superseding function, SendInput. I admit I'm lost as I'm not very familiar with the API.

Surely this is a simple problem to solve, but I can't find example code anywhere that gets me to where I can implement a solution. Any help, pointers, or solid examples of how to add this to my code behind would be appreciated.

Thanks Mark


回答1:


Win32 API won't work with WPF, this link might help

 // Copied the snippet of code from the link above, just to help future readers
 MouseEventArgs e = new MouseEventArgs(Mouse.PrimaryDevice, 0);
 e.RoutedEvent = Mouse.MouseEnterEvent;

 youUIElement.RaiseEvent(e);
 // Or
 InputManager.Current.ProcessInput(e);


来源:https://stackoverflow.com/questions/6325956/how-can-i-raise-a-mouse-event-in-wpf-c-sharp-with-specific-coordinates

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!