我使用此代码测试同时按下 3 个字母但IF
跳到外面case
!
....
private
FValidKeyCombo: boolean
....
procedure MyForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if FValidKeyCombo and (Shift = [ssAlt]) then
case Key of
Ord('N'): //New
if (GetKeyState(Ord('C')) and $80) = $80 then
btn1.OnClick(nil)
else if (GetKeyState(Ord('T')) and $80) = $80 then
btn2.OnClick(nil)
else if (GetKeyState(Ord('Q')) and $80) = $80 then
btn3.OnClick(nil)
else if (GetKeyState(Ord('W')) and $80) = $80 then
btn3.OnClick(nil);
Ord('E'): //New
if (GetKeyState(Ord('C')) and $80) = $80 then
btn1.OnClick(nil)
else if (GetKeyState(Ord('T')) and $80) = $80 then //<-- after this line if jump to line 30!! why ???
btn2.OnClick(nil)
else if (GetKeyState(Ord('Q')) and $80) = $80 then
btn3.OnClick(nil)
else if (GetKeyState(Ord('W')) and $80) = $80 then
btn3.OnClick(nil);
end; //case Key of
{This is line 30} FValidKeyCombo := (Shift = [ssAlt]) and (Key in [Ord('C'), Ord('T'), Ord('Q'), Ord('W')]);
end;
procedure MyForm.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
FValidKeyCombo := False;
end;
正如代码中注释的那样,当我按下 Alt+W+E 时,会If
跳转到设置值的第 30 行!FValidKeyCombo
为什么 ??