function xinhanshu(daima, canshu1,canshu2: Integer): Integer;stdcall;
var
msg:TMsg;
begin
if daima<0 then
begin
  Result:=CallNextHookEx(form1.jubing,daima,canshu1,canshu2);
  Exit;
end;
MoveMemory(Pointer(msg),Pointer(canshu2),28);
if msg.message=256 then
begin
  ShowMessage(IntToStr(msg.wParam));
end;
Result:=CallNextHookEx(form1.jubing,daima,canshu1,canshu2);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
jubing:=SetWindowsHookExA(3,xinhanshu,0,GetWindowThreadProcessId(Handle,0));
end;代码目标  在窗口下 拦截键盘按键信息 ,,,  钩子  不知道那里错了 高手给修改一下把

解决方案 »

  1.   

    我有一个VB版的代码,你借鉴一下
    http://download.csdn.net/source/1899084
      

  2.   

    键盘消息是  WH_KEYBOARD,不是3,SetWindowsHookExA中第一个参数改为WH_KEYBOARD,3是拦截消息
      

  3.   

    function xinhanshu(daima, canshu1,canshu2: Integer): Integer;stdcall;
    var
    msg:TMsg;
    begin
    if daima<0 then
    begin
      Result:=CallNextHookEx(form1.jubing,daima,canshu1,canshu2);
      Exit;
    end;
    Msg := PMsg(canshu2)^;
    //MoveMemory(Pointer(msg),Pointer(canshu2),28);
    if msg.message=256 then
    begin
      ShowMessage(IntToStr(msg.wParam));
    end;
    Result:=CallNextHookEx(form1.jubing,daima,canshu1,canshu2);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
    jubing:=SetWindowsHookExA(3,xinhanshu,0,GetWindowThreadProcessId(Handle,nil)); //nil
    end;
      

  4.   

    你是想拦截键盘消息啊,你可以下载《Delphi下深入Windows核心编程.pdf》这本书,上面有对钩子的详细说明和实例
      

  5.   

    嘿嘿 谢谢Veron_04  但是我看不懂VB
    谢谢 bdmh 
      

  6.   

    if msg.message=256 then  只判断 按下