Upon the arrival of one of the keys, you can see if the other key has already been disabled. For instance:.
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;
However, it will also detect, for example, N + Ctrl + C , a sequence that does not start with the Ctrl key. If this does not apply to a valid key combination, you can save a little key history with a flag. The following should only detect sequences that initially begin with 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;
source share