delphi怎么设单字母(不加Alt的)做按钮快捷键

来源:百度知道 编辑:UC知道 时间:2024/06/19 09:55:26
就是form中只有两个按钮,把它们的快捷键设为V和X(不加Alt或Ctrl或Shift),怎么弄?(不是“(&V)”法)

//Form的Create事件,把KeyPreview属性改为true,接受键盘事件
procedure TForm1.FormCreate(Sender: TObject);
begin
KeyPreview := true;
end;

//Form的KeyPress事件
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if (Key = #86) or (Key = #118) then //当按下的是小写或大写v时就单击button1
button1.Click;
if (Key = #88) or (Key = #120) then //当按下的是小写或大写x时就单击button2
button2.Click;
end;