以上几个事件的Key参数即是键值!

解决方案 »

  1.   

    可以用以下几种方法获取:
    1.重载application的OnMessagae事件
    2.重载Form的wndProc虚拟对象方法
    3.重载Form的DefaultHandle虚拟对象方法。
    4.重载WMKeyDown消息响应。
    5.重载KeyDwon对象方法。具体应用可以用下例:
    (这个例子演试的是MouseDown,你可以改为KeyDown)
    unit ListMsg;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TfrmListMsg = class(TForm)
        ListBox1: TListBox;
        btnClear: TButton;
        procedure btnClearClick(Sender: TObject);
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        procedure ApplicationMessage(var Msg: TMsg; var Handled: Boolean);
        procedure WndProc(var Message: TMessage); override;
        procedure DefaultHandler(var Message); override;
        procedure WMLButtonDown(var Message: TWMMouse); message WM_LButtonDown;
        procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
        { Public declarations }
      end;var
      frmListMsg: TfrmListMsg;implementation{$R *.DFM}uses  MsgCreate;procedure TfrmListMsg.btnClearClick(Sender: TObject);
    begin
    //  ListBox1.Items.Clear;
    end;procedure TfrmListMsg.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      if Button = mbLeft then
        ListBox1.Items.Add (Format ('%s in [%d, %d]', ['FormMouseDown', X, Y]));
    end;procedure TfrmListMsg.WndProc(var Message: TMessage);
    begin
      if Message.Msg = WM_LButtonDown then
        Listbox1.Items.Add (Format ('%s in [%d, %d]',
          ['WndProc', LoWord(Message.LParam), HiWord(Message.LParam)]));
      inherited;
    end;procedure TfrmListMsg.DefaultHandler(var Message);
    begin
      with TMessage(Message) do
        if Msg = WM_LButtonDown then
          Listbox1.Items.Add(Format ('%s in [%d, %d]',
            ['DefaultHandler', LoWord(LParam), HiWord(LParam)]));
      inherited;
    end;procedure TfrmListMsg.WMLButtonDown(var Message: TWMMouse);
    begin
      Listbox1.Items.Add(Format( '%s in [%d, %d]', ['WMLButtonDown', Message.XPos, Message.YPos]));
      inherited;
    end;procedure TfrmListMsg.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      if Button = mbLeft then
        Listbox1.Items.Add(Format('%s in [%d, %d]', ['MouseDown', X, Y]));
      inherited;
    end;procedure TfrmListMsg.ApplicationMessage(var Msg: TMsg; var Handled: Boolean);
    begin
      if (Msg.message = WM_LButtonDown) and (Msg.hwnd = Handle) then
        ListBox1.Items.Add(Format('%s in [%d, %d]',
          ['ApplicationMessage', LoWord(Msg.lParam), HiWord(Msg.lParam)]));
      if (Msg.message = WM_LButtonDown) and (Msg.hwnd = btnClear.Handle) then
        Listbox1.Items.Add(Format('Button Click: [%d, %d]',
          [LoWord(Msg.lParam), HiWord(Msg.lParam)]));
      Handled := False;
    end;procedure TfrmListMsg.FormCreate(Sender: TObject);
    begin
      Application.OnMessage := ApplicationMessage;
    end;end.
      

  2.   

    showmessage(key)
    或showmssage(inttostr(key))
    不就知道了。