0
votes

I'm using C++ and DirectD3D9 to draw a menu. I wish to navigate the menu with the mouse. I can get the mouse position, however, checking if the left button is clicked is proving tricky. I am able to check if it is being held down, but not clicked.

bool LBUTTONDOWN = false;
LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) {
    if (nCode == HC_ACTION && (wParam == WM_LBUTTONUP || wParam == WM_LBUTTONDOWN)) {
        LBUTTONDOWN = wParam == WM_LBUTTONDOWN;
    }
    return CallNextHookEx(0, nCode, wParam, lParam);
}

How can I add a check to see if I clicked the left button?

2
Have a look at DirectInput. It's great for checking keyboard/mouse/controller state - cppguy
Using DirectInput for keyboard & mouse has been strongly discouraged for many years. The last time it was a good choice for keyboard/mouse was Windows 9x/ME. - Chuck Walbourn

2 Answers

0
votes

There is no DoubleClick message for LowLevelMouseProc. However, I suppose you can have a work around:

Record the time interval between LBUTTONDOWN and LBUTTONUP, then to check whether it is quick enough to be a click event. And because the mouse acts very fast, it is better to set a timer for the mouse capturing.

For the mouse capturing, you can still call LowLevelMouseProc. However, the DirectInput is more convenient for processing mouse movements.

In DirectX SDK samples, there is a DirectInput sample named "CustomFormat". It shows how to set up a timer to capture mouse input.

I hope this helps.

0
votes

You need to use a timing trick. Create a variable named something like 'nTime', Set the zero for it when the LButton is up. Increase the variable value using a '+=' operator when the LButton is down and check the variable against a value something like that -

bool LBUTTONDOWN = false;
int nTime = 0;
LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) 
{
    if (nCode == HC_ACTION && (wParam == WM_LBUTTONUP || wParam == WM_LBUTTONDOWN)) 
    {
        LBUTTONDOWN = wParam == WM_LBUTTONDOWN;

        if ( LBUTTONDOWN )
        {
            nTime += 1;
            if ( nTime > 1000 /*( this value depends on you )*/ )
            {
                nTime = 0;
                // Here is your hold event code.
            }
        }
        else
            nTime = 0;
    }
    return CallNextHookEx(0, nCode, wParam, lParam);
}