Using SendMessage for Simulating User Mouse Clicks

家住魔仙堡 提交于 2019-12-24 11:06:05

问题


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.

Cheers

Ross


回答1:


Unfortunately, this page on win32 hooks says

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.

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?



来源:https://stackoverflow.com/questions/792130/using-sendmessage-for-simulating-user-mouse-clicks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!