library KeyHook;<br><br>uses<br> Windows,Messages,SysUtils,<br> Classes;<br>const<br> AlTIsDownFlags=$20;<br>type<br> PKeyBoardLLStruct=^TKeyBoardLLStruct;<br> TKeyBoardLLStruct=record<br> VCode
WORD;<br> ScanCode
WORD;<br> Flags
WORD;<br> Time
WORD;<br> dwExtroInfo
WORD;<br>end;<br>var<br>MyHook,HookHandle:HHook;<br>keyPress:boolean;<br><br>{$R *.res}<br><br>//屏蔽低级键盘<br>function KeyLLHookProc(icode:integer;wparam:Wparam;lparam:LPARAM):LRESULT;stdcall;<br>var<br> P
KeyBoardLLStruct;<br>begin<br> result:=0;<br> if icode=HC_ACTION then<br> begin<br> case wparam of<br> WM_KEYDOWN,<br> WM_KEYUP,<br> WM_SYSKEYDOWN,<br> WM_SYSKEYUP:<br> begin<br> p:=PKeyBoardLLStruct(lparam);<br> keyPress:= (P.VCode=VK_LWIN) or (P.VCode=VK_RWIN) or<br> ((P.VCode=VK_TAB) and ((P.Flags and AlTIsDownFlags)<>0)) or<br> ((P.VCode=VK_ESCAPE) and ((P.Flags and AlTIsDownFlags)<>0)) or<br> ((P.VCode=VK_ESCAPE) and ((GetKeyState(VK_CONTROL) and $8000)<>0)) or<br> ((P.VCode=VK_DELETE) and ((GetKeyState(VK_CONTROL) and $8000)<>0) and ((P.Flags and AlTIsDownFlags)<>0));<br> if KeyPress then<br> result:=1;<br><br> end;<br> end;<br><br> end<br> else<br> CallNextHookEx(MyHook,icode,wparam,lparam);<br><br>end;<br><br>function InstallKeyHook:bool;stdcall;export;<br>begin<br> MyHook:=0;<br> MyHook:=SetWindowsHookEx(13{WH_KEYBOARD_LL},@KeyLLHookProc,Hinstance,0);<br> result:=(MyHook<>0);<br>end;<br>function UnInstallKeyHook:bool;stdcall;export;<br>begin<br> result:=UnHookWindowsHookEx(MyHook);<br> MyHook:=0;<br>end;<br><br><br>//屏蔽键盘<br>function KeyHookProc(icode:integer;wparam:WPARAM;lparam:LPARAM):LRESULT;stdcall;<br>begin<br> result:=0;<br> if icode<0 then<br> CallNextHookEx(hookHandle,icode,wparam,lparam)<br> else<br> begin<br> result:=1;<br> end;<br>end;<br><br>function EnabledKeyHook:bool;stdcall;export;<br>begin<br> hookHandle:=0;<br> hookHandle:=SetWindowsHookEx(WH_KEYBOARD,@KeyHookProc,Hinstance,0);<br> result:=(hookHandle<>0);<br>end;<br>function UnEnabledKeyHook:bool;stdcall;export;<br>begin<br> result:=UnHookWindowsHookEx(hookHandle);<br> hookHandle:=0;<br>end;<br><br>exports<br> InstallKeyHook,UnInstallKeyHook,EnabledKeyHook,UnEnabledKeyHook;<br>end.<br> <br>第一个钩子是屏蔽系统功能键的 比如Alt+Tab ,Ctrl+Esc,Win键. 第二个是屏蔽普通键盘的。任务管理器是屏蔽不掉的。