如何引发点击事件? [英] How to raise a click event?

查看:80
本文介绍了如何引发点击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想知道是否可以用C#(或其他任何编程语言)以编程方式引发单击事件,从而有效地模拟用户按下鼠标左键.
我知道我可以根据光标位置调用适当的事件处理程序,但这只能模拟用户在应用程序窗口内单击.我想做的是模拟另一个程序在窗口中的用户单击,从而迫使另一个程序以与用户实际单击它相同的方式做出反应.

预先感谢.

Hi,
I was wondering whether it''s possible in C# (or alternatively in any other programming language) to raise click event programmatically, thus effectively simulating user pressing left mouse button.
I know that I can just call appropriate event handler, based on cursor position, but that can only simulate user clicking inside windows of my application. What I would like to be able to do is to simulate user clicks in windows of another program, thus forcing the other program to react in the same way as if user actually clicked on it.

Thanks in advance.

推荐答案

Microsoft提供了称为 Microsoft Active Accessibility 的东西. a> [ ^ ]允许您自动执行应用程序. Silverlight和WPF应用程序还提供了称为自动化对等点 [ ^ ]允许您自动执行应用程序.
Microsoft provides something called Microsoft Active Accessibility[^] to allow you to automate applications. Silverlight and WPF applications also provide something called Automation Peers[^] to allow you to automate applications.


使用P/Invoke,可以将消息发送到其他窗口,包括WM_MOUSEDOWN/UP和WM_CLICK. SendInput [
Using P/Invoke you can send messages to other windows, including WM_MOUSEDOWN/UP and WM_CLICK. SendInput[^] also appears to be useful.


0)要模拟按钮,请单击包含按钮的应用程序,请使用PeformClick方法.

1)如果它在另一个应用程序中,则需要具有其中包含按钮的窗口的窗口句柄,然后使用PostMessageSendMessage(我将自己使用Postmessage).转到
pInvoke.net [ ^ ]来获取这些API方法的正确原型.
0) To imulate a button click in the app containing the button, use the PeformClick method.

1) If it''s in another app, you need to have the window handle of the window that has the button in it, and then use either PostMessage or SendMessage (I would use Postmessage myself). Go to pInvoke.net[^] to get the proper prototypes for these API methods.


这篇关于如何引发点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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