Reputation: 3
I need to repeat my function in my mousehook while the left mouse button is held down. But with my current code, it only gets called once. I assumed that when I hold down the left mouse button the code gets called over and over again and I am not sure if this actually works what I wanna try. I need the code to run in the hook for timing purposes.
LRESULT __stdcall hk_mouse( int nCode, WPARAM wParam, LPARAM lParam )
{
if (nCode >= 0)
{
switch (wParam) {
case WM_LBUTTONDOWN:
{
Beep( 1000, 100 );
break;
}
case WM_LBUTTONUP:
{
break;
}
default:
{
break;
}
}
}
return CallNextHookEx( mouse_hook, nCode, wParam, lParam );
}
Upvotes: 0
Views: 168
Reputation: 315
Mouse button messages don't repeat in Windows.
When you receive WM_LBUTTONDOWN
you should create a timer with the repeat delay you require, and then handle WM_TIMER
messages in your hook proc and look for the timer ID you specified when creating the timer.
When the mouse button is released and you receive WM_LBUTTONUP
you should delete the timer.
You should note that any code you execute in response to the WM_TIMER
message should also be executed in the WM_LBUTTONDOWN
event (unless you want a delay when the button is first pressed), so it would be best to put that code in a function that can then be called from both places.
Upvotes: 1