@@ -195,12 +195,14 @@ TMainForm = class(TForm)
195195 procedure SetStartAutoCaptureHotKey (AHotKey: THotKey);
196196 procedure SetStopAutoCaptureHotKey (AHotKey: THotKey);
197197 procedure SetSingleCaptureHotKey (AHotKey: THotKey);
198+ procedure SetHotKey (AHotKeyId: String; AHotKey: THotKey);
198199 procedure SetCompressionLevel (ALevel: Tcompressionlevel);
199200 function GetCompressionLevel : Tcompressionlevel;
200201 procedure UpdateFormAutoSize ;
201202
202203 procedure OnHotKeyEvent (const AHotKeyId: String);
203204 procedure OnDebugLnEvent (Sender: TObject; S: string; var Handled: Boolean);
205+ function OnHotKeysSaving (ASender: TObject; out AErrorMsg: string): Boolean;
204206
205207 { $IfDef Linux}
206208 procedure OnScreenConfigurationChanged (const AEvent: TXEvent);
@@ -467,17 +469,9 @@ procedure TMainForm.ReadSettings;
467469
468470procedure TMainForm.FormCreate (Sender: TObject);
469471const
470- StartAutoCaptureDefaultHotKey: THotKey = (
471- ShiftState: [ssCtrl];
472- Key: VK_F5;
473- );
474- StopAutoCaptureDefaultHotKey: THotKey = (
475- ShiftState: [ssCtrl];
476- Key: VK_F6;
477- );
478- SingleCaptureDefaultHotKey: THotKey = (
479- ShiftState: [ssCtrl];
480- Key: VK_F7;
472+ NoHotKey: THotKey = (
473+ ShiftState: [];
474+ Key: VK_UNKNOWN;
481475 );
482476var
483477 // /////
@@ -540,12 +534,24 @@ procedure TMainForm.FormCreate(Sender: TObject);
540534 // Enable global hotkeys
541535 KeyHook := TGlobalKeyHook.Create({ $IfDef Windows} Handle, ' AutoScreenshot' { $EndIf}
542536 { $IfDef Linux} @OnHotKeyEvent{ $EndIf} );
543- HotKey := Ini.ReadHotKey(HotKeysIniSection, ' StartAutoCapture' , StartAutoCaptureDefaultHotKey);
544- KeyHook.RegisterKey(' StartAutoCapture' , HotKey);
545- HotKey := Ini.ReadHotKey(HotKeysIniSection, ' StopAutoCapture' , StopAutoCaptureDefaultHotKey);
546- KeyHook.RegisterKey(' StopAutoCapture' , HotKey);
547- HotKey := Ini.ReadHotKey(HotKeysIniSection, ' SingleCapture' , SingleCaptureDefaultHotKey);
548- KeyHook.RegisterKey(' SingleCapture' , HotKey);
537+ HotKey := Ini.ReadHotKey(HotKeysIniSection, ' StartAutoCapture' , NoHotKey);
538+ try
539+ KeyHook.RegisterKey(' StartAutoCapture' , HotKey);
540+ except
541+ KeyHook.RegisterKey(' StartAutoCapture' , NoHotKey);
542+ end ;
543+ HotKey := Ini.ReadHotKey(HotKeysIniSection, ' StopAutoCapture' , NoHotKey);
544+ try
545+ KeyHook.RegisterKey(' StopAutoCapture' , HotKey);
546+ except
547+ KeyHook.RegisterKey(' StopAutoCapture' , NoHotKey);
548+ end ;
549+ HotKey := Ini.ReadHotKey(HotKeysIniSection, ' SingleCapture' , NoHotKey);
550+ try
551+ KeyHook.RegisterKey(' SingleCapture' , HotKey);
552+ except
553+ KeyHook.RegisterKey(' SingleCapture' , NoHotKey);
554+ end ;
549555
550556 { $IfDef Linux}
551557 // Enable monitor confuguration changed updates in Linux
@@ -594,18 +600,15 @@ procedure TMainForm.FormShow(Sender: TObject);
594600procedure TMainForm.HotKetsSettingsMenuItemClick (Sender: TObject);
595601var
596602 HotKeysForm: THotKeysForm;
603+ HasErrors: Boolean = False;
597604begin
598- HotKeysForm := THotKeysForm.Create(Nil );
605+ // ToDo: Reduce amount of code duplicates
606+
607+ HotKeysForm := THotKeysForm.Create(Nil , @OnHotKeysSaving);
599608 HotKeysForm.StartAutoCaptureKey := Self.KeyHook.FindHotKey(' StartAutoCapture' );
600609 HotKeysForm.StopAutoCaptureKey := Self.KeyHook.FindHotKey(' StopAutoCapture' );
601610 HotKeysForm.SingleCaptureKey := Self.KeyHook.FindHotKey(' SingleCapture' );
602- if HotKeysForm.ShowModal = mrOK then
603- begin
604- SetStartAutoCaptureHotKey(HotKeysForm.StartAutoCaptureKey);
605- SetStopAutoCaptureHotKey(HotKeysForm.StopAutoCaptureKey);
606- SetSingleCaptureHotKey(HotKeysForm.SingleCaptureKey);
607- end ;
608-
611+ HotKeysForm.ShowModal;
609612 HotKeysForm.Free;
610613end ;
611614
@@ -1618,20 +1621,23 @@ procedure TMainForm.SetAutoCheckForUpdates(AVal: Boolean);
16181621
16191622procedure TMainForm.SetStartAutoCaptureHotKey (AHotKey: THotKey);
16201623begin
1621- KeyHook.RegisterKey(' StartAutoCapture' , AHotKey);
1622- Ini.WriteHotKey(HotKeysIniSection, ' StartAutoCapture' , AHotKey);
1624+ SetHotKey(' StartAutoCapture' , AHotKey);
16231625end ;
16241626
16251627procedure TMainForm.SetStopAutoCaptureHotKey (AHotKey: THotKey);
16261628begin
1627- KeyHook.RegisterKey(' StopAutoCapture' , AHotKey);
1628- Ini.WriteHotKey(HotKeysIniSection, ' StopAutoCapture' , AHotKey);
1629+ SetHotKey(' StopAutoCapture' , AHotKey);
16291630end ;
16301631
16311632procedure TMainForm.SetSingleCaptureHotKey (AHotKey: THotKey);
16321633begin
1633- KeyHook.RegisterKey(' SingleCapture' , AHotKey);
1634- Ini.WriteHotKey(HotKeysIniSection, ' SingleCapture' , AHotKey);
1634+ SetHotKey(' SingleCapture' , AHotKey);
1635+ end ;
1636+
1637+ procedure TMainForm.SetHotKey (AHotKeyId: String; AHotKey: THotKey);
1638+ begin
1639+ KeyHook.RegisterKey(AHotKeyId, AHotKey);
1640+ Ini.WriteHotKey(HotKeysIniSection, AHotKeyId, AHotKey);
16351641end ;
16361642
16371643procedure TMainForm.SetCompressionLevel (ALevel: Tcompressionlevel);
@@ -1687,6 +1693,45 @@ procedure TMainForm.OnDebugLnEvent(Sender: TObject; S: string;
16871693 Handled := True;
16881694end ;
16891695
1696+ function TMainForm.OnHotKeysSaving (ASender: TObject; out AErrorMsg: string): Boolean;
1697+ var
1698+ HasErrors: Boolean = False;
1699+ HotKeysForm: THotKeysForm;
1700+ begin
1701+ HotKeysForm := THotKeysForm(ASender);
1702+
1703+ try
1704+ SetStartAutoCaptureHotKey(HotKeysForm.StartAutoCaptureKey);
1705+ HotKeysForm.StartAutoCaptureMarked := False;
1706+ except
1707+ HasErrors := True;
1708+ HotKeysForm.StartAutoCaptureMarked := True;
1709+ end ;
1710+
1711+ try
1712+ SetStopAutoCaptureHotKey(HotKeysForm.StopAutoCaptureKey);
1713+ HotKeysForm.StopAutoCaptureMarked := False;
1714+ except
1715+ HasErrors := True;
1716+ HotKeysForm.StopAutoCaptureMarked := True;
1717+ end ;
1718+
1719+ try
1720+ SetSingleCaptureHotKey(HotKeysForm.SingleCaptureKey);
1721+ HotKeysForm.SingleCaptureMarked := False;
1722+ except
1723+ HasErrors := True;
1724+ HotKeysForm.SingleCaptureMarked := True;
1725+ end ;
1726+
1727+ if HasErrors then
1728+ AErrorMsg := Localizer.I18N(' HotKeyOccupied' )
1729+ else
1730+ AErrorMsg := ' ' ;
1731+
1732+ Result := not HasErrors;
1733+ end ;
1734+
16901735{ $IfDef Linux}
16911736procedure TMainForm.OnScreenConfigurationChanged (const AEvent: TXEvent);
16921737begin
0 commit comments