We can map WM_LBUTTON or WM_RBUTTON down to know whether user has pressed the left or right button respectively on top of the window or not. But sometimes, we have to know this information while we’re processing other handlers like painting/drawing the window.
#define SHIFTED 0x8000
void GetMouseButtonState()
{
if ((GetKeyState(VK_LBUTTON) & SHIFTED))
{
printf( "Left button is pressed" );
}
if ((GetKeyState(VK_RBUTTON) & SHIFTED))
{
printf( "Right button is pressed" );
}
}
Please note that this information is a system wide information. By knowing this status doesn’t mean that the button is pressed on top of your window. For that you will have to know the current cursor position using GetCursorPosition and check if it’s within the Window Rect or not.
You can see the similar keyboard sample at MSDN website. – Using Keyboard Input