Hey.
I've got a low level mouse hook that is keeping track of button clicks (lbutton,rbutton,mbutton,xbutton). However, when xbutton is pressed, I cannot figure out how to determine whether or not it was the button1 or button2. It doesn't appear to think it's either XBUTTON1 or XBUTTON2.
Here's the hook (there's some code in there that doesn't matter, for example: the maps).
Code:
LRESULT CALLBACK CHook::LLMouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if ( nCode == HC_ACTION )
{
if ( wParam == WM_LBUTTONDOWN || wParam == WM_RBUTTONDOWN || wParam == WM_MBUTTONDOWN || wParam == WM_XBUTTONDOWN ) //Mouse key down...
{
keytype kt;
kt.type = TYPE_MOUSE;
kt.mouseCode = wParam;
switch ( wParam )
{
case WM_LBUTTONDOWN:
kt.name = _T("Left Mouse");
break;
case WM_RBUTTONDOWN:
kt.name = _T("Right Mouse");
break;
case WM_MBUTTONDOWN:
kt.name = _T("Middle Mouse");
break;
case WM_XBUTTONDOWN:
int whichbtn = GET_KEYSTATE_WPARAM ( wParam );
if ( whichbtn == XBUTTON1 )//ugh! always prints out Mouse 5
kt.name = _T("Mouse 4");
else
kt.name = _T("Mouse 5");
break;
}
CHook::activeKeys.insert ( make_pair ( wParam, kt ) );
if ( CHook::KeyIsDropped ( wParam ) ) return 1; //If we need to filter this key, do so
}
else if ( wParam == WM_LBUTTONUP || wParam == WM_RBUTTONUP || wParam == WM_MBUTTONUP || wParam == WM_XBUTTONUP )
{
CHook::keyReleased = true; //A key has been released - set the variable to it
//Remove the key from the map (it has been released now...)
map<long, keytype>::iterator i = CHook::activeKeys.find ( wParam );
if ( i != CHook::activeKeys.end() )
{
CHook::activeKeys.erase ( i );
}
}
}
return CallNextHookEx ( CHook::hMouseHook, nCode, wParam, lParam );
}
Any help concerning this topic would be greatly appreciated.
Thanks,
Matt N