procedure TForm1.FormCreate(Sender: TObject);
begin
keypreview := true; //可以接收键盘操作 先要在软件启动的时候这么做
end;
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
(或你要的Button1KeyPress)
begin
if key = #27 then
begin
Button5.Click;//你要响应的 (这句换成你要的)
end;
end;
button 不用设置,只要button 获得焦点,就可以了
edit
procedure TForm1.Button1KeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then
begin
showmessage('PLMM');
end;
end;
上分上分!
button回车是
procedure TForm1.Button1Click(Sender: TObject);
var msg:Tmsg;
begin
getmessage( msg,self.Handle,0,0);
if Msg.message = WM_KEYUP then
if (msg.wParam)=VK_RETURN then
showmessage('click');
end;
edit的回车是
在edit 的keydown事件中写
if Key = 13 then
begin
end;
edit的回车是
在edit 的onkeypress事件里写
if Key = #13 then
begin
语句
end;
button回车是
先把button的default属性设置为true,然后写下如下代码:
procedure TForm1.Button1Click(Sender: TObject);
var msg:Tmsg;
begin
getmessage( msg,self.Handle,0,0);
if Msg.message = WM_KEYUP then
if (msg.wParam)=VK_RETURN then
showmessage('click');
end;
你要设计好到底是在那里用:
1.KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
key=13
2.KeyPress(Sender: TObject; var Key: Char);
key=#13
这两个参数不一样的
[red]procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
Button1Click(Sender);
end;[/red].[blue]上面的是可以的,你要把KeyPress事件当Button1Click(Sender);[/blue]