C # for low-level mouse and form event handling

I am using a simple form generated by VS 2010 which contains 2 buttons, start and stop. Start starts WH_MOUSE_LL with SetWindowsHookEx and stops the stop. The hook works fine, and I'm trying to "replace" the middle mouse button with a double click, the only problem I have is to click the "Minimize" / "Maximize / Close" buttons of the form, it seems that there is some kind of "event race" between the hook and the events triggered by the buttons mentioned above. It reflects the fact that when you press one of these buttons, it continues to β€œpress” for a while until it completes the action (for example, minimizes it). When I right-click on a form and select one of these actions, it will immediately respond when I stop the hook and press one of the buttons mentioned above. Has anyone encountered this behavior?

+6
source share
1 answer

I also experienced this before. I'm not sure about the specific reason, but I always solved the problem by listening to events that fire when the mouse enters and leaves the client area of ​​the form, window, whatever. You can use these events to capture and detach the mouse, and then you will get normal behavior.

+2
source

Source: https://habr.com/ru/post/896136/


All Articles