Intercepting click event for all controls in an app in C# (WinForms)

前端 未结 4 835
不思量自难忘°
不思量自难忘° 2021-01-02 23:01

I want to make an application to intercept all UI events in all the forms of my application and to write them to a log. This data can than be used to see which controls are

4条回答
  •  抹茶落季
    2021-01-02 23:27

    In Windows API this is done using local hooks (you can set local mouse hook using SetWindowsHookEx function). This is the proper way to do your task. In C# you need to use P/Invoke in order to get access to SetWindowsHookEx.

    One more task would be to match the HWND (windows handle) to corresponding WinForms control. Read this article for how to do this (via WM_GETCONTROLNAME message).

    Also see this question which is a duplicate of yours.

提交回复
热议问题