[英]win32api: temporarily block mouse clicks?
Is there any way to disable regular windows mouse clicks using the win API? 有什么方法可以使用Win API禁用常规的Windows鼠标单击? I can disable clicks anywhere besides a particular point by doing
ClipCursor
, but the clicks still register. 我可以通过执行
ClipCursor
来禁用除特定点之外的任何位置的单击,但是单击仍会注册。
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. 另外,我也想有条件地禁用鼠标单击……例如,我要使其无法关闭不受控制的应用程序的窗口,因此我希望发送到该窗口的“ X”的单击不会消失通过。
You can, and it's very dangerous. 您可以,这非常危险。 Here's how, in c++
这是在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. 更改以上示例中的
false
,以重新启用键盘。
BTW this technique also works similarly with keyboard input, even Ctrl+Alt+Del wont work. 顺便说一句,此技术也与键盘输入类似,即使Ctrl + Alt + Del也无法使用。
If you want to allow the mouse to move, but block clicks only, add some if ((wParam == WM_MOUSEMOVE) || (wParam == WM_NCMOUSEMOVE))
code. 如果要允许鼠标移动,但仅阻止点击,请添加一些
if ((wParam == WM_MOUSEMOVE) || (wParam == WM_NCMOUSEMOVE))
代码。
More info at http://msdn.microsoft.com/en-us/library/ms644986(VS.85).aspx 有关更多信息,请访问http://msdn.microsoft.com/zh-cn/library/ms644986(VS.85).aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.