📄 鼠标移动控件-自动.txt
字号:
1.在左边的对象观察器(Object Inspector)工具栏中翻到事件(Events)页
找到键盘事件(OnKeyDown)
2.双击它生成键盘事件,并添加代码,在窗体Form1的标题上显示按键的值
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Form1.Caption:=IntToStr(Key);
end;
运行后,试按空格键和左、上、右、下4个方向键,在窗体Form1的标题上就显示它们的值分别为32、37、38、39、40
3.现在把键盘事件的代码改为如下:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=32 then Label1.Caption:='停止';
if Key=37 then Label1.Caption:='向左';
if Key=38 then Label1.Caption:='向上';
if Key=39 then Label1.Caption:='向右';
if Key=40 then Label1.Caption:='向下';
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -