@@ -43,22 +43,40 @@ protected override async Task OnInitializedAsync()
4343 _keyboardDownChecked = ( AppSettings . PasswordBoxActiveMethod & PasswordBoxActiveMethodEnum . KeyboardDown ) == PasswordBoxActiveMethodEnum . KeyboardDown ;
4444 _mouseDownChecked = ( AppSettings . PasswordBoxActiveMethod & PasswordBoxActiveMethodEnum . MouseDown ) == PasswordBoxActiveMethodEnum . MouseDown ;
4545
46- if ( AppSettings . ShortcutKeyForLock . IsNotTrimEmpty ( ) )
46+ if ( AppSettings . LockHotkeyString . IsNotTrimEmpty ( ) )
4747 {
48- RegisterHotkey ( ) ;
48+ RegisterLockHotkey ( ) ;
49+ }
50+ if ( AppSettings . UnlockHotkeyString . IsNotTrimEmpty ( ) )
51+ {
52+ RegisterUnlockHotkey ( ) ;
4953 }
5054
5155 HotkeyHook . HotkeyPressed += ( id ) =>
5256 {
53- if ( GlobalLockService . IsLocked )
57+ if ( id == ( int ) HotkeyType . Lock )
5458 {
55- Logger . Write ( "快捷键解锁" ) ;
56- GlobalLockService . Unlock ( ) ;
59+ if ( ! GlobalLockService . IsLocked )
60+ {
61+ Logger . Write ( "快捷键锁定" ) ;
62+ GlobalLockService . Lock ( ) ;
63+ }
64+ else
65+ {
66+ if ( AppSettings . ScreenUnlockMethod == ScreenUnlockMethods . Hotkey && AppSettings . IsUnlockUseLockHotkey )
67+ {
68+ Logger . Write ( "快捷键解锁" ) ;
69+ GlobalLockService . Unlock ( ) ;
70+ }
71+ }
5772 }
58- else
73+ else if ( id == ( int ) HotkeyType . Unlock )
5974 {
60- Logger . Write ( "快捷键锁定" ) ;
61- GlobalLockService . Lock ( ) ;
75+ if ( GlobalLockService . IsLocked )
76+ {
77+ Logger . Write ( "快捷键解锁" ) ;
78+ GlobalLockService . Unlock ( ) ;
79+ }
6280 }
6381 } ;
6482
@@ -150,22 +168,37 @@ private void SaveSettings()
150168 {
151169 AppSettingsProvider . SaveSettings ( AppSettings ) ;
152170 }
153- private Task SetHotkey ( string hotkey )
171+ private Task SetLockHotkey ( string hotkey )
172+ {
173+ AppSettings . LockHotkeyString = hotkey ;
174+ SaveSettings ( ) ;
175+ RegisterLockHotkey ( ) ;
176+ return Task . CompletedTask ;
177+ }
178+ private Task ClearLockHotkey ( )
179+ {
180+ AppSettings . LockHotkeyString = "" ;
181+ SaveSettings ( ) ;
182+ UnregisterLockHotkey ( ) ;
183+ return Task . CompletedTask ;
184+ }
185+
186+ private Task SetUnlockHotkey ( string hotkey )
154187 {
155- AppSettings . ShortcutKeyForLock = hotkey ;
188+ AppSettings . UnlockHotkeyString = hotkey ;
156189 SaveSettings ( ) ;
157- RegisterHotkey ( ) ;
190+ RegisterUnlockHotkey ( ) ;
158191 return Task . CompletedTask ;
159192 }
160- private Task ClearHotkey ( )
193+ private Task ClearUnlockHotkey ( )
161194 {
162- AppSettings . ShortcutKeyForLock = "" ;
195+ AppSettings . UnlockHotkeyString = "" ;
163196 SaveSettings ( ) ;
164- UnregisterHotkey ( ) ;
197+ UnregisterUnlockHotkey ( ) ;
165198 return Task . CompletedTask ;
166199 }
167200
168- public void RegisterHotkey ( )
201+ public void RegisterLockHotkey ( )
169202 {
170203 try
171204 {
@@ -181,8 +214,7 @@ public void RegisterHotkey()
181214 Snackbar . Add ( $ "{ Lang [ "ExRegistFailed" ] } { ex . Message } ", Severity . Error ) ;
182215 }
183216 }
184-
185- public void UnregisterHotkey ( )
217+ public void UnregisterLockHotkey ( )
186218 {
187219 try
188220 {
@@ -196,6 +228,35 @@ public void UnregisterHotkey()
196228 }
197229 }
198230
231+ public void RegisterUnlockHotkey ( )
232+ {
233+ try
234+ {
235+ if ( AppSettings . UnlockHotkey != null )
236+ {
237+ Logger . Write ( "注册解锁热键" ) ;
238+ HotkeyHook . Register ( ( int ) HotkeyType . Unlock , AppSettings . UnlockHotkey ) ;
239+ }
240+ }
241+ catch ( Exception ex )
242+ {
243+ Logger . Write ( $ "绑定解锁热键失败:{ ex . Message } 。{ ex . StackTrace } ") ;
244+ Snackbar . Add ( $ "{ Lang [ "ExRegistFailed" ] } { ex . Message } ", Severity . Error ) ;
245+ }
246+ }
247+ public void UnregisterUnlockHotkey ( )
248+ {
249+ try
250+ {
251+ Logger . Write ( "释放解锁热键" ) ;
252+ HotkeyHook . Unregister ( ( int ) HotkeyType . Unlock ) ;
253+ }
254+ catch ( Exception ex )
255+ {
256+ Logger . Write ( $ "释放解锁热键失败:{ ex . Message } 。{ ex . StackTrace } ") ;
257+ //MessageBoxUtils.ShowError($"取消快捷键失败:{ex.Message}");
258+ }
259+ }
199260 private async Task ResetPassword ( )
200261 {
201262 var noHeader = new DialogOptions ( )
0 commit comments