Delphi中使用低层钩子 屏蔽Win、Ctrl+ESC、Alt+Tab、Alt+F4


本文整理自网络,侵删。

 unit uHook;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Controls, Forms,
Dialogs, StdCtrls;

type
tagKBDLLHOOKSTRUCT = packed record
vkCode: DWORD;
scanCode: DWORD;
flags: DWORD;
time: DWORD;
dwExtraInfo: DWORD;
end;
KBDLLHOOKSTRUCT= tagKBDLLHOOKSTRUCT;
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
const WH_KEYBOARD_LL = 13;
const LLKHF_ALTDOWN = $20;
function LowLevelKeyboardProc(nCode:Integer;
WParam: WPARAM;LParam:LPARAM):LRESULT;stdcall;
procedure hookstar;
procedure hookend;
var
hhkLowLevelKybd:HHOOK;

implementation

function LowLevelKeyboardProc(nCode: Integer;WParam: WPARAM;LParam: LPARAM):LRESULT; stdcall;
var
fEatKeystroke: BOOL;
p: PKBDLLHOOKSTRUCT;
begin
Result:=0;
fEatKeystroke:=FALSE;
p:=PKBDLLHOOKSTRUCT(lParam);
if (nCode=HC_ACTION) then
begin
case wParam of
WM_KEYDOWN,
WM_SYSKEYDOWN,
WM_KEYUP,
WM_SYSKEYUP:
fEatKeystroke:=
((p.vkCode=VK_TAB) and ((p.flags and LLKHF_ALTDOWN) <> 0)) or
((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
((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;
if nCode <> 0 then
Result := CallNextHookEx(0,nCode,wParam,lParam);
end;

procedure HookStar;
begin
if hhkLowLevelKybd=0 then
hhkLowLevelKybd:=SetWindowsHookExW(WH_KEYBOARD_LL,LowLevelKeyboardProc, Hinstance,0);
end;

procedure HookEnd;
begin
if (hhkLowLevelKybd<>0) and UnhookWindowsHookEx(hhkLowLevelKybd) then
hhkLowLevelKybd:=0;
end;

end.

相关阅读 >>

Delphi 对image字段存取图片、文件

Delphi richedit根据鼠标位置定位光标的方法

Delphi xe6 在两个图片切换的时候实现翻书效果

Delphi显示 jpg、png、gif 图片及 gif 动画

Delphi firemonkey移动应用程序将设置保存到ini文件的示例

Delphi 检测进程是否存在函数

Delphi中线程的释放

Delphi10.x dpr文件

Delphi异常处理的基本原则和方法

Delphi webbrowser设置自己定义user-agent

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...