在WPF中模拟鼠标/键盘输入 [英] Simulate Mouse/Keyboard Input In WPF

查看:536
本文介绍了在WPF中模拟鼠标/键盘输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于在WPF(和Windows)中模拟鼠标/键盘输入有很多问题.我认为我的问题与平常的问题略有不同,我希望您能提供一些意见.我见过的大多数帖子都考虑到了特定的更高级别的操作:我想单击它,我要在这里移动鼠标,等等.要模拟这些,可以简单地使用路由事件.但是,我希望从远程应用程序操作鼠标,并希望以较低级别输入鼠标事件:当前鼠标位置为x,y,按钮状态为此类.我的目标框架是WPF,但是如果要使用通用的虚拟鼠标驱动程序之类的方法,我也很满意.我没有安全方面的顾虑:接收消息的应用程序将由我进行更高级别的编码,因此我不需要疯狂的黑客.我愿意使用托管或非托管代码,并尽其所能去完成这个工作,但我不想重蹈覆辙.如果需要访问Windows消息,我可以将我的应用程序托管在HwndHost中.

There are many questions relating to simulating mouse/keyboard input in WPF (and Windows, for that matter). I have something a little different than the usual question, I think, and I'd like your input. Most posts I've seen have a specific higher level action in mind: I want to click this, I want to move the mouse here, etc. To emulate these, one can simply use routed events. However, I'm hoping to operate a mouse from a remote app and would like to input mouse events at a low-level: current mouse position is x,y and button state is such and such. My target framework is WPF, but if something like a generic virtual mouse driver is the way to go, I'm cool with that too. I do not have security concerns: the apps receiving the messages will be coded by me at a higher level, so I don't need crazy hacks. I'm willing to use managed or unmanaged code and take the rabbit hole as deep as it needs to go to make this work, but I don't want to reinvent the wheel. I can host my apps in an HwndHost or some such too, in case I need access to windows messages.

有想法吗?

推荐答案

WPF具有一些内置的自动化功能.这有点复杂,而且我从来没有亲自尝试过,但是最近我一直在读它-值得一试:

WPF has some built-in automation capabilities. It's a bit complicated, and I've never actually tried it myself, but I've been reading about it recently - it might be worth checking out:

http://msdn.microsoft.com/en-us/library/ms747327.aspx

或在Google中搜索"WPF自动化"

Or search google for "WPF automation"

这篇关于在WPF中模拟鼠标/键盘输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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