I am looking for a method to get a button press event, something similar like this which 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.
2 Answers
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.

- 9,212
- 3
- 35
- 59
-
Thanks for your ideas ! – Kay Lee Jul 17 '16 at 15:45
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

- 1
- 1

- 2,833
- 1
- 25
- 26