M
muyixin
Unregistered / Unconfirmed
GUEST, unregistred user!
本来想屏蔽win键的 开始使用系统热键 好像不能当读注册win 改用键盘钩子 可在学习过程中 还时有些问题不时弄的很明白
下面一段代码时在网上找到最多的
library HideWin;
uses
Windows, SysUtils, Messages,Classes;
{$R *.res}
var
KeyHook: HHook;
function HookKey(Code: integer;
wParam: wParam;
lParam: lParam): LRESULT;
stdcall;
type
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
KBDLLHOOKSTRUCT = record
vkCode: DWORD;
ScanCode: DWORD;
Flags: DWORD;
Time: DWORD;
dwExtraInfo: DWORD;
end;
begin
//屏蔽win键
if (Code = HC_ACTION) and ((PKBDLLHOOKSTRUCT(lParam).vkCode = VK_LWIN)
or (PKBDLLHOOKSTRUCT(lParam).vkCode = VK_RWIN)) then
begin
Result := 1;
end
else
begin
Result := CallNextHookEx(KeyHook, Code, wParam, lParam);
end;
end;
procedure begin
Hook;
begin
KeyHook := SetWindowsHookEx(13{=WH_KEYBOARD_LL}, @HookKey, HInstance, 0);
//第四个参数为0 表示为全局钩子
end;
procedure EndHook;
begin
UnhookWindowsHookEx(KeyHook);
end;
exports
begin
Hook, EndHook;
begin
end.
不明白的地方是function HookKey(Code: integer;
wParam: wParam;
lParam: lParam): LRESULT;
stdcall;中为什么要定义这么一个记录 而且是这样定义的
type
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
KBDLLHOOKSTRUCT = record
......
end
在函数中的参数引用也用这个记录来引用 就更不明白了 为什么不直接用呢?
找了好久 还是没答案?
下面一段代码时在网上找到最多的
library HideWin;
uses
Windows, SysUtils, Messages,Classes;
{$R *.res}
var
KeyHook: HHook;
function HookKey(Code: integer;
wParam: wParam;
lParam: lParam): LRESULT;
stdcall;
type
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
KBDLLHOOKSTRUCT = record
vkCode: DWORD;
ScanCode: DWORD;
Flags: DWORD;
Time: DWORD;
dwExtraInfo: DWORD;
end;
begin
//屏蔽win键
if (Code = HC_ACTION) and ((PKBDLLHOOKSTRUCT(lParam).vkCode = VK_LWIN)
or (PKBDLLHOOKSTRUCT(lParam).vkCode = VK_RWIN)) then
begin
Result := 1;
end
else
begin
Result := CallNextHookEx(KeyHook, Code, wParam, lParam);
end;
end;
procedure begin
Hook;
begin
KeyHook := SetWindowsHookEx(13{=WH_KEYBOARD_LL}, @HookKey, HInstance, 0);
//第四个参数为0 表示为全局钩子
end;
procedure EndHook;
begin
UnhookWindowsHookEx(KeyHook);
end;
exports
begin
Hook, EndHook;
begin
end.
不明白的地方是function HookKey(Code: integer;
wParam: wParam;
lParam: lParam): LRESULT;
stdcall;中为什么要定义这么一个记录 而且是这样定义的
type
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
KBDLLHOOKSTRUCT = record
......
end
在函数中的参数引用也用这个记录来引用 就更不明白了 为什么不直接用呢?
找了好久 还是没答案?