Thread: 'IsLButtonDown' ?

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    102

    'IsLButtonDown' ?

    I need a function that will return the current state of the left mouse button.
    The obvious answer would be to have a static boolean variable that changes according to WM_LBUTTONDOWN/UP messages. However, this doesn't take into account whether the mouse button was released on a child window, or outside of the main window even.

    Any suggestions apreciated.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You can use GetAsyncKeyState.
    Code:
    BOOL IsLButtonDown(void)
    {
        return (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
    }
    Note that MSDN says this:
    Quote Originally Posted by MSDN GetAsyncKeyState
    The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling

    GetSystemMetrics(SM_SWAPBUTTON)

    which returns TRUE if the mouse buttons have been swapped.

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    102
    Excellent, thanks a lot.

Popular pages Recent additions subscribe to a feed