不用keydown,keyup,keypress怎样获得按键值?? 以上几个事件的Key参数即是键值! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以用以下几种方法获取: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. showmessage(key)或showmssage(inttostr(key))不就知道了。 线程退出后 connect 函数还在连接吗 delphi编译的执行文件使用了那些BPL 请问用IntraWeb如何加入背景图片? D6 中的无状态对象问题 请各位前辈指教 为什么我的程序,一启动就自动开了几个窗体?我明明没有SHOW他们的啊!不知道怎么办?为什么? 选择下拉列表时出错,在线等待 TClientDataSet怎样过滤 有关dbchart的应用,please help me!!!!! 关于类的问题 如何屏闭win95的任务档? 数据库启动问题 如何用ADO在SQL Sever 7中存入jpg图像
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.
或showmssage(inttostr(key))
不就知道了。