C# low level mouse hook and form event handling

耗尽温柔 提交于 2019-12-22 05:36:12

问题


I'm using a simple form generated by VS 2010 which contains 2 buttons, start and stop. Start triggers WH_MOUSE_LL using SetWindowsHookEx, and stop stops the hook. The hook works fine and I mange to "replace" middle mouse button click with double click, the only problem I have is clicking on Minimize/Maximize/Close buttons of the form, it seems that there is some sort of "event race" between the hook and events called by buttons mentioned above. It reflects on the fact that when you press one of those buttons it keeps being "pressed" for a while before it completes it's action (e.g. form minimizes). When I right click the form and select one of those actions it responds immediately same thing goes when I stop the hook and press one of the buttons mentioned above. Have anyone encountered such behavior ?


回答1:


I have experienced this before as well. I'm not sure as to the exact cause, but I have always solved the problem by listening for events that are fired when the mouse enters and leaves the client area of the form, window, whatever. You can use those events to hook and unhook the mouse, and then you will get the normal behaviour.



来源:https://stackoverflow.com/questions/7232819/c-sharp-low-level-mouse-hook-and-form-event-handling

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