问题
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