触发顺序OnKeyDown -> OnKeyPress -> OnKeyUp
OnKeyPressr当按下一个ASCII的字时有效,对于其他没有反应.
//根据上下左右来改变图的位置
if key = vk_up then
image1.Top :=image1.top-32
else if key = vk_down then
image1.Top :=image1.top+32
else if key = vk_left then
image1.left :=image1.left-32
else if key = vk_right then
image1.left :=image1.left+32;
补充
//自己看吧
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key in [''0''..''9''] then
ShowMessage(''按下0至9'');
end;