如题,谢谢

解决方案 »

  1.   

    我的意思是,怎么获得WH_KEYBOARD类型的钩子里wParam对应的值
      

  2.   

    这段代码去看看,里面有日志钩子的全部的信息,还可以全局捉到键盘的键。
    相信对你有用
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Edit1: TEdit;
        Label1: TLabel;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
      Function KbHook( code: Integer; wparam: Word; lparam: LongInt ): LRESULT;stdcall;
    var
      Form1: TForm1;
      oldHook:Hhook;
    implementation{$R *.dfm}
    Function KbHook( code: Integer; wparam: Word; lparam: LongInt ): LRESULT;stdcall;
    var temp,KeyValue:UINT;
        ks: TkeyBoardState;
    Begin
    result:=0;
    If code < 0 Then
    begin
      result:= CallNextHookEx( oldHook, code, wparam, lparam );
    end
    Else begin
      if pEventMSG(lParam)^.message=WM_KEYDOWN then
      begin
        KeyValue:=pEventMSG(lParam)^.paramL mod 256;
        GetKeyboardState(ks);
        if (KeyValue>=65) and (KeyValue<92)then
        begin
          if (ks[VK_CAPITAL]<>1) then
            if ks[VK_SHIFT]and $80<>0 then
              temp:=KeyValue
            else
              temp:=KeyValue+32
          else
            if ks[VK_SHIFT]and $80<>0 then
              temp:=KeyValue+32
            else
              temp:=KeyValue;
        end
        else if(KeyValue>=96)and(KeyValue<106) then
          temp:=KeyValue-48
        else if(KeyValue>=112)and(KeyValue<124) then
        begin
          Form1.Label1.Caption:='F'+IntTostr(KeyValue-111)+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=13 then
        begin
          Form1.Label1.Caption:='Enter'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=32 then
        begin
          Form1.Label1.Caption:='Space'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=16 then
        begin
          Form1.Label1.Caption:='Shift'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=17 then
        begin
          Form1.Label1.Caption:='Ctrl or Alt'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=20 then
        begin
          Form1.Label1.Caption:='Caps Lock'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=9 then
        begin
          Form1.Label1.Caption:='Tab'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=188 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='<'+': '+INTtoStr(KeyValue)
          else
             Form1.Label1.Caption:=','+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=190 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='>'+': '+INTtoStr(KeyValue)
          else
            Form1.Label1.Caption:='.'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=191 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='?'+': '+INTtoStr(KeyValue)
          else
             Form1.Label1.Caption:='/'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=192 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='~'+': '+INTtoStr(KeyValue)
          else
            Form1.Label1.Caption:='`'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=189 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='_'+': '+INTtoStr(KeyValue)
          else
            Form1.Label1.Caption:='-'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=187 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='+'+': '+INTtoStr(KeyValue)
          else
            Form1.Label1.Caption:='='+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=220 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='|'+': '+INTtoStr(KeyValue)
          else
          Form1.Label1.Caption:='\'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=46 then
        begin
          Form1.Label1.Caption:='Delete'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=35 then
        begin
          Form1.Label1.Caption:='End'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=27 then
        begin
          Form1.Label1.Caption:='ESC'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=8 then
        begin
          Form1.Label1.Caption:='Back Sapce'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=45 then
        begin
          Form1.Label1.Caption:='Insert'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=33 then
        begin
          Form1.Label1.Caption:='Page Up'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=34 then
        begin
          Form1.Label1.Caption:='Page Down'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=36 then
        begin
          Form1.Label1.Caption:='Hone'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=38 then
        begin
          Form1.Label1.Caption:='Up'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=37 then
        begin
          Form1.Label1.Caption:='Left'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=40 then
        begin
          Form1.Label1.Caption:='Down'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=39 then
        begin
          Form1.Label1.Caption:='Right'+': '+INTtoStr(KeyValue);
          exit;
        end
      

  3.   

    else if Keyvalue=107 then
        begin
          Form1.Label1.Caption:='+'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=109 then
        begin
          Form1.Label1.Caption:='-'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=111 then
        begin
          Form1.Label1.Caption:='/'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=106 then
        begin
          Form1.Label1.Caption:='*'+': '+INTtoStr(KeyValue);
          exit;
        end
         else if Keyvalue=219 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='{'+': '+INTtoStr(KeyValue)
          else
          Form1.Label1.Caption:='['+': '+INTtoStr(KeyValue);
          exit;
        end
         else if Keyvalue=221 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='}'+': '+INTtoStr(KeyValue)
          else
          Form1.Label1.Caption:=']'+': '+INTtoStr(KeyValue);
          exit;
        end
         else if Keyvalue=110 then
        begin
          Form1.Label1.Caption:='.'+': '+INTtoStr(KeyValue);
          exit;
        end
         else if Keyvalue=186 then
        begin
        if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:=':'+': '+INTtoStr(KeyValue)
          else
          Form1.Label1.Caption:=';'+': '+INTtoStr(KeyValue);
          exit;
        end
         else if Keyvalue=222 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='”'+': '+INTtoStr(KeyValue)
          else
          Form1.Label1.Caption:='’'+': '+INTtoStr(KeyValue);
          exit;
        end
        else if Keyvalue=49 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='!'+': '+INTtoStr(KeyValue)
          else
          Form1.Label1.Caption:='1'+': '+INTtoStr(KeyValue);
          exit;
        end
         else if Keyvalue=50 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='@'+': '+INTtoStr(KeyValue)
          else
          Form1.Label1.Caption:='2'+': '+INTtoStr(KeyValue);
          exit;
        end
         else if Keyvalue=51 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='#'+': '+INTtoStr(KeyValue)
          else
          Form1.Label1.Caption:='3'+': '+INTtoStr(KeyValue);
          exit;
        end
         else if Keyvalue=52 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='$'+': '+INTtoStr(KeyValue)
          else
          Form1.Label1.Caption:='4'+': '+INTtoStr(KeyValue);
          exit;
        end
         else if Keyvalue=53 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='%'+': '+INTtoStr(KeyValue)
          else
          Form1.Label1.Caption:='5'+': '+INTtoStr(KeyValue);
          exit;
        end
         else if Keyvalue=54 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='^'+': '+INTtoStr(KeyValue)
          else
          Form1.Label1.Caption:='6'+': '+INTtoStr(KeyValue);
          exit;
        end
         else if Keyvalue=55 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='&'+': '+INTtoStr(KeyValue)
          else
          Form1.Label1.Caption:='7'+': '+INTtoStr(KeyValue);
          exit;
        end
         else if Keyvalue=56 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='*'+': '+INTtoStr(KeyValue)
          else
          Form1.Label1.Caption:='8'+': '+INTtoStr(KeyValue);
          exit;
        end
         else if Keyvalue=57 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:='('+': '+INTtoStr(KeyValue)
          else
          Form1.Label1.Caption:='9'+': '+INTtoStr(KeyValue);
          exit;
        end
         else if Keyvalue=48 then
        begin
          if ks[VK_SHIFT]and $80<>0 then
             Form1.Label1.Caption:=')'+': '+INTtoStr(KeyValue)
          else
          Form1.Label1.Caption:='0'+': '+INTtoStr(KeyValue);
          exit;
        end
        else
          temp:=KeyValue;    Form1.Label1.Caption:=char(temp)+': '+INTtoStr(temp);  end;
    end;
    End; // KbHookprocedure TForm1.Button1Click(Sender: TObject);
    begin
     if oldHook=0 then
       oldHook := SetWindowsHookEx( WH_JOURNALRECORD, @KbHook, HInstance, 0);end;
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      If oldHook <> 0 Then
      Begin
      UnhookWindowshookEx( oldHook );
      oldHook := 0;
      End; // Ifend;end.
      

  4.   

    KeyValue:=pEventMSG(lParam)^.paramL mod 256
    这句有用
    我找到了,谢谢!