unit HookUnit;
interface
uses
Windows, Messages;
var
hNextHookProc: HHook;//保存SetWindowsHookEx的返回值
procSaveExit: Pointer;
function KeyboardHookHandler(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall; export;
function EnableHotKeyHook: BOOL; export;//安装钩子
function DisableHotKeyHook: BOOL; export;//卸载钩子
procedure HotKeyHookExit; far;
implementation
function KeyboardHookHandler(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall; export;
const
_KeyPressMask=$80000000;//键盘掩码常量
begin
Result:=0;
If iCode < 0 Then //根据SDK说明,若iCode小于0,调用CallNextHookEx并返回
begin
Result:=CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
end;
// 监测是否按下了Ctrl+X、Ctrl+V、Ctrl+C这三个组合键,若按下则退出,不响应事件
if ((lParam and _KeyPressMask) = 0) and(GetKeyState(vk_control) <0)
and ((wParam = Ord('X'))or(wParam = Ord('V'))or(wParam = Ord('C')))then
begin
Result:=1;
Exit;
end;
end;
function EnableHotKeyHook: BOOL; export;
begin
Result := False;//初始化返回值
if hNextHookProc<>0 then//如果已经注册,直接退出
Exit;
//挂上键盘钩子,同时传回值必须保留下来,免得Hook呼叫链结断掉
hNextHookProc:=SetWindowsHookEx(WH_KEYBOARD,KeyboardHookHandler,HInstance,0);
//注册hook
Result:=hNextHookProc <> 0;//通过返回值确定是否注册成功
end;
function DisableHotKeyHook: BOOL; export;
begin
if hNextHookProc<>0 then
begin
UnhookWindowshookEx(hNextHookProc);//解除Keyboard Hook
hNextHookProc:=0;//恢复标志
end;
Result:=hNextHookProc=0;//返回是否注销成功
end;
procedure HotKeyHookExit;
begin
if hNextHookProc<>0 then DisableHotKeyHook;//如果忘了解除HOOK,自动代理解除动作
ExitProc:=procSaveExit;
end;
end. 改为当按下ctrl+shift和ctrl+空格
就是屏掉这两组快捷键,且不要退出,只是停止它们,达到无映应就行了?
interface
uses
Windows, Messages;
var
hNextHookProc: HHook;//保存SetWindowsHookEx的返回值
procSaveExit: Pointer;
function KeyboardHookHandler(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall; export;
function EnableHotKeyHook: BOOL; export;//安装钩子
function DisableHotKeyHook: BOOL; export;//卸载钩子
procedure HotKeyHookExit; far;
implementation
function KeyboardHookHandler(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall; export;
const
_KeyPressMask=$80000000;//键盘掩码常量
begin
Result:=0;
If iCode < 0 Then //根据SDK说明,若iCode小于0,调用CallNextHookEx并返回
begin
Result:=CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
end;
// 监测是否按下了Ctrl+X、Ctrl+V、Ctrl+C这三个组合键,若按下则退出,不响应事件
if ((lParam and _KeyPressMask) = 0) and(GetKeyState(vk_control) <0)
and ((wParam = Ord('X'))or(wParam = Ord('V'))or(wParam = Ord('C')))then
begin
Result:=1;
Exit;
end;
end;
function EnableHotKeyHook: BOOL; export;
begin
Result := False;//初始化返回值
if hNextHookProc<>0 then//如果已经注册,直接退出
Exit;
//挂上键盘钩子,同时传回值必须保留下来,免得Hook呼叫链结断掉
hNextHookProc:=SetWindowsHookEx(WH_KEYBOARD,KeyboardHookHandler,HInstance,0);
//注册hook
Result:=hNextHookProc <> 0;//通过返回值确定是否注册成功
end;
function DisableHotKeyHook: BOOL; export;
begin
if hNextHookProc<>0 then
begin
UnhookWindowshookEx(hNextHookProc);//解除Keyboard Hook
hNextHookProc:=0;//恢复标志
end;
Result:=hNextHookProc=0;//返回是否注销成功
end;
procedure HotKeyHookExit;
begin
if hNextHookProc<>0 then DisableHotKeyHook;//如果忘了解除HOOK,自动代理解除动作
ExitProc:=procSaveExit;
end;
end. 改为当按下ctrl+shift和ctrl+空格
就是屏掉这两组快捷键,且不要退出,只是停止它们,达到无映应就行了?
谁帮改一下,达到:改为当按下ctrl+shift和ctrl+空格
就是屏掉这两组快捷键,且不要退出,只是停止它们,达到无映应就行了?
and ((wParam = Ord('X'))or(wParam = Ord('V'))or(wParam = Ord('C')))then
检查一下这一句有没有问题
希望给出完整的dll的代码,当然是测试通过的
就是屏掉这两组快捷键,且不要退出,只是停止它们,达到无映应就行了?
自己顶一下?
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;
implementationfunction 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.
我在学hook
function KeyboardHookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; export;
const
_KeyPressMask = $80000000; //键盘掩码常量
begin
Result := 0;
if iCode < 0 then //根据SDK说明,若iCode小于0,调用CallNextHookEx并返回
begin
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
end;
//下面代码理论上是屏蔽任何键,但是Ctrl+Shift,Ctrl+Shfit+Del都照样有效,我想
//Ctrl+Shift,Ctrl+Shfit+Del...是M$对Windows特别设定的键屏蔽不了
Result := 1;
//监测是否按下了Ctrl+X、Ctrl+V、Ctrl+C这三个组合键,若按下则退出,不响应事件
{if ((lParam and _KeyPressMask) = 0) and (GetKeyState(vk_control) < 0)
and ((wParam = Ord('X')) or (wParam = Ord('V')) or (wParam = Ord('C'))) then
begin
Result := 1;
Exit;
end; }
end;
另外有没有其它办法,达到屏蔽ctrl+shift和ctrl+空格 的方法?
function KeyboardHookHandler(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall; export;
里面的函数能讲一下吗?
Windows, Messages, StdCtrls, Classes, Forms;var
hNextHookProc: HHook; //保存SetWindowsHookEx的返回值
procSaveExit: Pointer;function KeyboardHookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; export;
function EnableHotKeyHook: BOOL; export; //安装钩子
function DisableHotKeyHook: BOOL; export; //卸载钩子
procedure HotKeyHookExit; far;
implementationfunction KeyboardHookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; export;
var
ShiftState: TShiftState;
begin
Result := 0;
if iCode < 0 then //根据SDK说明,若iCode小于0,调用CallNextHookEx并返回
begin
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
end; //此函数KeyDataToShiftState由Delphi的Forms单元提供 --- by BlazingFire
ShiftState := KeyDataToShiftState(lParam);
//屏蔽Ctrl+X、Ctrl+V、Ctrl+C、Ctrl+Space
if ([ssCtrl] = ShiftState) and
(wParam in [Ord('X'), Ord('V'), Ord('C'), Ord(' ')]) then
begin
Result := 1;
Exit;
end;
end;function EnableHotKeyHook: BOOL; export;
begin
Result := False; //初始化返回值
if hNextHookProc <> 0 then //如果已经注册,直接退出
Exit;
//挂上键盘钩子,同时传回值必须保留下来,免得Hook呼叫链结断掉
hNextHookProc := SetWindowsHookEx(WH_KEYBOARD, KeyboardHookHandler, HInstance, 0);
//注册hook
Result := hNextHookProc <> 0; //通过返回值确定是否注册成功
end;function DisableHotKeyHook: BOOL; export;
begin
if hNextHookProc <> 0 then
begin
UnhookWindowshookEx(hNextHookProc); //解除Keyboard Hook
hNextHookProc := 0; //恢复标志
end;
Result := hNextHookProc = 0; //返回是否注销成功
end;procedure HotKeyHookExit;
begin
if hNextHookProc <> 0 then DisableHotKeyHook; //如果忘了解除HOOK,自动代理解除动作
ExitProc := procSaveExit;
end;
end.
这样讲吧:首先你要知道键盘钩子的必须在Dll中实现,exe中调用才能起作用,只有这样钩子才能正在的作用(至少我知道的是这样)!
下面我分一屏一屏的贴出所有的代码
1)DLL 单元library HookDll;uses
Windows,
HookUnit in 'HookUnit.pas';procedure _DllProc(Reason: Integer);
begin
//DLL卸载是关闭钩子
if Reason = DLL_PROCESS_DETACH then
DisableHotKeyHook;
end;exports
EnableHotKeyHook, DisableHotKeyHook;
begin
DLLProc := @_DllProc
end.
Windows, Messages, StdCtrls, Classes, Forms;var
hNextHookProc: HHook; //保存SetWindowsHookEx的返回值function EnableHotKeyHook: BOOL; export; //安装钩子
function DisableHotKeyHook: BOOL; export;implementationfunction KeyboardHookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; export;
var
ShiftState: TShiftState;
begin
Result := 0;
if iCode < 0 then //根据SDK说明,若iCode小于0,调用CallNextHookEx并返回
begin
Result := CallNextHookEx(0, iCode, wParam, lParam);
Exit;
end; //此函数KeyDataToShiftState由Delphi的Forms单元提供 --- by BlazingFire
ShiftState := KeyDataToShiftState(lParam);
//屏蔽Ctrl+X、Ctrl+V、Ctrl+C、Ctrl+Space
if ([ssCtrl] = ShiftState) and
(wParam in [Ord('X'), Ord('V'), Ord('C'), Ord(' ')]) then
begin
Result := 1;
Exit;
end;
end;function EnableHotKeyHook: BOOL; export;
begin
Result := False; //初始化返回值
if hNextHookProc <> 0 then //如果已经注册,直接退出
Exit;
//挂上键盘钩子,同时传回值必须保留下来,免得Hook呼叫链结断掉
hNextHookProc := SetWindowsHookEx(WH_KEYBOARD, KeyboardHookHandler, HInstance, 0);
//注册hook
Result := hNextHookProc <> 0; //通过返回值确定是否注册成功
end;function DisableHotKeyHook: BOOL; export;
begin
if hNextHookProc <> 0 then
begin
UnhookWindowshookEx(hNextHookProc); //解除Keyboard Hook
hNextHookProc := 0; //恢复标志
end;
Result := hNextHookProc = 0; //返回是否注销成功
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TfrmMain = class(TForm)
Install: TButton; //安装钩子按钮
Uninstall: TButton; //卸载钩子按钮
procedure InstallClick(Sender: TObject);
procedure UninstallClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;function EnableHotKeyHook: BOOL; external 'HookDll.dll';
function DisableHotKeyHook: BOOL; external 'HookDll.dll';var
frmMain: TfrmMain;implementation{$R *.dfm}procedure TfrmMain.InstallClick(Sender: TObject);
begin
EnableHotKeyHook;
end;procedure TfrmMain.UninstallClick(Sender: TObject);
begin
DisableHotKeyHook;
end;end.
再有我会在代码中调用dll,dll的编译生成和在代码中的调用,步骤完全正确
因为我以前也在网上下载过dll的代码,编译后调用,完全没有问题
你的代码,确实不能屏掉ctrl+空格
因为其它三组都屏掉了,就空格这一组,没有屏掉
我机器上的输入法是Ctrl+Shift切换,这个是屏蔽不了。如果Ctrl+Space也屏不了,只能这样理解(猜想?!)的输入法的热键可能比我们的钩子程序执行级别要高。另外Ctrl+Alt+Del(启动任务管理器)也没办法屏蔽,即使你在KeyboardProc里直接Result := 1也没有用!
如果上面的能屏掉,哪我指的哪两组应该也不是问题了
Windows,
SysUtils,
Classes,
Messages,
Dialogs;type
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
KBDLLHOOKSTRUCT = record
vkCode: DWORD;
ScanCode: DWORD;
Flags: DWORD;
Time: DWORD;
dwExtraInfo: DWORD;
end;var
hhk: HHOOK;{$R *.res}function HookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
p: PKBDLLHOOKSTRUCT;
y: Integer;
begin
y:= 0;
if nCode = HC_ACTION then
begin
case WParam of
WM_KEYDOWN, WM_SYSKEYDOWN:
begin
p:= PKBDLLHOOKSTRUCT(Lparam);
if p^.vkCode = 160 then y:= 1;
if p^.vkCode = 32 then y:= 1;
end;
WM_KEYUP, WM_SYSKEYUP:
begin
p:= PKBDLLHOOKSTRUCT(Lparam);
if p^.vkCode = 160 then y:= 1;
if p^.vkCode = 32 then y:= 1;
end;
end;
end;
if y = 1 then Result:= 1 else Result:= CallNextHookEx(hHk,nCode,WParam,LParam);
end;function InstKeyBoard: Boolean; stdcall; export;
begin
if hhk <> 0 then
begin
Result:= False;
Exit;
end;
hhk:= SetWindowsHookEx(13, @HookProc, HINSTANCE, 0);
Result:= hhk <> 0;
end;function UnInstKeyBoard: Boolean; stdcall; export;
begin
if hhk <> 0 then
begin
UnhookWindowshookEx(hhk);
hhk:= 0;
end;
Result:= hhk = 0;
end;exports
InstKeyBoard,
UnInstKeyBoard;begin
end.代码给你,分给我
还定义了一个常量
const
WH_KEYBOARD_LL = 13;
Windows,
SysUtils,
Classes,
Messages,
Dialogs; type
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
KBDLLHOOKSTRUCT = record
vkCode: DWORD;
ScanCode: DWORD;
Flags: DWORD;
Time: DWORD;
dwExtraInfo: DWORD;
end; var
hhk: HHOOK; {$R *.res} function HookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
p: PKBDLLHOOKSTRUCT;
y: Integer;
begin
y:= 0;
if nCode = HC_ACTION then
begin
case WParam of
WM_KEYDOWN, WM_SYSKEYDOWN:
begin
p:= PKBDLLHOOKSTRUCT(Lparam);
if p^.vkCode = 160 then y:= 1;
if p^.vkCode = 161 then y:= 1;
if p^.vkCode = 32 then y:= 1; end;
WM_KEYUP, WM_SYSKEYUP:
begin
p:= PKBDLLHOOKSTRUCT(Lparam);
if p^.vkCode = 160 then y:= 1;
if p^.vkCode = 161 then y:= 1;
if p^.vkCode = 32 then y:= 1;
end;
end;
end;
if y = 1 then Result:= 1 else Result:= CallNextHookEx(hHk,nCode,WParam,LParam);
end; function InstKeyBoard: Boolean; stdcall; export;
begin
if hhk <> 0 then
begin
Result:= False;
Exit;
end;
hhk:= SetWindowsHookEx(13, @HookProc, HINSTANCE, 0);
Result:= hhk <> 0;
end; function UnInstKeyBoard: Boolean; stdcall; export;
begin
if hhk <> 0 then
begin
UnhookWindowshookEx(hhk);
hhk:= 0;
end;
Result:= hhk = 0;
end; exports
InstKeyBoard,
UnInstKeyBoard; begin
end.
WM_KEYDOWN, WM_SYSKEYDOWN: //测试当按键被按下
begin
p:= PKBDLLHOOKSTRUCT(Lparam);
if p^.vkCode = 160 then y:= 1; //屏蔽左 Ctrl + Shift
if p^.vkCode = 161 then y:= 1; //屏蔽右 Ctrl + Shift
if p^.vkCode = 32 then y:= 1; //屏蔽 Ctrl + 空格 end;
WM_KEYUP, WM_SYSKEYUP: //测试当放开按键
begin
p:= PKBDLLHOOKSTRUCT(Lparam);
if p^.vkCode = 160 then y:= 1; //屏蔽左 Ctrl + Shift
if p^.vkCode = 161 then y:= 1; //屏蔽右 Ctrl + Shift
if p^.vkCode = 32 then y:= 1; //屏蔽 Ctrl + 空格
end;
end;
Windows,
SysUtils,
Classes,
Messages;type
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
KBDLLHOOKSTRUCT = record
vkCode: DWORD;
ScanCode: DWORD;
Flags: DWORD;
Time: DWORD;
dwExtraInfo: DWORD;
end; var
hhk: HHOOK; {$R *.res} function HookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
p: PKBDLLHOOKSTRUCT;
y: Integer;
begin
y:= 0;
if nCode = HC_ACTION then
begin
case WParam of
WM_KEYDOWN, WM_SYSKEYDOWN:
begin
p:= PKBDLLHOOKSTRUCT(Lparam);
if p^.vkCode = 160 then if GetKeyState(162) < 0 then y:= 1;
if p^.vkCode = 161 then if GetKeyState(162) < 0 then y:= 1;
if p^.vkCode = 32 then if GetKeyState(162) < 0 then y:= 1;
end;
WM_KEYUP, WM_SYSKEYUP:
begin
p:= PKBDLLHOOKSTRUCT(Lparam);
if p^.vkCode = 160 then if GetKeyState(162) < 0 then y:= 1;
if p^.vkCode = 161 then if GetKeyState(162) < 0 then y:= 1;
if p^.vkCode = 32 then if GetKeyState(162) < 0 then y:= 1;
end;
end;
end;
if y = 1 then Result:= 1 else Result:= CallNextHookEx(hHk,nCode,WParam,LParam);
end; function InstKeyBoard: Boolean; stdcall; export;
begin
if hhk <> 0 then
begin
Result:= False;
Exit;
end;
hhk:= SetWindowsHookEx(13, @HookProc, HINSTANCE, 0);
Result:= hhk <> 0;
end; function UnInstKeyBoard: Boolean; stdcall; export;
begin
if hhk <> 0 then
begin
UnhookWindowshookEx(hhk);
hhk:= 0;
end;
Result:= hhk = 0;
end; exports
InstKeyBoard,
UnInstKeyBoard; begin
end.谢谢哥们,由于我再次的不细心,又出了个错误,不好意思,上面那个我屏蔽的按键有问题,请不惜再改一下吧~!
Windows,
SysUtils,
Classes,
Messages;type
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
KBDLLHOOKSTRUCT = record
vkCode: DWORD;
ScanCode: DWORD;
Flags: DWORD;
Time: DWORD;
dwExtraInfo: DWORD;
end; var
hhk: HHOOK; {$R *.res} function HookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
p: PKBDLLHOOKSTRUCT;
y: Integer;
begin
y:= 0;
if nCode = HC_ACTION then
begin
case WParam of
WM_KEYDOWN, WM_SYSKEYDOWN:
begin
p:= PKBDLLHOOKSTRUCT(Lparam);
//测试当 160(左 Shift 键) 和 162(左 Ctrl 键) 也按下的同时 触发事件
if p^.vkCode = 160 then if GetKeyState(162) < 0 then y:= 1;
//测试当 161(右 Shift 键) 和 162(左 Ctrl 键) 也按下的同时 触发事件
if p^.vkCode = 161 then if GetKeyState(162) < 0 then y:= 1;
//测试当 32(空格键) 和 162(左 Ctrl 键) 也按下的同时 触发事件
if p^.vkCode = 32 then if GetKeyState(162) < 0 then y:= 1;
//测试当 160(左 Shift 键) 和 163(右 Ctrl 键) 也按下的同时 触发事件
if p^.vkCode = 160 then if GetKeyState(163) < 0 then y:= 1;
//测试当 161(右 Shift 键) 和 163(右 Ctrl 键) 也按下的同时 触发事件
if p^.vkCode = 161 then if GetKeyState(163) < 0 then y:= 1;
//测试当 32(空格键) 和 163(右 Ctrl 键) 也按下的同时 触发事件
if p^.vkCode = 32 then if GetKeyState(163) < 0 then y:= 1;
end;
WM_KEYUP, WM_SYSKEYUP:
begin
p:= PKBDLLHOOKSTRUCT(Lparam);
//测试当 160(左 Shift 键) 和 162(左 Ctrl 键) 也按下的同时 触发事件
if p^.vkCode = 160 then if GetKeyState(162) < 0 then y:= 1;
//测试当 161(右 Shift 键) 和 162(左 Ctrl 键) 也按下的同时 触发事件
if p^.vkCode = 161 then if GetKeyState(162) < 0 then y:= 1;
//测试当 32(空格键) 和 162(左 Ctrl 键) 也按下的同时 触发事件
if p^.vkCode = 32 then if GetKeyState(162) < 0 then y:= 1;
//测试当 160(左 Shift 键) 和 163(右 Ctrl 键) 也按下的同时 触发事件
if p^.vkCode = 160 then if GetKeyState(163) < 0 then y:= 1;
//测试当 161(右 Shift 键) 和 163(右 Ctrl 键) 也按下的同时 触发事件
if p^.vkCode = 161 then if GetKeyState(163) < 0 then y:= 1;
//测试当 32(空格键) 和 163(右 Ctrl 键) 也按下的同时 触发事件
if p^.vkCode = 32 then if GetKeyState(163) < 0 then y:= 1;
end;
end;
end;
if y = 1 then Result:= 1 else Result:= CallNextHookEx(hHk,nCode,WParam,LParam);
end; function InstKeyBoard: Boolean; stdcall; export;
begin
if hhk <> 0 then
begin
Result:= False;
Exit;
end;
hhk:= SetWindowsHookEx(13, @HookProc, HINSTANCE, 0);
Result:= hhk <> 0;
end; function UnInstKeyBoard: Boolean; stdcall; export;
begin
if hhk <> 0 then
begin
UnhookWindowshookEx(hhk);
hhk:= 0;
end;
Result:= hhk = 0;
end; exports
InstKeyBoard,
UnInstKeyBoard; begin
end.