Form1.keypreview:=true;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key=33 then showmessage('up'); if key=34 then showmessage('down'); end;
不用消息,一楼的对,KeyDown过程本身就提供了键码识别。
直接使用虚拟键就是,不用具体比较它的ASCII值。主FORM的keypreview属性要为trueprocedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Shift>=[ssalt]// and (activecontrol.Name='button1') then if key=VK_UP then begin activecontrol.Top:=activecontrol.top-10; end; end;
Shift: TShiftState);
begin
if key=33 then showmessage('up');
if key=34 then showmessage('down');
end;
Shift: TShiftState);
begin
if Shift>=[ssalt]// and (activecontrol.Name='button1')
then if key=VK_UP then
begin
activecontrol.Top:=activecontrol.top-10;
end;
end;