[ACCEPTED]-Check if Mouse LButton is down?-mouse

Accepted answer
Score: 21

There is a Windows API function GetAsyncKeyState(), which 17 despite its name is also usable to get the 16 state of the mouse buttons. The linked documentation 15 directly contains the answer to your question:

The 14 GetAsyncKeyState function works with mouse buttons. However, it 13 checks on the state of the physical mouse 12 buttons, not on the logical mouse buttons 11 that the physical buttons are mapped to. For 10 example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state 9 of the left physical mouse button, regardless 8 of whether it is mapped to the left or right 7 logical mouse button. You can determine 6 the system's current mapping of physical 5 mouse buttons to logical mouse buttons by 4 calling GetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons 3 have been swapped.

The result type is short, to 2 check for the most significant bit just 1 test whether the value is negative.

Score: 0
OnMouseMove(UINT nFlags, CPoint point)
  m_LButtonPressed=nFlags & MK_LBUTTON;
  CWnd::OnMouseMove(nFlags, point);


More Related questions