如何使用全局钩子检测到鼠标左键? [英] How can I detect just the left mouse click using the global hook?

查看:246
本文介绍了如何使用全局钩子检测到鼠标左键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过用它记录鼠标和键的例子,但我不能只是做左键单击。谢谢

I have seen the examples with it logging the mouse and keys but I couldnt get it just to do the left click. Thank you

推荐答案

请看我对这个问题的评论:你不能使用C#。当然,你的所有应用程序仍然可以用C#编写,但是为了编写设置/取消设置钩子的DLL并且应该用钩子编写一些主要的消息处理,你需要使用其中一种语言编译成本机代码。



如果你看一下设置钩子的功能,你会发现你必须连接一组鼠标事件,其中包括所有按钮,WM_MOUSE或WM_MOUSE_LL:

http: //msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/ library / windows / desktop / ms644988%28v = vs.85%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library /windows/desktop/ms644986%28v=vs.85%29.aspx [ ^ ]。



所有你能做的就是忽略消息您不需要在挂钩功能中处理。



-SA
Please see my comment to the question: you won''t be able to use C#. Of course, all of your application still can be written in C#, but for writing the DLL which sets/unsets the hook and does some primary message processing should be written in hook, you will need to use one of the languages compiling into native code.

If you look at the function setting the hook, you will see that you have to hook up a set of mouse events which does includes all the buttons, WM_MOUSE or WM_MOUSE_LL:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644988%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644986%28v=vs.85%29.aspx[^].

All you can do is ignoring messages which you don''t need to process in your hook function.

—SA


这篇关于如何使用全局钩子检测到鼠标左键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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