unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> procedure FormCreate(Sender: TObject);<br> procedure FormDestroy(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br> KBDLLHOOKSTRUCT=record<br> vkCode
WORD;<br> scanCode
WORD;<br> flags
WORD;<br> time
WORD;<br> dwExtraInfo:ulong;<br> end;<br> LPKBDLLHOOKSTRUCT=^KBDLLHOOKSTRUCT;<br><br>var<br> Form1: TForm1;<br> //定义句柄<br> OldHook:HHOOK;// 钩子 句柄<br><br>implementation<br><br>{$R *.dfm}<br>const<br>LLKHF_ALTDOWN=$20;<br>WH_KEYBOARD_LL= 13;<br><br>//键盘钩子 封锁 windows 热键<br>function KeyProc(code: Integer; wparam: WPARAM; lparam: LPARAM): LRESULT stdcall;<br>var<br>pkbhs:LPKBDLLHOOKSTRUCT;<br>begin<br><br><br> Result:=1;<br> if (code < 0) then<br> begin<br> Result:= CallNextHookEx(OldHook,code, wParam, lParam);<br> exit;<br> end;<br><br> pkbhs := LPKBDLLHOOKSTRUCT( lParam);<br><br> if (pkbhs.vkCode=91) then//封锁win键<br> begin<br> exit;<br> end;<br><br> if (pkbhs.vkCode=VK_ESCAPE) and (GetAsyncKeyState(VK_CONTROL)<0) then<br> begin<br> exit; //封锁 CTRL+ESC<br> end;<br><br> if (pkbhs.vkCode=VK_TAB) and (( LLKHF_ALTDOWN and pkbhs.flags)>0) then<br> begin<br> exit; //封锁 ALT+TAB<br> end;<br><br> if (pkbhs.vkCode=115) and ((pkbhs.flags and LLKHF_ALTDOWN)>0) then<br> begin<br> exit; //封锁 ALT+F4<br> end;<br><br> if (pkbhs.vkCode=VK_ESCAPE) and ((pkbhs.flags and LLKHF_ALTDOWN)>0) then<br> begin<br> exit; //封锁 ALT+ESC<br> end;<br><br> if (pkbhs.vkCode=VK_SPACE) and (GetAsyncKeyState(VK_CONTROL)<0) then<br> begin<br> exit; //封锁 CTRL+ ' '<br> end;<br> if (pkbhs.vkCode=VK_SNAPSHOT) then<br> begin<br> exit; //封锁 Print Screen<br> end;<br> if(pkbhs.vkCode=164) then<br> begin<br> exit;<br> end;<br> Result:=CallNextHookEx(OldHook, code, wParam, lParam);<br>end;<br><br>//---------------------------------------------------------------------------<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> OldHook:=0;<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> if OldHook>0 then<br> UnhookWindowsHookEx(OldHook);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> //注册 钩子<br> OldHook := SetWindowsHookEx(WH_KEYBOARD_LL {WH_KEYBOARD_LL},<br> KeyProc, HInstance, 0);<br> if (Sender is TButton) then<br> TButton(Sender).Enabled:=not (OldHook>0);<br><br>end;<br><br>end.<br><br>=============================<br>以上代码,除了Ctrl+Alt+Del之外基本上的键盘按键都能屏蔽,若是想把C.A.D.也屏蔽掉,可以试着将代码注入到WinLogon.exe进程当中去,以提升权限。