使用SendMessage函数用于模拟用户鼠标点击 [英] Using SendMessage for Simulating User Mouse Clicks

查看:763
本文介绍了使用SendMessage函数用于模拟用户鼠标点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用SendMessage函数来回回在目标程序作为SendMessage函数块模拟用户点击,直到它触发完成处理该事件。这样做的原因是,这种阻塞使机会,如果任何对话框开辟了作为点击的结果来检测。我的问题是目前,虽然我可以点击在打开模型对话框中嘲笑了形式使用WM_LBUTTONDOWN和WM_LBUTTONUP消息consecutivly上的一个按钮来上班,我不能让它在标准的Windows应用程序菜单和菜单项工作(记事本)。在获得在其中工作将AP precieated的方式执行菜单项上点击的能力,任何帮助。我已经可以检测,如果它是一个菜单项,只需要能够模拟一下就可以使用SendMessage函数阻塞。

I need to use SendMessage fro simulating user clicks in a target program as SendMessage blocks until the event that it triggers is finished processing. The reason for this is that this blocking gives opportunity to detect if any dialogs have opened up as a result of the clicking. My problem currently is that although I can get the click to work using WM_LBUTTONDOWN and WM_LBUTTONUP messages consecutivly on a button in a mocked up form which opens a model dialog, I cannot get it to work on menus and menu items in a standard windows app (Notepad). Any help in getting the ability to perform clicks on menu items in a way which works would be apprecieated. I can already detect if it is a menu item, just need to be able to simulate a click on it with blocking using SendMessage.

干杯

罗斯

推荐答案

不幸的是,在此页面上的 Win32的挂钩说:

Unfortunately, this page on win32 hooks says

模拟鼠标和键盘输入(WH_JOURNALPLAYBACK)。钩子提供唯一可靠的方法来模拟这些活动。如果您尝试通过发送或发布消息来模拟这些事件,Windows内部不更新键盘或鼠标的状态,这可能会导致意外的行为。如果钩子用于播放键盘或鼠标事件,这些事件被处理酷似真实键盘或鼠标事件。

Simulate mouse and keyboard input (WH_JOURNALPLAYBACK). Hooks provide the only reliable way to simulate these activities. If you try to simulate these events by sending or posting messages, Windows internals do not update the keyboard or mouse state, which can lead to unexpected behavior. If hooks are used to play back keyboard or mouse events, these events are processed exactly like real keyboard or mouse events.

所以看起来你可能需要使用诉诸某种为您自动测试宏录制一样的功能 WH_JOURNALRECORD WH_JOURNALPLAYBACK

So it looks like you may have to resort to some kind of macro recorder-like functionality for your automated testing by using WH_JOURNALRECORD and WH_JOURNALPLAYBACK?

这篇关于使用SendMessage函数用于模拟用户鼠标点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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