1 //调用键盘钩子,屏蔽功能键
2 function keyHookProc(nCode: Integer; LWParam: WPARAM; LLParam: LPARAM): LRESULT; stdcall;
3
4 var
5 hHk :HHOOK;
6
7 //创建勾子
8 hHk:= SetWindowsHookEx(13, @keyHookProc, HInstance, 0);
9
10 function keyHookProc(nCode: Integer; LWParam: WPARAM; LLParam: LPARAM): LRESULT;//调用键盘钩子,屏蔽功能键
11 var
12 p: PKBDLLHOOKSTRUCT;
13 y: integer;
14 begin
15 if nCode < 0 then
16 begin
17 Result:= CallNextHookEx(hHk, nCode, LWParam, LLParam);
18 Exit;
19 end
20 else
21 begin
22 y := 0;
23 case LWParam of
24 WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP,WM_SYSKEYUP:
25 begin
26 p:= PKBDLLHOOKSTRUCT(LLParam);
27 if p^.vkCode = VK_LWIN then y:= 1
28 else if p^.vkCode = VK_RWIN then y:= 1
29 else if (p.vkCode = VK_RETURN) and ((p.flags and (KF_ALTDOWN shr 8)) <> 0)
30 and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then y:= 1
31 else if (p.vkCode = VK_ESCAPE) and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then y:= 1
32 else if (p.vkCode = VK_ESCAPE) and ((GetKeyState(VK_MENU) and $8000) <> 0) then y:= 1
33 else if (p.vkCode = 192) and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then y:= 1
34 else if (p.vkCode = VK_TAB) and ((GetKeyState(VK_MENU) and $8000) <> 0) then y:= 1;
35 end;
36 end;
37 if y=1 then
38 Result:=1 //如果为WIN功能键则屏蔽
39 else
40 Result:= CallNextHookEx(hHk, nCode, LWParam, LLParam); //其他键放下一个钩子
41 end
42 end;
43
44
45 //卸载勾子
46 UnHookWindowsHookEx(hHk);
2 function keyHookProc(nCode: Integer; LWParam: WPARAM; LLParam: LPARAM): LRESULT; stdcall;
3
4 var
5 hHk :HHOOK;
6
7 //创建勾子
8 hHk:= SetWindowsHookEx(13, @keyHookProc, HInstance, 0);
9
10 function keyHookProc(nCode: Integer; LWParam: WPARAM; LLParam: LPARAM): LRESULT;//调用键盘钩子,屏蔽功能键
11 var
12 p: PKBDLLHOOKSTRUCT;
13 y: integer;
14 begin
15 if nCode < 0 then
16 begin
17 Result:= CallNextHookEx(hHk, nCode, LWParam, LLParam);
18 Exit;
19 end
20 else
21 begin
22 y := 0;
23 case LWParam of
24 WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP,WM_SYSKEYUP:
25 begin
26 p:= PKBDLLHOOKSTRUCT(LLParam);
27 if p^.vkCode = VK_LWIN then y:= 1
28 else if p^.vkCode = VK_RWIN then y:= 1
29 else if (p.vkCode = VK_RETURN) and ((p.flags and (KF_ALTDOWN shr 8)) <> 0)
30 and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then y:= 1
31 else if (p.vkCode = VK_ESCAPE) and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then y:= 1
32 else if (p.vkCode = VK_ESCAPE) and ((GetKeyState(VK_MENU) and $8000) <> 0) then y:= 1
33 else if (p.vkCode = 192) and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then y:= 1
34 else if (p.vkCode = VK_TAB) and ((GetKeyState(VK_MENU) and $8000) <> 0) then y:= 1;
35 end;
36 end;
37 if y=1 then
38 Result:=1 //如果为WIN功能键则屏蔽
39 else
40 Result:= CallNextHookEx(hHk, nCode, LWParam, LLParam); //其他键放下一个钩子
41 end
42 end;
43
44
45 //卸载勾子
46 UnHookWindowsHookEx(hHk);