注射/模拟WPF路由鼠标点击事件 [英] Inject/simulate WPF routed mouse click events

查看:763
本文介绍了注射/模拟WPF路由鼠标点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些直WPF 3.5控件处理鼠标左键点击,我需要一个表面的应用程序(SDK 1.0)中使用。我现在面临的问题是,默认情况下不工作。我想包装在 SurfaceContentControl 和翻译 ContactTouchDown ContactTapGesture 事件对应的的MouseDown 事件

I have some straight WPF 3.5 controls handling left mouse clicks that I need to use within a Surface app (SDK 1.0). The problem I am facing is that do not work by default. I am thinking of wrapping each control in a SurfaceContentControl and translating ContactTouchDown or ContactTapGesture events to corresponding MouseDown events.

这个问题归结为 - 如何注入或模拟任意路由鼠标事件?我曾尝试 InputManager.Current.ProcessInput(),但没有得到很远。任何帮助表示赞赏。

The problem boils down to - how to "inject" or simulate arbitrary routed mouse events? I have tried InputManager.Current.ProcessInput() but didn't get very far. Any help is appreciated.

推荐答案

evpo的想法是一个有趣的(不过,如果你使用的自定义控件工作,他们很少来用的AutomationPeer类)。

evpo's idea is an interesting one (though if you're working with custom controls, they rarely come with AutomationPeer classes).

您不能简单地注入鼠标输入发送WM_MOUSE *事件添加到您的应用程序... WPF确实会处理该消息,但是,当它去弄清楚鼠标的位置这种情况下,它会查询的实际的鼠标API,而不是试图您在WM坚持什么。

You can't simply 'inject' mouse input by sending WM_MOUSE* events to your app... WPF would indeed process the message but when it goes to figure out the position of mouse for that event, it will query the actual mouse API instead of trying what you stick in the WM.

所以真的所有你能做的就是告诉Windows移动实际的鼠标光标,并作为虽是点击按钮/释放。一些代码,你可以使用的是 http://www.codeproject.com/KB/系统/ globalmousekeyboardlib.aspx

So really all you can do is tell windows to move the actual mouse cursor and act as though the button is being clicked/released. Some code you can use for that is in http://www.codeproject.com/KB/system/globalmousekeyboardlib.aspx

这是说,你可以在技术上做到这一点,它吮吸......你有一个昂贵的多点触控设备,但有1 )表示在其上2)限制其任意部分到鼠标光标正在使用单触摸(并且仅在一个时间的那些的任意部分中的一个和3)未来与确定你将把作为哪个手指的任意方法鼠标控制一个

That said, while you can technically do this, it sucks... you've got an expensive multitouch device but are 1) showing a mouse cursor on it 2) limiting arbitrary parts of it to being used 'single touch' (and only one of those arbitrary parts at a time and 3) coming up with an arbitrary method of determining which finger you will treat as the mouse-controlling one

这篇关于注射/模拟WPF路由鼠标点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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