unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,shellapi;type
  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
    Button1: TButton;
    Edit1: TEdit;
    Memo1: TMemo;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
//    function KeyboardHook(nCode: Integer; wParam: WPARAM;
//  lParam: LPARAM):LResult stdcall;
  private
    { Private declarations }
  public
{ Public declarations }
  end;var
  Form1: TForm1;
  winhook :Hhook;
implementation{$R *.dfm}
function KeyboardHook(nCode: Integer; wParam: WPARAM;lParam: LPARAM): LResult;
begin
  {if we can process the hook information...}
  Form1.Memo1.Lines.Add(inttostr(wparam)+inttostr(lParam));
  if (nCode>-1) then
    {...was the TAB key pressed?}
    if (wParam=VK_TAB) then
    begin
      {if so, output a beep sound}
      MessageBeep(0);      {indicate that the message was processed}
      Result := 1;
    end
    else
    {...was the RETURN key pressed?}    if (wParam=VK_return) then
    begin
      showmessage('asdfsd');
      {if so, and if the key is on the up stroke, cause
       the focus to move to the next control}
      if ((lParam shr 31)=1) then
        form1.Perform(WM_NEXTDLGCTL, 0, 0);      {indicate that the message was processed}
      Result := 1;
    end
    else
      {otherwise, indicate that the message was not processed.}      Result := 0
  else
    {we must pass the hook information to the next hook in the chain}
    Result := CallNextHookEx(WinHook, nCode, wParam, lParam);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnHookWindowsHookEx(WinHook);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
WinHook:=SetWindowsHookEx(WH_keyboard,@KeyboardHook,0,GetCurrentThreadID);end;end.
为什么取得都是WPARAM是39,而且一点都不改变,我是在WIN2000里面写的程序DELPHI7

解决方案 »

  1.   

    还是给你贴出来吧,csdn怎么整的,问题显示不全,连滚动条都没有!///////////////////
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,shellapi;type
      TForm1 = class(TForm)
        CheckBox1: TCheckBox;
        Button1: TButton;
        Edit1: TEdit;
        Memo1: TMemo;
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormCreate(Sender: TObject);
    //    function KeyboardHook(nCode: Integer; wParam: WPARAM;
    //  lParam: LPARAM):LResult stdcall;
      private
        { Private declarations }
      public
    { Public declarations }
      end;var
      Form1: TForm1;
      winhook :Hhook;
    implementation{$R *.dfm}
    function KeyboardHook(nCode: Integer; wParam: WPARAM;lParam: LPARAM): LResult;
    begin
      {if we can process the hook information...}
      Form1.Memo1.Lines.Add(inttostr(wparam)+inttostr(lParam));
      if (nCode>-1) then
        {...was the TAB key pressed?}
        if (wParam=VK_TAB) then
        begin
          {if so, output a beep sound}
          MessageBeep(0);      {indicate that the message was processed}
          Result := 1;
        end
        else
        {...was the RETURN key pressed?}    if (wParam=VK_return) then
        begin
          showmessage('asdfsd');
          {if so, and if the key is on the up stroke, cause
           the focus to move to the next control}
          if ((lParam shr 31)=1) then
            form1.Perform(WM_NEXTDLGCTL, 0, 0);      {indicate that the message was processed}
          Result := 1;
        end
        else
          {otherwise, indicate that the message was not processed.}      Result := 0
      else
        {we must pass the hook information to the next hook in the chain}
        Result := CallNextHookEx(WinHook, nCode, wParam, lParam);
    end;
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
    UnHookWindowsHookEx(WinHook);
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    WinHook:=SetWindowsHookEx(WH_keyboard,@KeyboardHook,0,GetCurrentThreadID);end;end.
    为什么取得都是WPARAM是39,而且一点都不改变,我是在WIN2000里面写的程序DELPHI7
      

  2.   

    function KeyboardHook(nCode: Integer; wParam: WPARAM;lParam: LPARAM): LResult;stdcall;//<----一定要加上!!!
      

  3.   

    OK
    搞定了,能否告书我STDCALL是什么意思?
      

  4.   

    Stdcall为标准参数调用方式,用其他语言如C++,Java调用你用Delphi写的DLL,需要设为stdcall.Delphi默认是Register调用方式。