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.
我需要使用SendMessage来模拟目标程序中的用户点击,因为SendMessage会阻塞,直到它触发的事件完成处理。这样做的原因是这种阻塞有机会检测是否由于点击而打开了任何对话框。我当前的问题是虽然我可以使用WM_LBUTTONDOWN和WM_LBUTTONUP消息连续地在一个模拟窗体中打开一个模型对话框的按钮上工作,但我无法让它在标准的Windows应用程序中处理菜单和菜单项(记事本)。任何有助于以一种有效的方式执行菜单项目点击的能力的任何帮助都将得到赞赏。我已经可以检测到它是否是一个菜单项,只需要能够通过使用SendMessage阻塞来模拟对它的点击。
Cheers
Ross
1 个解决方案
#1
Unfortunately, this page on win32 hooks says
不幸的是,这个关于win32钩子的页面说
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_JOURNALPLAYBACK)。钩子提供了模拟这些活动的唯一可靠方法。如果您尝试通过发送或发布消息来模拟这些事件,Windows内部不会更新键盘或鼠标状态,这可能会导致意外行为。如果使用挂钩来回放键盘或鼠标事件,则这些事件的处理方式与真正的键盘或鼠标事件完全相同。
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
?
所以看起来你可能不得不通过使用WH_JOURNALRECORD和WH_JOURNALPLAYBACK来采用某种类似宏记录器的功能进行自动化测试?
#1
Unfortunately, this page on win32 hooks says
不幸的是,这个关于win32钩子的页面说
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_JOURNALPLAYBACK)。钩子提供了模拟这些活动的唯一可靠方法。如果您尝试通过发送或发布消息来模拟这些事件,Windows内部不会更新键盘或鼠标状态,这可能会导致意外行为。如果使用挂钩来回放键盘或鼠标事件,则这些事件的处理方式与真正的键盘或鼠标事件完全相同。
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
?
所以看起来你可能不得不通过使用WH_JOURNALRECORD和WH_JOURNALPLAYBACK来采用某种类似宏记录器的功能进行自动化测试?