[原创] 在XP/2K 下实现 Win+Ctrl+Del 等键的屏蔽的方法,附源码与演示程序下载。
作者: 陆岛工作室
![](https://www.cnblogs.com/images/cnblogs_com/iinsnian/139915/t_xoteclogo2.gif)
在 Windows 98 下我们知道用 SystemParametersInfo(SPI_SETFASTTASKSWITCH, 1, @temp, 0); 来实现 Win+Ctrl+Del 的屏蔽,但这种方法在NT的操作系统下如 Windows XP / Windows 2000等就不行了,这里我给大家提供一个新的方法,采用钩子拦截的方式,来实现屏蔽系统按键。本示例附详细的源码与演示程序。
源码与演示程序。 ![](https://www.cnblogs.com/images/cnblogs_com/iinsnian/139262/t_download.gif)
实现方法的代码如下:
{*******************************************************************************
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
XOtecExpress Visual Component Library [陆岛工作室]
Copyright (c) 2008 XOtec Studio. [PengJunli]
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
By: PengJunLi Build: 2008-06
E-mail: iinsnian@126.com XOtec@vip.QQ.com QQ:442801172
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
*******************************************************************************}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
unit Unit2;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
interface
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
uses
Windows, Messages, SysUtils, Variants, Classes;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
type
tagKBDLLHOOKSTRUCT = packed record
vkCode: DWORD;
ScanCode: DWORD;
Flags: DWORD;
Time: DWORD;
dwExtraInfo: DWORD;
end;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
KBDLLHOOKSTRUCT = tagKBDLLHOOKSTRUCT;
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
const
WH_KEYBOARD_LL = 13;
LLKHF_ALTDOWN = $20;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//采用钩子的方法屏蔽系统按键
function DisableTaskKeys(Disable: Boolean): Boolean;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
implementation
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
var
hhkLowLevelKybd: HHOOK;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
{ LowLevelKeyboardProc }
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
function LowLevelKeyboardProc(nCode: Integer; WParam: WPARAM; LParam: LPARAM): LRESULT; stdcall;
var
fEatKeystroke: BOOL;
p: PKBDLLHOOKSTRUCT;
begin
Result := 0;
fEatKeystroke := FALSE;
p := PKBDLLHOOKSTRUCT (lParam);
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
if (nCode = HC_ACTION) then //nCode值为HC_ACTION时表示WParam和LParam参数包涵了按键消息
begin
//拦截按键消息并测试是否是Ctrl+Esc、Alt+Tab、和Alt+Esc功能键。
case wParam of
WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP, WM_SYSKEYUP:
fEatKeystroke :=
((p.vkCode = VK_TAB) and ((p.flags and LLKHF_ALTDOWN) <> 0)) or // Alt+Tab
((p.vkCode = VK_ESCAPE) and ((p.flags and LLKHF_ALTDOWN) <> 0))or //
(p.vkCode = VK_Lwin) or (p.vkCode = VK_Rwin) or (p.vkCode = VK_apps) or //屏蔽WIN按键
((p.vkCode = VK_ESCAPE) and ((GetKeyState(VK_CONTROL) and $8000) <> 0)) or
((p.vkCode = VK_F4) and ((p.flags and LLKHF_ALTDOWN) <> 0)) or
((p.vkCode = VK_SPACE) and ((p.flags and LLKHF_ALTDOWN) <> 0)) OR
(((p.vkCode = VK_CONTROL) and (P.vkCode = LLKHF_ALTDOWN and p.flags) and (P.vkCode = VK_Delete)));
end;
end;
if fEatKeystroke = True then
Result := 1;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
if nCode <> 0 then
Result := CallNextHookEx(0, nCode, wParam, lParam);
end;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
{ DisableTaskKeys }
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
function DisableTaskKeys(Disable: Boolean): Boolean;
begin
Result := False;
if (hhkLowLevelKybd = 0) and Disable then
begin
hhkLowLevelKybd :=SetWindowsHookExW(WH_KEYBOARD_LL, LowLevelKeyboardProc, Hinstance, 0); //设置钩子
Result := hhkLowLevelKybd<>0; // 返回设置成功
end else if not Disable and (hhkLowLevelKybd<>0) then
begin
if UnhookWindowsHookEx(hhkLowLevelKybd) then //卸载键盘钩子
begin
Result := True;
hhkLowLevelKybd := 0;
end;
end;
end;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
end.
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/images/cnblogs_com/iinsnian/139915/t_xoteclogo2.gif)
在 Windows 98 下我们知道用 SystemParametersInfo(SPI_SETFASTTASKSWITCH, 1, @temp, 0); 来实现 Win+Ctrl+Del 的屏蔽,但这种方法在NT的操作系统下如 Windows XP / Windows 2000等就不行了,这里我给大家提供一个新的方法,采用钩子拦截的方式,来实现屏蔽系统按键。本示例附详细的源码与演示程序。
![](https://www.cnblogs.com/Emoticons/qface/055243929.gif)
![](https://www.cnblogs.com/images/cnblogs_com/iinsnian/139262/t_download.gif)
实现方法的代码如下:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
作者: 陆岛工作室