Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

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

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.
Posted
Updated 4-Sep-18 13:01pm
v3

1 solution

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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900