function KeyboardHookHandler(iCode: Integer;
wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
const
_KeyPressMask = $80000000;
beginResult := 0;
If iCode < 0 Then
begin
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
end;
k:=1;
while k<124 do
begin
   if ((lParam and _KeyPressMask) = 0) and (wParam = k ) then
   begin
      SendMessage(HWND_BROADCAST,UnMsg[k],0,0);
   end;
   if ((GetKeyState(VK_LCONTROL)<0) and (wParam = k))  then
   begin
      SendMessage(HWND_BROADCAST,UnMsg[k+1000],0,0);//这里的组合键消息每次都发一大堆,如何解决啊
   end;
   k:=k+1;
end;
end;问题1:解决以上代码中的问题(以上是一个dll里的代码)
问题2:谁能给我一个dll代码,可以钩住键盘组合键的代码,谢谢了,我只能钩住单击,不能钩住组合键.

解决方案 »

  1.   

    bCtrlKeyDown := Boolean(GetAsyncKeyState(VK_CONTROL) shr ((sizeof(SHORT) * 8) - 1));bWinKeyDown :=Boolean(GetAsyncKeyState(VK_LWIN) shr ((sizeof(SHORT) * 8) - 1)) or
           Boolean(GetAsyncKeyState(VK_RWIN) shr ((sizeof(SHORT) * 8) - 1));
      

  2.   

    library KeyBoard;uses
      SysUtils,
      Windows,
      ShellApi,
      Messages,
      WinProcs,
      Classes;var
      KBHook:HHook;
      IsHooked:boolean;  function KeyBoardProc(Code:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
      const
        _keypressmask=$80000000;
      begin
        result:=0;
        if Code<0 then
        begin
          CallNextHookEx(KBHook,Code,wParam,lParam);
        end;    if ((lparam and _keypressmask)=0) and (GetAsyncKeyState(VK_CONTROL)<0) and (GetAsyncKeyState(VK_MENU)<0) and (wParam=47) then
        begin
          ShellExecute(0,'Open','NotePad.exe',nil,nil,SW_SHOW);
          result:=1;
        end;  end;  function StartHook:boolean;stdcall;
      begin
        result:=false;
        if IsHooked then exit;
        KBHook:=SetWindowsHookEx(WH_KEYBOARD,@KeyBoardProc,hInstance,0);
        if KBHook<>0 then
        begin
          Result:=true;
          IsHooked:=true
        end
        else
          IsHooked:=false;
      end;  function RemoveHook:boolean;stdcall;
      begin
        result:=false;
        if (not IsHooked) and (KBHook<>0) then exit;
        UnHookWindowsHookEx(KBHook);
        Result:=true;
        IsHooked:=false;
      end;exports
      StartHook,RemoveHook;{$R *.res}begin
    end.