C#低级鼠标钩子和表单事件处理 [英] C# low level mouse hook and form event handling

查看:205
本文介绍了C#低级鼠标钩子和表单事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是2010年VS其中包含2个按钮,启动和停止生成一个简单的表格。
开始触发WH_MOUSE_LL使用SetWindowsHookEx函数,并停止停止钩。
挂钩工作正常,我奶源与双击替换鼠标中键点击,我唯一的问题是点击最小化形式/最大化/关闭按钮,似乎有某种事件竞赛挂钩和事件由上述按钮叫之间。它反映的事实是,当你按了它不断被逼了一回它完成之前的一个按钮的行动(例如最小化的形式)。
当我右键单击窗体,然后选择它响应这些行动一出,立即相同的事情会发生在我停下挂钩,按上述按钮之一。
具有人遇到这样的行为?

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 ?

推荐答案

我以前都经历过这一点。我不知道来的确切原因,但我一直通过监听当鼠标进入和离开形式的客户区被触发的事件,窗口,无论解决了这个问题。您可以使用这些事件挂钩和脱钩鼠标,然后你会得到正常的行为。

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.

这篇关于C#低级鼠标钩子和表单事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆