我怎样才能提高与具体坐标在WPF / C#中的鼠标事件? [英] How can I raise a mouse event in WPF / C# with specific coordinates?

查看:187
本文介绍了我怎样才能提高与具体坐标在WPF / C#中的鼠标事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个WPF窗口获取用户的点击任意位置,通过已知的差异翻译它,例如提高鼠标事件(点击,鼠标按下或鼠标松开)单击X,Y,提高在x + 100 click事件,Y + 100。

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.

根本的问题是,有一个显示器的肢体动作相对于重叠触摸屏。而不是一举一动重新校准触摸屏,我想补充翻译偏移到Click事件。

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.

我看了在Win32 API的mouse_event及其替代的功能,SendInput。我承认我迷路了,因为我不是很熟悉的API。

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.

由于
选中

推荐答案

的Win32 API不会与WPF工作,这的链接可以帮助

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);

这篇关于我怎样才能提高与具体坐标在WPF / C#中的鼠标事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆