delphi 全局钩子锁定键盘

2018-10-31

//可以锁所有键盘按键和任意组合键,但对于ALT+TAB,CTRL+ALT+DEL无效!

//DLL代码如下

Library KillKB;

uses Wintypes, WinProcs;

Var
oldHook: HHook;

function KBHooKProc(code: Integer; wParam: WPARAM;lParam: LPARAM):LRESULT;stdcall; export;
Begin
If code < 0 Then
Result := CallNextHookEx( oldHook, code, wparam, lparam )
Else
Result := 1;
end;

function DisableKeyboard: Boolean; export;
Begin
oldHook := SetWindowsHookEx(WH_KEYBOARD,KBHooKProc,HInstance, 0 );
DisableKeyboard := oldHook <> 0;
End;

procedure EnableKeyboard; export;
Begin
If oldHook <> 0 Then Begin
UnhookWindowshookEx( oldHook );
oldHook := 0;
End;
End;

exports
DisableKeyboard,
EnableKeyboard;

Begin
oldHook := 0;
End.

阅读42