如何使用低级鼠标挂钩? [英] How do I use low level mouse hooks?

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

问题描述

你好!

我正在制作一个快速启动程序,当用户按住鼠标左键时会自动快速点击。



我通常会使用GetAsyncKeyState,但由于同样检测到原始输入,它会检测程序发出的点击,然后继续点击并永不停止。



问题示例:





代码:



Hello!
I am making a rapid-fire program, that autoclicks fast when the user holds the Left-mouse button down.

I usually would use GetAsyncKeyState, but since the same detects raw input, it will detect the clicks made by the program, and then continue clicking and never stop.

Example of problem:


Code:

if (GetAsyncKeyState(VK_LBUTTON))
  {
  mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
  mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
  Sleep (10);
  }



我已经搜索了几天,并且所有线程都说让我使用低级MouseHook,文档非常混乱(特别是对于初学者)。



我怎么能做这个工作,有人能给我一个鼠标勾的例子,检测左鼠标持有并将真值返回给bool变量吗?



感谢您的阅读!



我的尝试:



GetAsyncKeyState不起作用,我已经尝试了几种方法来实现它。


I have searched for days, and all threads said for me to use a Low-Level MouseHook, The documentation is very confusing (especially for a beginner).

How could I make this work, could someone give me an example of a mouse hook detecting left mouse to hold and return a true value to a bool variable?

Thanks for reading!

What I have tried:

GetAsyncKeyState will not work, I have tried several ways of implementing it.

推荐答案

我写了一些鼠标和键盘挂钩代码很久以前我基于这篇文章: HOWTO跟踪用户的空闲时间 [ ^ ]。它向您展示了如何设置挂钩并监控输入。关键是钩子程序必须驻留在DLL中。至少它确实如此,我认为它仍然存在,但我不确定。



那篇文章很老了。我写的代码仍然在W10中工作,所以这也应该有用,但是如果你的目标是W10,我肯定会下载并运行该文章中的示例应用程序,并确保它适合你。
I wrote some mouse and keyboard hooking code a long time ago and I based it on this article : HOWTO track a user's idle time[^]. It shows you how to set the hook and monitor the inputs. The key thing is the hook procedure has to reside in a DLL. At least it did and I assume it still does but I am not certain.

That article is quite old. The code I wrote still works in W10 so this should work also but if you are targeting W10 I would be sure to download and run the sample app from that article and make sure it works for you.


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

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