开发者

Handle button click in another application

I am looking for a method to get a button press event, something similar like this whi开发者_运维问答ch is used to retrieve a pointer right after an event is fired. The button I mean is located on any particular windows application I set as a target (.eg windows media player's Play button). If you know what message to catch right after I click the Play button.


What you are looking for is Global Mouse Hook. You can take a look at this article: Processing Global Mouse and Keyboard Hooks in C#

Once you handle CLICK event, you can use API functions to get Application / Control under the cursor (WindowFromPoint).

Here is one more article with code sample that will help you: .NET Object Spy and InvokeRemote (this is similar to spy++)

You cannot do this without using windows native methods.


User tagged this in winapi. He probably already knew about hooks. Part of HABJAN reply point to the right direction. Answer to the question is: Use Spy++ I don't think there's a message for "button clicked" or "url link clicked" but if you observe a program with spy++ you'll see there's UI notification messages like these ones: WM_CAPTURECHANGED, WM_CHANGEUISTATE or even WM_POSCHANGING. I think these are the messages you are looking for.

Another way to do this may be to use the AutomationElement, see this answer: Getting the current tab's URL from Google Chrome using C#

PS: If I could downvote an edit by another user to a question, I would downvote Dyppl's edit... question used very precise words: "get message" instead of "handle" in the title. PS2: It's an old question but I was asking me the same question earlier and came across it on google, maybe my answer will help someone

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜