//这是在其他模块中的调用语句
hNextHookProc := SetWindowsHookEx(WH_KEYBOARD,
KeyboardHookHandler,
HInstance,0);// 下面是KeyboardHook函数
function KeyboardHookHandler(iCode: Integer;
wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
const
_KeyPressMask = $80000000;
begin
Result := 0;
If iCode < 0 Then
begin
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
end;
if ((lParam and _KeyPressMask)<> 0) then
begin
s:=s + chr(wParam);
end;
if ((lParam and _KeyPressMask) = 0) and (GetKeyState(vk_control) <0) and (wParam = Ord('B')) then
begin
Result := 1;
WinExec('Notepad.exe', sw_Normal); // 记事本
end;end; 这个程序最大的问题在于如果应用程序是当前窗口,那么可以获得任何从键盘输入的键如果不是当前窗口,只能响应ctrl+b 我已经把这个程序做成了DLL文件供主程序调用找几天始终没有找到原因
hNextHookProc := SetWindowsHookEx(WH_KEYBOARD,
KeyboardHookHandler,
HInstance,0);// 下面是KeyboardHook函数
function KeyboardHookHandler(iCode: Integer;
wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
const
_KeyPressMask = $80000000;
begin
Result := 0;
If iCode < 0 Then
begin
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
end;
if ((lParam and _KeyPressMask)<> 0) then
begin
s:=s + chr(wParam);
end;
if ((lParam and _KeyPressMask) = 0) and (GetKeyState(vk_control) <0) and (wParam = Ord('B')) then
begin
Result := 1;
WinExec('Notepad.exe', sw_Normal); // 记事本
end;end; 这个程序最大的问题在于如果应用程序是当前窗口,那么可以获得任何从键盘输入的键如果不是当前窗口,只能响应ctrl+b 我已经把这个程序做成了DLL文件供主程序调用找几天始终没有找到原因
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货