不知如何辨别同时按下两个键!单个就会;) procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if ord(Key)=16 then showmessage('按了Shift键'); if ord(Key)=17 then showmessage('按了Ctrl键');end;
if (ssctrl in shift) and (key =VK_Shift) then// 如果按的键是Ctrl+Shift showmessage('哈哈,按下了Ctrl+Shift'); //空格类似
我来总结一下给你个直接的例子: { D7 调试通过 } procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (ssShift in Shift) and (ssCtrl in Shift) then if key = $20 then form1.Caption:='Ctrl+Shift+[ ]'; end;
OnKeyPress只能够响应具有标准ASCII码的键盘事件,比如数字键,字母键;
而OnKeyDown可以响应非标准ASCII码的键盘事件,比如[Shift]键,功能键F1-F12
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if ord(Key)=16 then
showmessage('按了Shift键');
if ord(Key)=17 then
showmessage('按了Ctrl键');end;
showmessage('哈哈,按下了Ctrl+Shift'); //空格类似
{ D7 调试通过 }
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssShift in Shift) and (ssCtrl in Shift) then
if key = $20 then form1.Caption:='Ctrl+Shift+[ ]';
end;