简体   繁体   中英

win32api: temporarily block mouse clicks?

Is there any way to disable regular windows mouse clicks using the win API? I can disable clicks anywhere besides a particular point by doing ClipCursor , but the clicks still register.

Alternatively I also want to disable mouse clicks conditionally... for example, I want to make it impossible to close a window of an application I don't control, so I want clicks sent to the 'X' of that window to not go through.

You can, and it's very dangerous. Here's how, in c++

LRESULT __stdcall LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    if ((nCode < 0) || false)
    {
        result = CallNextHookEx(myLowLevelMouseHookHandle, nCode, wParam, lParam);
    }

    return result;
}

Change the false in the example above to re-enable keyboard to work.

BTW this technique also works similarly with keyboard input, even Ctrl+Alt+Del wont work.

If you want to allow the mouse to move, but block clicks only, add some if ((wParam == WM_MOUSEMOVE) || (wParam == WM_NCMOUSEMOVE)) code.

More info at http://msdn.microsoft.com/en-us/library/ms644986(VS.85).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM