Ser*_*yuz 17
当其中一个键到达时,您可以查看其他键是否已经关闭.例如:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Shift = [ssCtrl] then begin
case Key of
Ord('C'):
if (GetKeyState(Ord('N')) and $80) = $80 then
ShowMessage('combo');
Ord('N'):
if (GetKeyState(Ord('C')) and $80) = $80 then
ShowMessage('combo');
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)
然而,这也将检测例如N+ Ctrl+ C,一个不以Ctrl密钥开头的序列.如果这不符合有效的密钥组合,您可以借助标记保留一些密钥历史记录.以下应仅检测最初以下列开头的序列Ctrl:
type
TForm1 = class(TForm)
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
private
FValidKeyCombo: Boolean;
end;
...
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if FValidKeyCombo and (Shift = [ssCtrl]) then
case Key of
Ord('C'):
if (GetKeyState(Ord('N')) and $80) = $80 then
ShowMessage('combo');
Ord('N'):
if (GetKeyState(Ord('C')) and $80) = $80 then
ShowMessage('combo');
end;
FValidKeyCombo := (Shift = [ssCtrl]) and (Key in [Ord('C'), Ord('N')]);
end;
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
FValidKeyCombo := False;
end;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7499 次 |
最近记录: |