C# 低级鼠标钩子和表单事件处理
我正在使用 VS 2010 生成的简单表单,其中包含 2 个按钮:开始和停止。 Start 使用 SetWindowsHookEx 触发 WH_MOUSE_LL,stop 停止钩子。 钩子工作正常,我设法用双击“替换”鼠标中键单击,我遇到的唯一问题是单击表单的最小化/最大化/关闭按钮,似乎之间存在某种“事件竞赛”上面提到的按钮调用的钩子和事件。它反映了这样一个事实:当您按下其中一个按钮时,它会在完成其操作(例如表单最小化)之前持续“按下”一段时间。 当我右键单击表单并选择其中一项操作时,它会立即响应,当我停止挂钩并按上述按钮之一时,也会发生同样的情况。 有人遇到过这样的行为吗?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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.